Class: 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.
Constructors
new BaggingClassifier()
new BaggingClassifier(
opts
?):BaggingClassifier
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 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). |
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 BaggingClassifier
Defined in generated/ensemble/BaggingClassifier.ts:27
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/ensemble/BaggingClassifier.ts:25 |
_isInitialized | boolean | false | generated/ensemble/BaggingClassifier.ts:24 |
_py | PythonBridge | undefined | generated/ensemble/BaggingClassifier.ts:23 |
id | string | undefined | generated/ensemble/BaggingClassifier.ts:20 |
opts | any | undefined | generated/ensemble/BaggingClassifier.ts:21 |
Accessors
classes_
Get Signature
get classes_():
Promise
<ArrayLike
>
The classes labels.
Returns Promise
<ArrayLike
>
Defined in generated/ensemble/BaggingClassifier.ts:670
estimator_
Get Signature
get estimator_():
Promise
<any
>
The base estimator from which the ensemble is grown.
Returns Promise
<any
>
Defined in generated/ensemble/BaggingClassifier.ts:535
estimators_
Get Signature
get estimators_():
Promise
<any
>
The collection of fitted base estimators.
Returns Promise
<any
>
Defined in generated/ensemble/BaggingClassifier.ts:616
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/BaggingClassifier.ts:643
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/BaggingClassifier.ts:589
n_classes_
Get Signature
get n_classes_():
Promise
<number
|any
[]>
The number of classes.
Returns Promise
<number
| any
[]>
Defined in generated/ensemble/BaggingClassifier.ts:697
n_features_in_
Get Signature
get n_features_in_():
Promise
<number
>
Number of features seen during fit.
Returns Promise
<number
>
Defined in generated/ensemble/BaggingClassifier.ts:562
oob_decision_function_
Get Signature
get oob_decision_function_():
Promise
<ArrayLike
[]>
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
.
Returns Promise
<ArrayLike
[]>
Defined in generated/ensemble/BaggingClassifier.ts:751
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/BaggingClassifier.ts:724
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/BaggingClassifier.ts:103
Methods
decision_function()
decision_function(
opts
):Promise
<ArrayLike
[]>
Average of the decision functions of the base classifiers.
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/BaggingClassifier.ts:174
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/BaggingClassifier.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/BaggingClassifier.ts:210
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/BaggingClassifier.ts:261
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/BaggingClassifier.ts:116
predict()
predict(
opts
):Promise
<ArrayLike
>
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.
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/BaggingClassifier.ts:299
predict_log_proba()
predict_log_proba(
opts
):Promise
<ArrayLike
[]>
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.
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/BaggingClassifier.ts:335
predict_proba()
predict_proba(
opts
):Promise
<ArrayLike
[]>
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.
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/BaggingClassifier.ts:373
score()
score(
opts
):Promise
<number
>
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.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | ArrayLike | Sample weights. |
opts.X ? | ArrayLike [] | Test samples. |
opts.y ? | ArrayLike | True labels for X . |
Returns Promise
<number
>
Defined in generated/ensemble/BaggingClassifier.ts:411
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/BaggingClassifier.ts:459
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/BaggingClassifier.ts:499