Documentation
Classes
GradientBoostingClassifier

GradientBoostingClassifier

Gradient Boosting for classification.

This algorithm builds an additive model in a forward stage-wise fashion; it allows for the optimization of arbitrary differentiable loss functions. In each stage n\_classes\_ regression trees are fit on the negative gradient of the loss function, e.g. binary or multiclass log loss. Binary classification is a special case where only a single regression tree is induced.

sklearn.ensemble.HistGradientBoostingClassifier is a much faster variant of this algorithm for intermediate datasets (n\_samples >= 10\_000).

Read more in the User Guide.

Python Reference (opens in a new tab)

Constructors

constructor()

Signature

new GradientBoostingClassifier(opts?: object): GradientBoostingClassifier;

Parameters

NameTypeDescription
opts?object-
opts.ccp_alpha?anyComplexity parameter used for Minimal Cost-Complexity Pruning. The subtree with the largest cost complexity that is smaller than ccp\_alpha will be chosen. By default, no pruning is performed. Values must be in the range \0.0, inf). See [Minimal Cost-Complexity Pruning for details. Default Value 0
opts.criterion?"squared_error" | "friedman_mse"The function to measure the quality of a split. Supported criteria are ‘friedman_mse’ for the mean squared error with improvement score by Friedman, ‘squared_error’ for mean squared error. The default value of ‘friedman_mse’ is generally the best as it can provide a better approximation in some cases. Default Value 'friedman_mse'
opts.init?"zero"An estimator object that is used to compute the initial predictions. init has to provide fit and predict\_proba. If ‘zero’, the initial raw predictions are set to zero. By default, a DummyEstimator predicting the classes priors is used.
opts.learning_rate?numberLearning rate shrinks the contribution of each tree by learning\_rate. There is a trade-off between learning_rate and n_estimators. Values must be in the range \[0.0, inf). Default Value 0.1
opts.loss?"exponential" | "log_loss" | "deviance"The loss function to be optimized. ‘log_loss’ refers to binomial and multinomial deviance, the same as used in logistic regression. It is a good choice for classification with probabilistic outputs. For loss ‘exponential’, gradient boosting recovers the AdaBoost algorithm. Default Value 'log_loss'
opts.max_depth?numberMaximum depth of the individual regression estimators. The maximum depth limits the number of nodes in the tree. Tune this parameter for best performance; the best value depends on the interaction of the input variables. If undefined, then nodes are expanded until all leaves are pure or until all leaves contain less than min_samples_split samples. If int, values must be in the range \[1, inf). Default Value 3
opts.max_features?number | "auto" | "sqrt" | "log2"The number of features to consider when looking for the best split:
opts.max_leaf_nodes?numberGrow trees with max\_leaf\_nodes in best-first fashion. Best nodes are defined as relative reduction in impurity. Values must be in the range \[2, inf). If undefined, then unlimited number of leaf nodes.
opts.min_impurity_decrease?numberA node will be split if this split induces a decrease of the impurity greater than or equal to this value. Values must be in the range \[0.0, inf). The weighted impurity decrease equation is the following: Default Value 0
opts.min_samples_leaf?numberThe minimum number of samples required to be at a leaf node. A split point at any depth will only be considered if it leaves at least min\_samples\_leaf training samples in each of the left and right branches. This may have the effect of smoothing the model, especially in regression. Default Value 1
opts.min_samples_split?numberThe minimum number of samples required to split an internal node: Default Value 2
opts.min_weight_fraction_leaf?numberThe minimum weighted fraction of the sum total of weights (of all the input samples) required to be at a leaf node. Samples have equal weight when sample_weight is not provided. Values must be in the range \[0.0, 0.5\]. Default Value 0
opts.n_estimators?numberThe number of boosting stages to perform. Gradient boosting is fairly robust to over-fitting so a large number usually results in better performance. Values must be in the range \1, inf). Default Value 100
opts.n_iter_no_change?numbern\_iter\_no\_change is used to decide if early stopping will be used to terminate training when validation score is not improving. By default it is set to undefined to disable early stopping. If set to a number, it will set aside validation\_fraction size of the training data as validation and terminate training when validation score is not improving in all of the previous n\_iter\_no\_change numbers of iterations. The split is stratified. Values must be in the range \[1, inf).
opts.random_state?numberControls the random seed given to each Tree estimator at each boosting iteration. In addition, it controls the random permutation of the features at each split (see Notes for more details). It also controls the random splitting of the training data to obtain a validation set if n\_iter\_no\_change is not undefined. Pass an int for reproducible output across multiple function calls. See [Glossary.
opts.subsample?numberThe fraction of samples to be used for fitting the individual base learners. If smaller than 1.0 this results in Stochastic Gradient Boosting. subsample interacts with the parameter n\_estimators. Choosing subsample < 1.0 leads to a reduction of variance and an increase in bias. Values must be in the range (0.0, 1.0\]. Default Value 1
opts.tol?numberTolerance for the early stopping. When the loss is not improving by at least tol for n\_iter\_no\_change iterations (if set to a number), the training stops. Values must be in the range \0.0, inf). Default Value 0.0001
opts.validation_fraction?numberThe proportion of training data to set aside as validation set for early stopping. Values must be in the range (0.0, 1.0). Only used if n\_iter\_no\_change is set to an integer. Default Value 0.1
opts.verbose?numberEnable verbose output. If 1 then it prints progress and performance once in a while (the more trees the lower the frequency). If greater than 1 then it prints progress and performance for every tree. Values must be in the range \[0, inf). Default Value 0
opts.warm_start?booleanWhen set to true, reuse the solution of the previous call to fit and add more estimators to the ensemble, otherwise, just erase the previous solution. See [the Glossary. Default Value false

Returns

GradientBoostingClassifier

Defined in: generated/ensemble/GradientBoostingClassifier.ts:27 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/ensemble/GradientBoostingClassifier.ts:25 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/ensemble/GradientBoostingClassifier.ts:24 (opens in a new tab)

_py

PythonBridge

Defined in: generated/ensemble/GradientBoostingClassifier.ts:23 (opens in a new tab)

id

string

Defined in: generated/ensemble/GradientBoostingClassifier.ts:20 (opens in a new tab)

opts

any

Defined in: generated/ensemble/GradientBoostingClassifier.ts:21 (opens in a new tab)

Accessors

classes_

The classes labels.

Signature

classes_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/ensemble/GradientBoostingClassifier.ts:849 (opens in a new tab)

estimators_

The collection of fitted sub-estimators. loss\_.K is 1 for binary classification, otherwise n_classes.

Signature

estimators_(): Promise<any[]>;

Returns

Promise<any[]>

Defined in: generated/ensemble/GradientBoostingClassifier.ts:822 (opens in a new tab)

feature_names_in_

Names of features seen during fit. Defined only when X has feature names that are all strings.

Signature

feature_names_in_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/ensemble/GradientBoostingClassifier.ts:903 (opens in a new tab)

init_

The estimator that provides the initial predictions. Set via the init argument or loss.init\_estimator.

Signature

init_(): Promise<any>;

Returns

Promise<any>

Defined in: generated/ensemble/GradientBoostingClassifier.ts:795 (opens in a new tab)

loss_

The concrete LossFunction object.

Signature

loss_(): Promise<any>;

Returns

Promise<any>

Defined in: generated/ensemble/GradientBoostingClassifier.ts:768 (opens in a new tab)

max_features_

The inferred value of max_features.

Signature

max_features_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/ensemble/GradientBoostingClassifier.ts:957 (opens in a new tab)

n_classes_

The number of classes.

Signature

n_classes_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/ensemble/GradientBoostingClassifier.ts:930 (opens in a new tab)

n_estimators_

The number of estimators as selected by early stopping (if n\_iter\_no\_change is specified). Otherwise it is set to n\_estimators.

Signature

n_estimators_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/ensemble/GradientBoostingClassifier.ts:687 (opens in a new tab)

n_features_in_

Number of features seen during fit.

Signature

n_features_in_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/ensemble/GradientBoostingClassifier.ts:876 (opens in a new tab)

oob_improvement_

The improvement in loss (= deviance) on the out-of-bag samples relative to the previous iteration. oob\_improvement\_\[0\] is the improvement in loss of the first stage over the init estimator. Only available if subsample < 1.0

Signature

oob_improvement_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/ensemble/GradientBoostingClassifier.ts:714 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/ensemble/GradientBoostingClassifier.ts:164 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/ensemble/GradientBoostingClassifier.ts:168 (opens in a new tab)

train_score_

The i-th score train\_score\_\[i\] is the deviance (= loss) of the model at iteration i on the in-bag sample. If subsample \== 1 this is the deviance on the training data.

Signature

train_score_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/ensemble/GradientBoostingClassifier.ts:741 (opens in a new tab)

Methods

apply()

Apply trees in the ensemble to X, return leaf indices.

Signature

apply(opts: object): Promise<ArrayLike[][]>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeThe input samples. Internally, its dtype will be converted to dtype=np.float32. If a sparse matrix is provided, it will be converted to a sparse csr\_matrix.

Returns

Promise<ArrayLike[][]>

Defined in: generated/ensemble/GradientBoostingClassifier.ts:268 (opens in a new tab)

decision_function()

Compute the decision function of X.

Signature

decision_function(opts: object): Promise<ArrayLike[]>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeThe input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr\_matrix.

Returns

Promise<ArrayLike[]>

Defined in: generated/ensemble/GradientBoostingClassifier.ts:305 (opens in a new tab)

dispose()

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Signature

dispose(): Promise<void>;

Returns

Promise<void>

Defined in: generated/ensemble/GradientBoostingClassifier.ts:251 (opens in a new tab)

fit()

Fit the gradient boosting model.

Signature

fit(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeThe input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr\_matrix.
opts.monitor?anyThe monitor is called after each iteration with the current iteration, a reference to the estimator and the local variables of \_fit\_stages as keyword arguments callable(i, self, locals()). If the callable returns true the fitting procedure is stopped. The monitor can be used for various things such as computing held-out estimates, early stopping, model introspect, and snapshoting.
opts.sample_weight?ArrayLikeSample weights. If undefined, then samples are equally weighted. Splits that would create child nodes with net zero or negative weight are ignored while searching for a split in each node. In the case of classification, splits are also ignored if they would result in any single class carrying a negative weight in either child node.
opts.y?ArrayLikeTarget values (strings or integers in classification, real numbers in regression) For classification, labels must correspond to classes.

Returns

Promise<any>

Defined in: generated/ensemble/GradientBoostingClassifier.ts:343 (opens in a new tab)

init()

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Signature

init(py: PythonBridge): Promise<void>;

Parameters

NameType
pyPythonBridge

Returns

Promise<void>

Defined in: generated/ensemble/GradientBoostingClassifier.ts:177 (opens in a new tab)

predict()

Predict class for X.

Signature

predict(opts: object): Promise<ArrayLike>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeThe input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr\_matrix.

Returns

Promise<ArrayLike>

Defined in: generated/ensemble/GradientBoostingClassifier.ts:401 (opens in a new tab)

predict_log_proba()

Predict class log-probabilities for X.

Signature

predict_log_proba(opts: object): Promise<ArrayLike[]>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeThe input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr\_matrix.

Returns

Promise<ArrayLike[]>

Defined in: generated/ensemble/GradientBoostingClassifier.ts:438 (opens in a new tab)

predict_proba()

Predict class probabilities for X.

Signature

predict_proba(opts: object): Promise<ArrayLike[]>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeThe input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr\_matrix.

Returns

Promise<ArrayLike[]>

Defined in: generated/ensemble/GradientBoostingClassifier.ts:476 (opens in a new tab)

score()

Return the mean accuracy on the given test data and labels.

In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

Signature

score(opts: object): Promise<number>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLike[]Test samples.
opts.sample_weight?ArrayLikeSample weights.
opts.y?ArrayLikeTrue labels for X.

Returns

Promise<number>

Defined in: generated/ensemble/GradientBoostingClassifier.ts:516 (opens in a new tab)

staged_decision_function()

Compute decision function of X for each iteration.

This method allows monitoring (i.e. determine error on testing set) after each stage.

Signature

staged_decision_function(opts: object): Promise<any[]>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeThe input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr\_matrix.

Returns

Promise<any[]>

Defined in: generated/ensemble/GradientBoostingClassifier.ts:569 (opens in a new tab)

staged_predict()

Predict class at each stage for X.

This method allows monitoring (i.e. determine error on testing set) after each stage.

Signature

staged_predict(opts: object): Promise<any[]>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeThe input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr\_matrix.

Returns

Promise<any[]>

Defined in: generated/ensemble/GradientBoostingClassifier.ts:609 (opens in a new tab)

staged_predict_proba()

Predict class probabilities at each stage for X.

This method allows monitoring (i.e. determine error on testing set) after each stage.

Signature

staged_predict_proba(opts: object): Promise<any[]>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeThe input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr\_matrix.

Returns

Promise<any[]>

Defined in: generated/ensemble/GradientBoostingClassifier.ts:649 (opens in a new tab)