BaggingClassifier
A Bagging classifier.
A Bagging classifier is an ensemble meta-estimator that fits base classifiers 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 BaggingClassifier(opts?: object): BaggingClassifier;
Parameters
Name | Type | Description |
---|---|---|
opts? | object | - |
opts.base_estimator? | any | Use estimator instead. Default Value 'deprecated' |
opts.bootstrap? | boolean | Whether samples are drawn with replacement. If false , sampling without replacement is performed. Default Value true |
opts.bootstrap_features? | boolean | Whether features are drawn with replacement. Default Value false |
opts.estimator? | any | The base estimator to fit on random subsets of the dataset. If undefined , then the base estimator is a DecisionTreeClassifier . |
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). Default Value 1 |
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). Default Value 1 |
opts.n_estimators? | number | The number of base estimators in the ensemble. Default Value 10 |
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 (opens in a new tab) 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 . Default Value false |
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. 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, otherwise, just fit a whole new ensemble. See the Glossary. Default Value false |
Returns
Defined in: generated/ensemble/BaggingClassifier.ts:27 (opens in a new tab)
Methods
decision_function()
Average of the decision functions of the base classifiers.
Signature
decision_function(opts: object): Promise<ArrayLike[]>;
Parameters
Name | 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/BaggingClassifier.ts:198 (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/BaggingClassifier.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
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | The training input samples. Sparse matrices are accepted only if they are supported by the base estimator. |
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.y? | ArrayLike | The target values (class labels in classification, real numbers in regression). |
Returns
Promise
<any
>
Defined in: generated/ensemble/BaggingClassifier.ts:236 (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/BaggingClassifier.ts:287 (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/BaggingClassifier.ts:123 (opens in a new tab)
predict()
Predict class for X.
The predicted class of an input sample is computed as the class with the highest mean predicted probability. If base estimators do not implement a predict\_proba
method, then it resorts to voting.
Signature
predict(opts: object): Promise<ArrayLike>;
Parameters
Name | 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/BaggingClassifier.ts:327 (opens in a new tab)
predict_log_proba()
Predict class log-probabilities for X.
The predicted class log-probabilities of an input sample is computed as the log of the mean predicted class probabilities of the base estimators in the ensemble.
Signature
predict_log_proba(opts: object): Promise<ArrayLike[]>;
Parameters
Name | 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/BaggingClassifier.ts:364 (opens in a new tab)
predict_proba()
Predict class probabilities for X.
The predicted class probabilities of an input sample is computed as the mean predicted class probabilities of the base estimators in the ensemble. If base estimators do not implement a predict\_proba
method, then it resorts to voting and the predicted class probabilities of an input sample represents the proportion of estimators predicting each class.
Signature
predict_proba(opts: object): Promise<ArrayLike[]>;
Parameters
Name | 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/BaggingClassifier.ts:404 (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/BaggingClassifier.ts:443 (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/BaggingClassifier.ts:496 (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/BaggingClassifier.ts:538 (opens in a new tab)
Properties
_isDisposed
boolean
=false
Defined in: generated/ensemble/BaggingClassifier.ts:25 (opens in a new tab)
_isInitialized
boolean
=false
Defined in: generated/ensemble/BaggingClassifier.ts:24 (opens in a new tab)
_py
PythonBridge
Defined in: generated/ensemble/BaggingClassifier.ts:23 (opens in a new tab)
id
string
Defined in: generated/ensemble/BaggingClassifier.ts:20 (opens in a new tab)
opts
any
Defined in: generated/ensemble/BaggingClassifier.ts:21 (opens in a new tab)
Accessors
classes_
The classes labels.
Signature
classes_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/ensemble/BaggingClassifier.ts:711 (opens in a new tab)
estimator_
The base estimator from which the ensemble is grown.
Signature
estimator_(): Promise<any>;
Returns
Promise
<any
>
Defined in: generated/ensemble/BaggingClassifier.ts:576 (opens in a new tab)
estimators_
The collection of fitted base estimators.
Signature
estimators_(): Promise<any>;
Returns
Promise
<any
>
Defined in: generated/ensemble/BaggingClassifier.ts:657 (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/BaggingClassifier.ts:684 (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/BaggingClassifier.ts:630 (opens in a new tab)
n_classes_
The number of classes.
Signature
n_classes_(): Promise<number | any[]>;
Returns
Promise
<number
| any
[]>
Defined in: generated/ensemble/BaggingClassifier.ts:738 (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/BaggingClassifier.ts:603 (opens in a new tab)
oob_decision_function_
Decision function 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\_decision\_function\_
might contain NaN. This attribute exists only when oob\_score
is true
.
Signature
oob_decision_function_(): Promise<ArrayLike[]>;
Returns
Promise
<ArrayLike
[]>
Defined in: generated/ensemble/BaggingClassifier.ts:792 (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/BaggingClassifier.ts:765 (opens in a new tab)
py
Signature
py(): PythonBridge;
Returns
PythonBridge
Defined in: generated/ensemble/BaggingClassifier.ts:110 (opens in a new tab)
Signature
py(pythonBridge: PythonBridge): void;
Parameters
Name | Type |
---|---|
pythonBridge | PythonBridge |
Returns
void
Defined in: generated/ensemble/BaggingClassifier.ts:114 (opens in a new tab)