HistGradientBoostingRegressor
Histogram-based Gradient Boosting Regression Tree.
This estimator is much faster than GradientBoostingRegressor
for big datasets (n_samples >= 10 000).
This estimator has native support for missing values (NaNs). During training, the tree grower learns at each split point whether samples with missing values should go to the left or right child, based on the potential gain. When predicting, samples with missing values are assigned to the left or right child consequently. If no missing values were encountered for a given feature during training, then samples with missing values are mapped to whichever child has the most samples.
This implementation is inspired by LightGBM (opens in a new tab).
Read more in the User Guide.
Python Reference (opens in a new tab)
Constructors
constructor()
Signature
new HistGradientBoostingRegressor(opts?: object): HistGradientBoostingRegressor;
Parameters
Name | Type | Description |
---|---|---|
opts? | object | - |
opts.categorical_features? | number | Indicates the categorical features. |
opts.early_stopping? | boolean | "auto" | If ‘auto’, early stopping is enabled if the sample size is larger than 10000. If true , early stopping is enabled, otherwise early stopping is disabled. Default Value 'auto' |
opts.interaction_cst? | "pairwise" | "no_interactions" | Specify interaction constraints, the sets of features which can interact with each other in child node splits. Each item specifies the set of feature indices that are allowed to interact with each other. If there are more features than specified in these constraints, they are treated as if they were specified as an additional set. The strings “pairwise” and “no_interactions” are shorthands for allowing only pairwise or no interactions, respectively. For instance, with 5 features in total, interaction\_cst=\[{0, 1}\] is equivalent to interaction\_cst=\[{0, 1}, {2, 3, 4}\] , and specifies that each branch of a tree will either only split on features 0 and 1 or only split on features 2, 3 and 4. |
opts.l2_regularization? | number | The L2 regularization parameter. Use 0 for no regularization (default). Default Value 0 |
opts.learning_rate? | number | The learning rate, also known as shrinkage. This is used as a multiplicative factor for the leaves values. Use 1 for no shrinkage. Default Value 0.1 |
opts.loss? | "quantile" | "gamma" | "squared_error" | "absolute_error" | "poisson" | The loss function to use in the boosting process. Note that the “squared error”, “gamma” and “poisson” losses actually implement “half least squares loss”, “half gamma deviance” and “half poisson deviance” to simplify the computation of the gradient. Furthermore, “gamma” and “poisson” losses internally use a log-link, “gamma” requires y > 0 and “poisson” requires y >= 0 . “quantile” uses the pinball loss. Default Value 'squared_error' |
opts.max_bins? | number | The maximum number of bins to use for non-missing values. Before training, each feature of the input array X is binned into integer-valued bins, which allows for a much faster training stage. Features with a small number of unique values may use less than max\_bins bins. In addition to the max\_bins bins, one more bin is always reserved for missing values. Must be no larger than 255. Default Value 255 |
opts.max_depth? | number | The maximum depth of each tree. The depth of a tree is the number of edges to go from the root to the deepest leaf. Depth isn’t constrained by default. |
opts.max_iter? | number | The maximum number of iterations of the boosting process, i.e. the maximum number of trees. Default Value 100 |
opts.max_leaf_nodes? | number | The maximum number of leaves for each tree. Must be strictly greater than 1. If undefined , there is no maximum limit. Default Value 31 |
opts.min_samples_leaf? | number | The minimum number of samples per leaf. For small datasets with less than a few hundred samples, it is recommended to lower this value since only very shallow trees would be built. Default Value 20 |
opts.monotonic_cst? | any | Monotonic constraint to enforce on each feature are specified using the following integer values: |
opts.n_iter_no_change? | number | Used to determine when to “early stop”. The fitting process is stopped when none of the last n\_iter\_no\_change scores are better than the n\_iter\_no\_change \- 1 -th-to-last one, up to some tolerance. Only used if early stopping is performed. Default Value 10 |
opts.quantile? | number | If loss is “quantile”, this parameter specifies which quantile to be estimated and must be between 0 and 1. |
opts.random_state? | number | Pseudo-random number generator to control the subsampling in the binning process, and the train/validation data split if early stopping is enabled. Pass an int for reproducible output across multiple function calls. See Glossary. |
opts.scoring? | string | Scoring parameter to use for early stopping. It can be a single string (see The scoring parameter: defining model evaluation rules) or a callable (see Defining your scoring strategy from metric functions). If undefined , the estimator’s default scorer is used. If scoring='loss' , early stopping is checked w.r.t the loss value. Only used if early stopping is performed. Default Value 'loss' |
opts.tol? | number | The absolute tolerance to use when comparing scores during early stopping. The higher the tolerance, the more likely we are to early stop: higher tolerance means that it will be harder for subsequent iterations to be considered an improvement upon the reference score. Default Value 1e-7 |
opts.validation_fraction? | number | Proportion (or absolute size) of training data to set aside as validation data for early stopping. If undefined , early stopping is done on the training data. Only used if early stopping is performed. Default Value 0.1 |
opts.verbose? | number | The verbosity level. If not zero, print some information about the fitting process. Default Value 0 |
opts.warm_start? | boolean | When set to true , reuse the solution of the previous call to fit and add more estimators to the ensemble. For results to be valid, the estimator should be re-trained on the same data only. See the Glossary. Default Value false |
Returns
Defined in: generated/ensemble/HistGradientBoostingRegressor.ts:29 (opens in a new tab)
Methods
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/HistGradientBoostingRegressor.ts:261 (opens in a new tab)
fit()
Fit the gradient boosting model.
Signature
fit(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | The input samples. |
opts.sample_weight? | any | Weights of training data. |
opts.y? | ArrayLike | Target values. |
Returns
Promise
<any
>
Defined in: generated/ensemble/HistGradientBoostingRegressor.ts:278 (opens in a new tab)
get_metadata_routing()
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Signature
get_metadata_routing(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.routing? | any | A MetadataRequest encapsulating routing information. |
Returns
Promise
<any
>
Defined in: generated/ensemble/HistGradientBoostingRegressor.ts:331 (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
Name | Type |
---|---|
py | PythonBridge |
Returns
Promise
<void
>
Defined in: generated/ensemble/HistGradientBoostingRegressor.ts:183 (opens in a new tab)
predict()
Predict values for X.
Signature
predict(opts: object): Promise<ArrayLike>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | The input samples. |
Returns
Promise
<ArrayLike
>
Defined in: generated/ensemble/HistGradientBoostingRegressor.ts:369 (opens in a new tab)
score()
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.
Signature
score(opts: object): Promise<number>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
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.sample_weight? | ArrayLike | Sample weights. |
opts.y? | ArrayLike | True values for X . |
Returns
Promise
<number
>
Defined in: generated/ensemble/HistGradientBoostingRegressor.ts:408 (opens in a new tab)
set_fit_request()
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:
Signature
set_fit_request(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight? | string | boolean | Metadata routing for sample\_weight parameter in fit . |
Returns
Promise
<any
>
Defined in: generated/ensemble/HistGradientBoostingRegressor.ts:464 (opens in a new tab)
set_score_request()
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:
Signature
set_score_request(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight? | string | boolean | Metadata routing for sample\_weight parameter in score . |
Returns
Promise
<any
>
Defined in: generated/ensemble/HistGradientBoostingRegressor.ts:506 (opens in a new tab)
staged_predict()
Predict regression target for each iteration.
This method allows monitoring (i.e. determine error on testing set) after each stage.
Signature
staged_predict(opts: object): Promise<any[]>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | The input samples. |
Returns
Promise
<any
[]>
Defined in: generated/ensemble/HistGradientBoostingRegressor.ts:546 (opens in a new tab)
Properties
_isDisposed
boolean
=false
Defined in: generated/ensemble/HistGradientBoostingRegressor.ts:27 (opens in a new tab)
_isInitialized
boolean
=false
Defined in: generated/ensemble/HistGradientBoostingRegressor.ts:26 (opens in a new tab)
_py
PythonBridge
Defined in: generated/ensemble/HistGradientBoostingRegressor.ts:25 (opens in a new tab)
id
string
Defined in: generated/ensemble/HistGradientBoostingRegressor.ts:22 (opens in a new tab)
opts
any
Defined in: generated/ensemble/HistGradientBoostingRegressor.ts:23 (opens in a new tab)
Accessors
do_early_stopping_
Indicates whether early stopping is used during training.
Signature
do_early_stopping_(): Promise<boolean>;
Returns
Promise
<boolean
>
Defined in: generated/ensemble/HistGradientBoostingRegressor.ts:584 (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/HistGradientBoostingRegressor.ts:746 (opens in a new tab)
is_categorical_
Boolean mask for the categorical features. undefined
if there are no categorical features.
Signature
is_categorical_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/ensemble/HistGradientBoostingRegressor.ts:692 (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/HistGradientBoostingRegressor.ts:719 (opens in a new tab)
n_trees_per_iteration_
The number of tree that are built at each iteration. For regressors, this is always 1.
Signature
n_trees_per_iteration_(): Promise<number>;
Returns
Promise
<number
>
Defined in: generated/ensemble/HistGradientBoostingRegressor.ts:611 (opens in a new tab)
py
Signature
py(): PythonBridge;
Returns
PythonBridge
Defined in: generated/ensemble/HistGradientBoostingRegressor.ts:170 (opens in a new tab)
Signature
py(pythonBridge: PythonBridge): void;
Parameters
Name | Type |
---|---|
pythonBridge | PythonBridge |
Returns
void
Defined in: generated/ensemble/HistGradientBoostingRegressor.ts:174 (opens in a new tab)
train_score_
The scores at each iteration on the training data. The first entry is the score of the ensemble before the first iteration. Scores are computed according to the scoring
parameter. If scoring
is not ‘loss’, scores are computed on a subset of at most 10 000 samples. Empty if no early stopping.
Signature
train_score_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/ensemble/HistGradientBoostingRegressor.ts:638 (opens in a new tab)
validation_score_
The scores at each iteration on the held-out validation data. The first entry is the score of the ensemble before the first iteration. Scores are computed according to the scoring
parameter. Empty if no early stopping or if validation\_fraction
is undefined
.
Signature
validation_score_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/ensemble/HistGradientBoostingRegressor.ts:665 (opens in a new tab)