GBoostClassifier#

class GBoostClassifier(base_estimator=RuleTreeRegressor(base_stumps=DecisionTreeStumpRegressor(), max_depth=4), n_estimators=100, learning_rate=0.1, loss='squared_loss', patience=5, val_size=0.15, n_jobs=4, random_state=42)[source]#

Bases: ClassifierMixin, RuleTreeBase

Gradient boosting for classification with RuleTreeRegressors as base estimators (one-vs-rest, logistic loss).

For each class, a boosting of regression trees is fitted on the residuals of the predicted probability of the class; the leaves of each tree are given the Newton step of the log-odds. The prediction is the class with the highest probability. The classes are fitted in parallel.

Parameters:
  • base_estimator (RuleTreeRegressor, default=RuleTreeRegressor(max_depth=4)) – Estimator fitted at each iteration.

  • n_estimators (int, default=100) – Maximum number of estimators per class.

  • learning_rate (float, default=0.1) – Shrinkage of the contribution of each estimator.

  • loss ('squared_loss' or callable, default='squared_loss') – Checked but not used.

  • patience (int, default=5) – Number of iterations without improvement before stopping.

  • val_size (float, default=0.15) – Fraction of the training set used for validation (stratified).

  • n_jobs (int, default=os.cpu_count()) – Number of processes (at most one per class); with 1, the classes are fitted in the current process.

  • random_state (int, default=42) – Seed of the split between training and validation, and of the trees whose base estimator has no random_state (each tree gets a different seed drawn from it).

Variables:
  • classes (list) – Classes of the target.

  • base_log_odds (numpy.ndarray) – Initial log-odds of each class.

  • estimators (list of list) – For each class, the fitted estimators with the value of each of their leaves.

See also

GBoostRegressor

the same boosting for regression.

Examples

>>> from sklearn.datasets import load_breast_cancer
>>> from RuleTree import RuleTreeRegressor
>>> from RuleTree.ensemble.GBoostClassifier import GBoostClassifier
>>> X, y = load_breast_cancer(return_X_y=True)
>>> model = GBoostClassifier(base_estimator=RuleTreeRegressor(max_depth=2, random_state=0),
...                          n_estimators=10, n_jobs=1, random_state=0).fit(X, y)
>>> round(model.score(X, y), 3)
0.919
fit(X: ndarray, y: ndarray)[source]#

Fit a boosting for each class.

Parameters:
Returns:

self

Return type:

GBoostClassifier

predict(X: ndarray)[source]#

Predict the class with the highest probability.

Parameters:

X (numpy.ndarray of shape (n_samples, n_features)) – Tabular data.

Returns:

y_pred

Return type:

numpy.ndarray of shape (n_samples,)