Documentation
Classes
BaggingRegressor

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.

Python Reference (opens in a new tab)

Constructors

constructor()

Signature

new BaggingRegressor(opts?: object): BaggingRegressor;

Parameters

NameTypeDescription
opts?object-
opts.base_estimator?anyUse estimator instead. Default Value 'deprecated'
opts.bootstrap?booleanWhether samples are drawn with replacement. If false, sampling without replacement is performed. Default Value true
opts.bootstrap_features?booleanWhether features are drawn with replacement. Default Value false
opts.estimator?anyThe base estimator to fit on random subsets of the dataset. If undefined, then the base estimator is a DecisionTreeRegressor.
opts.max_features?numberThe number of features to draw from X to train each base estimator ( without replacement by default, see bootstrap\_features for more details). Default Value 1
opts.max_samples?numberThe number of samples to draw from X to train each base estimator (with replacement by default, see bootstrap for more details). Default Value 1
opts.n_estimators?numberThe number of base estimators in the ensemble. Default Value 10
opts.n_jobs?numberThe number of jobs to run in parallel for both fit and predict. undefined means 1 unless in a joblib.parallel\_backend (opens in a new tab) context. \-1 means using all processors. See Glossary for more details.
opts.oob_score?booleanWhether to use out-of-bag samples to estimate the generalization error. Only available if bootstrap=true. Default Value false
opts.random_state?numberControls 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?numberControls the verbosity when fitting and predicting. Default Value 0
opts.warm_start?booleanWhen 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. Default Value false

Returns

BaggingRegressor

Defined in: generated/ensemble/BaggingRegressor.ts:27 (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/BaggingRegressor.ts:181 (opens in a new tab)

fit()

Build a Bagging ensemble of estimators from the training set (X, y).

Signature

fit(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeThe training input samples. Sparse matrices are accepted only if they are supported by the base estimator.
opts.sample_weight?ArrayLikeSample weights. If undefined, then samples are equally weighted. Note that this is supported only if the base estimator supports sample weighting.
opts.y?ArrayLikeThe target values (class labels in classification, real numbers in regression).

Returns

Promise<any>

Defined in: generated/ensemble/BaggingRegressor.ts:198 (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

NameTypeDescription
optsobject-
opts.routing?anyA MetadataRequest encapsulating routing information.

Returns

Promise<any>

Defined in: generated/ensemble/BaggingRegressor.ts:249 (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

NameType
pyPythonBridge

Returns

Promise<void>

Defined in: generated/ensemble/BaggingRegressor.ts:123 (opens in a new tab)

predict()

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.

Signature

predict(opts: object): Promise<ArrayLike>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeThe 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:288 (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

NameTypeDescription
optsobject-
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?ArrayLikeSample weights.
opts.y?ArrayLikeTrue values for X.

Returns

Promise<number>

Defined in: generated/ensemble/BaggingRegressor.ts:325 (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

NameTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample\_weight parameter in fit.

Returns

Promise<any>

Defined in: generated/ensemble/BaggingRegressor.ts:378 (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

NameTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample\_weight parameter in score.

Returns

Promise<any>

Defined in: generated/ensemble/BaggingRegressor.ts:420 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/ensemble/BaggingRegressor.ts:25 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/ensemble/BaggingRegressor.ts:24 (opens in a new tab)

_py

PythonBridge

Defined in: generated/ensemble/BaggingRegressor.ts:23 (opens in a new tab)

id

string

Defined in: generated/ensemble/BaggingRegressor.ts:20 (opens in a new tab)

opts

any

Defined in: generated/ensemble/BaggingRegressor.ts:21 (opens in a new tab)

Accessors

estimator_

The base estimator from which the ensemble is grown.

Signature

estimator_(): Promise<any>;

Returns

Promise<any>

Defined in: generated/ensemble/BaggingRegressor.ts:458 (opens in a new tab)

estimators_

The collection of fitted sub-estimators.

Signature

estimators_(): Promise<any>;

Returns

Promise<any>

Defined in: generated/ensemble/BaggingRegressor.ts:539 (opens in a new tab)

estimators_features_

The subset of drawn features for each base estimator.

Signature

estimators_features_(): Promise<any>;

Returns

Promise<any>

Defined in: generated/ensemble/BaggingRegressor.ts:566 (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/BaggingRegressor.ts:512 (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/BaggingRegressor.ts:485 (opens in a new tab)

oob_prediction_

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.

Signature

oob_prediction_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/ensemble/BaggingRegressor.ts:620 (opens in a new tab)

oob_score_

Score of the training dataset obtained using an out-of-bag estimate. This attribute exists only when oob\_score is true.

Signature

oob_score_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/ensemble/BaggingRegressor.ts:593 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/ensemble/BaggingRegressor.ts:110 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/ensemble/BaggingRegressor.ts:114 (opens in a new tab)