Class: 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.
HistGradientBoostingClassifier
is a much faster variant of this algorithm for intermediate and large datasets (n_samples >= 10_000
) and supports monotonic constraints.
Read more in the User Guide.
Constructors
new GradientBoostingClassifier()
new GradientBoostingClassifier(
opts
?):GradientBoostingClassifier
Parameters
Parameter | Type | Description |
---|---|---|
opts ? | object | - |
opts.ccp_alpha ? | any | Complexity 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. |
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. |
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 ? | number | Learning 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) . |
opts.loss ? | "exponential" | "log_loss" | 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. |
opts.max_depth ? | number | Maximum 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) . |
opts.max_features ? | number | "sqrt" | "log2" | The number of features to consider when looking for the best split: |
opts.max_leaf_nodes ? | number | Grow 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 ? | number | A 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: |
opts.min_samples_leaf ? | number | The 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. |
opts.min_samples_split ? | number | The minimum number of samples required to split an internal node: |
opts.min_weight_fraction_leaf ? | number | The 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\] . |
opts.n_estimators ? | number | The 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) . |
opts.n_iter_no_change ? | number | n_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) . See Early stopping in Gradient Boosting. |
opts.random_state ? | number | Controls 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 ? | number | The 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\] . |
opts.tol ? | number | Tolerance 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) . |
opts.validation_fraction ? | number | The 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. |
opts.verbose ? | number | Enable 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) . |
opts.warm_start ? | boolean | When 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. |
Returns GradientBoostingClassifier
Defined in generated/ensemble/GradientBoostingClassifier.ts:27
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/ensemble/GradientBoostingClassifier.ts:25 |
_isInitialized | boolean | false | generated/ensemble/GradientBoostingClassifier.ts:24 |
_py | PythonBridge | undefined | generated/ensemble/GradientBoostingClassifier.ts:23 |
id | string | undefined | generated/ensemble/GradientBoostingClassifier.ts:20 |
opts | any | undefined | generated/ensemble/GradientBoostingClassifier.ts:21 |
Accessors
classes_
Get Signature
get classes_():
Promise
<ArrayLike
>
The classes labels.
Returns Promise
<ArrayLike
>
Defined in generated/ensemble/GradientBoostingClassifier.ts:969
estimators_
Get Signature
get estimators_():
Promise
<any
[]>
The collection of fitted sub-estimators. n_trees_per_iteration_
is 1 for binary classification, otherwise n_classes
.
Returns Promise
<any
[]>
Defined in generated/ensemble/GradientBoostingClassifier.ts:942
feature_names_in_
Get Signature
get feature_names_in_():
Promise
<ArrayLike
>
Names of features seen during fit. Defined only when X
has feature names that are all strings.
Returns Promise
<ArrayLike
>
Defined in generated/ensemble/GradientBoostingClassifier.ts:1023
init_
Get Signature
get init_():
Promise
<any
>
The estimator that provides the initial predictions. Set via the init
argument.
Returns Promise
<any
>
Defined in generated/ensemble/GradientBoostingClassifier.ts:915
max_features_
Get Signature
get max_features_():
Promise
<number
>
The inferred value of max_features.
Returns Promise
<number
>
Defined in generated/ensemble/GradientBoostingClassifier.ts:1077
n_classes_
Get Signature
get n_classes_():
Promise
<number
>
The number of classes.
Returns Promise
<number
>
Defined in generated/ensemble/GradientBoostingClassifier.ts:1050
n_estimators_
Get Signature
get n_estimators_():
Promise
<number
>
The number of estimators as selected by early stopping (if n_iter_no_change
is specified). Otherwise it is set to n_estimators
.
Returns Promise
<number
>
Defined in generated/ensemble/GradientBoostingClassifier.ts:753
n_features_in_
Get Signature
get n_features_in_():
Promise
<number
>
Number of features seen during fit.
Returns Promise
<number
>
Defined in generated/ensemble/GradientBoostingClassifier.ts:996
n_trees_per_iteration_
Get Signature
get n_trees_per_iteration_():
Promise
<number
>
The number of trees that are built at each iteration. For binary classifiers, this is always 1.
Returns Promise
<number
>
Defined in generated/ensemble/GradientBoostingClassifier.ts:780
oob_improvement_
Get Signature
get oob_improvement_():
Promise
<ArrayLike
>
The improvement in loss 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
.
Returns Promise
<ArrayLike
>
Defined in generated/ensemble/GradientBoostingClassifier.ts:807
oob_score_
Get Signature
get oob_score_():
Promise
<number
>
The last value of the loss on the out-of-bag samples. It is the same as oob_scores_\[-1\]
. Only available if subsample < 1.0
.
Returns Promise
<number
>
Defined in generated/ensemble/GradientBoostingClassifier.ts:861
oob_scores_
Get Signature
get oob_scores_():
Promise
<ArrayLike
>
The full history of the loss values on the out-of-bag samples. Only available if subsample < 1.0
.
Returns Promise
<ArrayLike
>
Defined in generated/ensemble/GradientBoostingClassifier.ts:834
py
Get Signature
get py():
PythonBridge
Returns PythonBridge
Set Signature
set py(
pythonBridge
):void
Parameters
Parameter | Type |
---|---|
pythonBridge | PythonBridge |
Returns void
Defined in generated/ensemble/GradientBoostingClassifier.ts:164
train_score_
Get Signature
get train_score_():
Promise
<ArrayLike
>
The i-th score train_score_\[i\]
is the loss of the model at iteration i
on the in-bag sample. If subsample \== 1
this is the loss on the training data.
Returns Promise
<ArrayLike
>
Defined in generated/ensemble/GradientBoostingClassifier.ts:888
Methods
apply()
apply(
opts
):Promise
<ArrayLike
[][]>
Apply trees in the ensemble to X, return leaf indices.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | The 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:237
decision_function()
decision_function(
opts
):Promise
<ArrayLike
[]>
Compute the decision function of X
.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | The 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:273
dispose()
dispose():
Promise
<void
>
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
Returns Promise
<void
>
Defined in generated/ensemble/GradientBoostingClassifier.ts:220
fit()
fit(
opts
):Promise
<any
>
Fit the gradient boosting model.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.monitor ? | any | The 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 snapshotting. |
opts.sample_weight ? | ArrayLike | Sample 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.X ? | ArrayLike | The input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr_matrix . |
opts.y ? | ArrayLike | Target 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:309
get_metadata_routing()
get_metadata_routing(
opts
):Promise
<any
>
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.routing ? | any | A MetadataRequest encapsulating routing information. |
Returns Promise
<any
>
Defined in generated/ensemble/GradientBoostingClassifier.ts:362
init()
init(
py
):Promise
<void
>
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Parameters
Parameter | Type |
---|---|
py | PythonBridge |
Returns Promise
<void
>
Defined in generated/ensemble/GradientBoostingClassifier.ts:177
predict()
predict(
opts
):Promise
<ArrayLike
>
Predict class for X.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | The 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:398
predict_log_proba()
predict_log_proba(
opts
):Promise
<ArrayLike
[]>
Predict class log-probabilities for X.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | The 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:434
predict_proba()
predict_proba(
opts
):Promise
<ArrayLike
[]>
Predict class probabilities for X.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | The 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:470
score()
score(
opts
):Promise
<number
>
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.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | ArrayLike | Sample weights. |
opts.X ? | ArrayLike [] | Test samples. |
opts.y ? | ArrayLike | True labels for X . |
Returns Promise
<number
>
Defined in generated/ensemble/GradientBoostingClassifier.ts:508
set_fit_request()
set_fit_request(
opts
):Promise
<any
>
Request metadata passed to the fit
method.
Note that this method is only relevant if enable_metadata_routing=True
(see sklearn.set_config
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.monitor ? | string | boolean | Metadata routing for monitor parameter in fit . |
opts.sample_weight ? | string | boolean | Metadata routing for sample_weight parameter in fit . |
Returns Promise
<any
>
Defined in generated/ensemble/GradientBoostingClassifier.ts:558
set_score_request()
set_score_request(
opts
):Promise
<any
>
Request metadata passed to the score
method.
Note that this method is only relevant if enable_metadata_routing=True
(see sklearn.set_config
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | string | boolean | Metadata routing for sample_weight parameter in score . |
Returns Promise
<any
>
Defined in generated/ensemble/GradientBoostingClassifier.ts:603
staged_decision_function()
staged_decision_function(
opts
):Promise
<any
[]>
Compute decision function of X
for each iteration.
This method allows monitoring (i.e. determine error on testing set) after each stage.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | The 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:641
staged_predict()
staged_predict(
opts
):Promise
<any
[]>
Predict class at each stage for X.
This method allows monitoring (i.e. determine error on testing set) after each stage.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | The 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:679
staged_predict_proba()
staged_predict_proba(
opts
):Promise
<any
[]>
Predict class probabilities at each stage for X.
This method allows monitoring (i.e. determine error on testing set) after each stage.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | The 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:717