Class: GradientBoostingRegressor
Gradient Boosting for regression.
This estimator builds an additive model in a forward stage-wise fashion; it allows for the optimization of arbitrary differentiable loss functions. In each stage a regression tree is fit on the negative gradient of the given loss function.
HistGradientBoostingRegressor
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 GradientBoostingRegressor()
new GradientBoostingRegressor(
opts
?):GradientBoostingRegressor
Parameters
Parameter | Type | Description |
---|---|---|
opts ? | object | - |
opts.alpha ? | number | The alpha-quantile of the huber loss function and the quantile loss function. Only if loss='huber' or loss='quantile' . Values must be in the range (0.0, 1.0) . |
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. If ‘zero’, the initial raw predictions are set to zero. By default a DummyEstimator is used, predicting either the average target value (for loss=’squared_error’), or a quantile for the other losses. |
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 ? | "quantile" | "squared_error" | "absolute_error" | "huber" | Loss function to be optimized. ‘squared_error’ refers to the squared error for regression. ‘absolute_error’ refers to the absolute error of regression and is a robust loss function. ‘huber’ is a combination of the two. ‘quantile’ allows quantile regression (use alpha to specify the quantile). |
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. 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 GradientBoostingRegressor
Defined in generated/ensemble/GradientBoostingRegressor.ts:27
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/ensemble/GradientBoostingRegressor.ts:25 |
_isInitialized | boolean | false | generated/ensemble/GradientBoostingRegressor.ts:24 |
_py | PythonBridge | undefined | generated/ensemble/GradientBoostingRegressor.ts:23 |
id | string | undefined | generated/ensemble/GradientBoostingRegressor.ts:20 |
opts | any | undefined | generated/ensemble/GradientBoostingRegressor.ts:21 |
Accessors
estimators_
Get Signature
get estimators_():
Promise
<any
[]>
The collection of fitted sub-estimators.
Returns Promise
<any
[]>
Defined in generated/ensemble/GradientBoostingRegressor.ts:763
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/GradientBoostingRegressor.ts:817
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/GradientBoostingRegressor.ts:736
max_features_
Get Signature
get max_features_():
Promise
<number
>
The inferred value of max_features.
Returns Promise
<number
>
Defined in generated/ensemble/GradientBoostingRegressor.ts:844
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/GradientBoostingRegressor.ts:574
n_features_in_
Get Signature
get n_features_in_():
Promise
<number
>
Number of features seen during fit.
Returns Promise
<number
>
Defined in generated/ensemble/GradientBoostingRegressor.ts:790
n_trees_per_iteration_
Get Signature
get n_trees_per_iteration_():
Promise
<number
>
The number of trees that are built at each iteration. For regressors, this is always 1.
Returns Promise
<number
>
Defined in generated/ensemble/GradientBoostingRegressor.ts:601
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/GradientBoostingRegressor.ts:628
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/GradientBoostingRegressor.ts:682
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/GradientBoostingRegressor.ts:655
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/GradientBoostingRegressor.ts:171
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/GradientBoostingRegressor.ts:709
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/GradientBoostingRegressor.ts:244
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/GradientBoostingRegressor.ts:227
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/GradientBoostingRegressor.ts:280
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/GradientBoostingRegressor.ts:331
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/GradientBoostingRegressor.ts:184
predict()
predict(
opts
):Promise
<ArrayLike
>
Predict regression target 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/GradientBoostingRegressor.ts:367
score()
score(
opts
):Promise
<number
>
Return the coefficient of determination of the prediction.
The coefficient of determination \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true \- y_pred)\*\* 2).sum()
and \(v\) is the total sum of squares ((y_true \- y_true.mean()) \*\* 2).sum()
. The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y
, disregarding the input features, would get a \(R^2\) score of 0.0.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | ArrayLike | Sample weights. |
opts.X ? | ArrayLike [] | Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted) , where n_samples_fitted is the number of samples used in the fitting for the estimator. |
opts.y ? | ArrayLike | True values for X . |
Returns Promise
<number
>
Defined in generated/ensemble/GradientBoostingRegressor.ts:405
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/GradientBoostingRegressor.ts:455
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/GradientBoostingRegressor.ts:500
staged_predict()
staged_predict(
opts
):Promise
<any
[]>
Predict regression target 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/GradientBoostingRegressor.ts:538