Class: BaggingRegressor
A Bagging regressor.
A Bagging regressor is an ensemble meta-estimator that fits base regressors each on random subsets of the original dataset and then aggregate their individual predictions (either by voting or by averaging) to form a final prediction. Such a meta-estimator can typically be used as a way to reduce the variance of a black-box estimator (e.g., a decision tree), by introducing randomization into its construction procedure and then making an ensemble out of it.
This algorithm encompasses several works from the literature. When random subsets of the dataset are drawn as random subsets of the samples, then this algorithm is known as Pasting [1]. If samples are drawn with replacement, then the method is known as Bagging [2]. When random subsets of the dataset are drawn as random subsets of the features, then the method is known as Random Subspaces [3]. Finally, when base estimators are built on subsets of both samples and features, then the method is known as Random Patches [4].
Read more in the User Guide.
Constructors
new BaggingRegressor()
new BaggingRegressor(
opts
?):BaggingRegressor
Parameters
Parameter | Type | Description |
---|---|---|
opts ? | object | - |
opts.bootstrap ? | boolean | Whether samples are drawn with replacement. If false , sampling without replacement is performed. |
opts.bootstrap_features ? | boolean | Whether features are drawn with replacement. |
opts.estimator ? | any | The base estimator to fit on random subsets of the dataset. If undefined , then the base estimator is a DecisionTreeRegressor . |
opts.max_features ? | number | The number of features to draw from X to train each base estimator ( without replacement by default, see bootstrap_features for more details). |
opts.max_samples ? | number | The number of samples to draw from X to train each base estimator (with replacement by default, see bootstrap for more details). |
opts.n_estimators ? | number | The number of base estimators in the ensemble. |
opts.n_jobs ? | number | The number of jobs to run in parallel for both fit and predict . undefined means 1 unless in a joblib.parallel_backend context. \-1 means using all processors. See Glossary for more details. |
opts.oob_score ? | boolean | Whether to use out-of-bag samples to estimate the generalization error. Only available if bootstrap=true . |
opts.random_state ? | number | Controls the random resampling of the original dataset (sample wise and feature wise). If the base estimator accepts a random_state attribute, a different seed is generated for each instance in the ensemble. Pass an int for reproducible output across multiple function calls. See Glossary. |
opts.verbose ? | number | Controls the verbosity when fitting and predicting. |
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 fit a whole new ensemble. See the Glossary. |
Returns BaggingRegressor
Defined in generated/ensemble/BaggingRegressor.ts:27
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/ensemble/BaggingRegressor.ts:25 |
_isInitialized | boolean | false | generated/ensemble/BaggingRegressor.ts:24 |
_py | PythonBridge | undefined | generated/ensemble/BaggingRegressor.ts:23 |
id | string | undefined | generated/ensemble/BaggingRegressor.ts:20 |
opts | any | undefined | generated/ensemble/BaggingRegressor.ts:21 |
Accessors
estimator_
Get Signature
get estimator_():
Promise
<any
>
The base estimator from which the ensemble is grown.
Returns Promise
<any
>
Defined in generated/ensemble/BaggingRegressor.ts:423
estimators_
Get Signature
get estimators_():
Promise
<any
>
The collection of fitted sub-estimators.
Returns Promise
<any
>
Defined in generated/ensemble/BaggingRegressor.ts:504
estimators_features_
Get Signature
get estimators_features_():
Promise
<any
>
The subset of drawn features for each base estimator.
Returns Promise
<any
>
Defined in generated/ensemble/BaggingRegressor.ts:531
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/BaggingRegressor.ts:477
n_features_in_
Get Signature
get n_features_in_():
Promise
<number
>
Number of features seen during fit.
Returns Promise
<number
>
Defined in generated/ensemble/BaggingRegressor.ts:450
oob_prediction_
Get Signature
get oob_prediction_():
Promise
<ArrayLike
>
Prediction computed with out-of-bag estimate on the training set. If n_estimators is small it might be possible that a data point was never left out during the bootstrap. In this case, oob_prediction_
might contain NaN. This attribute exists only when oob_score
is true
.
Returns Promise
<ArrayLike
>
Defined in generated/ensemble/BaggingRegressor.ts:585
oob_score_
Get Signature
get oob_score_():
Promise
<number
>
Score of the training dataset obtained using an out-of-bag estimate. This attribute exists only when oob_score
is true
.
Returns Promise
<number
>
Defined in generated/ensemble/BaggingRegressor.ts:558
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/BaggingRegressor.ts:103
Methods
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/BaggingRegressor.ts:157
fit()
fit(
opts
):Promise
<any
>
Build a Bagging ensemble of estimators from the training set (X, y).
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.fit_params ? | any | Parameters to pass to the underlying estimators. |
opts.sample_weight ? | ArrayLike | Sample weights. If undefined , then samples are equally weighted. Note that this is supported only if the base estimator supports sample weighting. |
opts.X ? | ArrayLike | The training input samples. Sparse matrices are accepted only if they are supported by the base estimator. |
opts.y ? | ArrayLike | The target values (class labels in classification, real numbers in regression). |
Returns Promise
<any
>
Defined in generated/ensemble/BaggingRegressor.ts:174
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 MetadataRouter encapsulating routing information. |
Returns Promise
<any
>
Defined in generated/ensemble/BaggingRegressor.ts:225
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/BaggingRegressor.ts:116
predict()
predict(
opts
):Promise
<ArrayLike
>
Predict regression target for X.
The predicted regression target of an input sample is computed as the mean predicted regression targets of the estimators in the ensemble.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | The training input samples. Sparse matrices are accepted only if they are supported by the base estimator. |
Returns Promise
<ArrayLike
>
Defined in generated/ensemble/BaggingRegressor.ts:263
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/BaggingRegressor.ts:299
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.sample_weight ? | string | boolean | Metadata routing for sample_weight parameter in fit . |
Returns Promise
<any
>
Defined in generated/ensemble/BaggingRegressor.ts:347
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/BaggingRegressor.ts:387