HistGradientBoostingClassifier
Histogram-based Gradient Boosting Classification Tree.
This estimator is much faster than GradientBoostingClassifier
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 HistGradientBoostingClassifier(opts?: object): HistGradientBoostingClassifier;
Parameters
Name | Type | Description |
---|---|---|
opts? | object | - |
opts.categorical_features? | number | Indicates the categorical features. |
opts.class_weight? | any | Weights associated with classes in the form {class\_label: weight} . If not given, all classes are supposed to have weight one. The “balanced” mode uses the values of y to automatically adjust weights inversely proportional to class frequencies in the input data as n\_samples / (n\_classes \* np.bincount(y)) . Note that these weights will be multiplied with sample_weight (passed through the fit method) if sample\_weight is specified. |
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 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? | "log_loss" | The loss function to use in the boosting process. For binary classification problems, ‘log_loss’ is also known as logistic loss, binomial deviance or binary crossentropy. Internally, the model fits one tree per boosting iteration and uses the logistic sigmoid function (expit) as inverse link function to compute the predicted positive class probability. For multiclass classification problems, ‘log_loss’ is also known as multinomial deviance or categorical crossentropy. Internally, the model fits one tree per boosting iteration and per class and uses the softmax function as inverse link function to compute the predicted probabilities of the classes. Default Value 'log_loss' |
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 for binary classification. For multiclass classification, n\_classes trees per iteration are built. 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.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. 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
HistGradientBoostingClassifier
Defined in: generated/ensemble/HistGradientBoostingClassifier.ts:29 (opens in a new tab)
Methods
decision_function()
Compute the decision function of X
.
Signature
decision_function(opts: object): Promise<ArrayLike>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | The input samples. |
Returns
Promise
<ArrayLike
>
Defined in: generated/ensemble/HistGradientBoostingClassifier.ts:284 (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/HistGradientBoostingClassifier.ts:267 (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/HistGradientBoostingClassifier.ts:322 (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/HistGradientBoostingClassifier.ts:375 (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/HistGradientBoostingClassifier.ts:187 (opens in a new tab)
predict()
Predict classes 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/HistGradientBoostingClassifier.ts:413 (opens in a new tab)
predict_proba()
Predict class probabilities for X.
Signature
predict_proba(opts: object): Promise<ArrayLike>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | The input samples. |
Returns
Promise
<ArrayLike
>
Defined in: generated/ensemble/HistGradientBoostingClassifier.ts:450 (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
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | Test samples. |
opts.sample_weight? | ArrayLike | Sample weights. |
opts.y? | ArrayLike | True labels for X . |
Returns
Promise
<number
>
Defined in: generated/ensemble/HistGradientBoostingClassifier.ts:490 (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/HistGradientBoostingClassifier.ts:546 (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/HistGradientBoostingClassifier.ts:588 (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
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | The input samples. |
Returns
Promise
<any
[]>
Defined in: generated/ensemble/HistGradientBoostingClassifier.ts:628 (opens in a new tab)
staged_predict()
Predict classes at 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/HistGradientBoostingClassifier.ts:668 (opens in a new tab)
staged_predict_proba()
Predict class probabilities at each iteration.
This method allows monitoring (i.e. determine error on testing set) after each stage.
Signature
staged_predict_proba(opts: object): Promise<any[]>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | The input samples. |
Returns
Promise
<any
[]>
Defined in: generated/ensemble/HistGradientBoostingClassifier.ts:708 (opens in a new tab)
Properties
_isDisposed
boolean
=false
Defined in: generated/ensemble/HistGradientBoostingClassifier.ts:27 (opens in a new tab)
_isInitialized
boolean
=false
Defined in: generated/ensemble/HistGradientBoostingClassifier.ts:26 (opens in a new tab)
_py
PythonBridge
Defined in: generated/ensemble/HistGradientBoostingClassifier.ts:25 (opens in a new tab)
id
string
Defined in: generated/ensemble/HistGradientBoostingClassifier.ts:22 (opens in a new tab)
opts
any
Defined in: generated/ensemble/HistGradientBoostingClassifier.ts:23 (opens in a new tab)
Accessors
classes_
Class labels.
Signature
classes_(): Promise<any>;
Returns
Promise
<any
>
Defined in: generated/ensemble/HistGradientBoostingClassifier.ts:746 (opens in a new tab)
do_early_stopping_
Indicates whether early stopping is used during training.
Signature
do_early_stopping_(): Promise<boolean>;
Returns
Promise
<boolean
>
Defined in: generated/ensemble/HistGradientBoostingClassifier.ts:773 (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/HistGradientBoostingClassifier.ts:935 (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/HistGradientBoostingClassifier.ts:881 (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/HistGradientBoostingClassifier.ts:908 (opens in a new tab)
n_trees_per_iteration_
The number of tree that are built at each iteration. This is equal to 1 for binary classification, and to n\_classes
for multiclass classification.
Signature
n_trees_per_iteration_(): Promise<number>;
Returns
Promise
<number
>
Defined in: generated/ensemble/HistGradientBoostingClassifier.ts:800 (opens in a new tab)
py
Signature
py(): PythonBridge;
Returns
PythonBridge
Defined in: generated/ensemble/HistGradientBoostingClassifier.ts:174 (opens in a new tab)
Signature
py(pythonBridge: PythonBridge): void;
Parameters
Name | Type |
---|---|
pythonBridge | PythonBridge |
Returns
void
Defined in: generated/ensemble/HistGradientBoostingClassifier.ts:178 (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/HistGradientBoostingClassifier.ts:827 (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/HistGradientBoostingClassifier.ts:854 (opens in a new tab)