Class: StackingClassifier
Stack of estimators with a final classifier.
Stacked generalization consists in stacking the output of individual estimator and use a classifier to compute the final prediction. Stacking allows to use the strength of each individual estimator by using their output as input of a final estimator.
Note that estimators_ are fitted on the full X while final_estimator_ is trained using cross-validated predictions of the base estimators using cross_val_predict.
Read more in the User Guide.
Constructors
new StackingClassifier()
new StackingClassifier(
opts?):StackingClassifier
Parameters
| Parameter | Type | Description |
|---|---|---|
opts? | object | - |
opts.cv? | number | "prefit" | Determines the cross-validation splitting strategy used in cross_val_predict to train final_estimator. Possible inputs for cv are: |
opts.estimators? | any | Base estimators which will be stacked together. Each element of the list is defined as a tuple of string (i.e. name) and an estimator instance. An estimator can be set to ‘drop’ using set_params. The type of estimator is generally expected to be a classifier. However, one can pass a regressor for some use case (e.g. ordinal regression). |
opts.final_estimator? | any | A classifier which will be used to combine the base estimators. The default classifier is a LogisticRegression. |
opts.n_jobs? | number | The number of jobs to run in parallel all estimators fit. undefined means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details. |
opts.passthrough? | boolean | When false, only the predictions of estimators will be used as training data for final_estimator. When true, the final_estimator is trained on the predictions as well as the original training data. |
opts.stack_method? | "auto" | "predict_proba" | "decision_function" | "predict" | Methods called for each base estimator. It can be: |
opts.verbose? | number | Verbosity level. |
Returns StackingClassifier
Defined in generated/ensemble/StackingClassifier.ts:27
Properties
| Property | Type | Default value | Defined in |
|---|---|---|---|
_isDisposed | boolean | false | generated/ensemble/StackingClassifier.ts:25 |
_isInitialized | boolean | false | generated/ensemble/StackingClassifier.ts:24 |
_py | PythonBridge | undefined | generated/ensemble/StackingClassifier.ts:23 |
id | string | undefined | generated/ensemble/StackingClassifier.ts:20 |
opts | any | undefined | generated/ensemble/StackingClassifier.ts:21 |
Accessors
classes_
Get Signature
get classes_():
Promise<ArrayLike>
Class labels.
Returns Promise<ArrayLike>
Defined in generated/ensemble/StackingClassifier.ts:615
estimators_
Get Signature
get estimators_():
Promise<any>
The elements of the estimators parameter, having been fitted on the training data. If an estimator has been set to 'drop', it will not appear in estimators_. When cv="prefit", estimators_ is set to estimators and is not fitted again.
Returns Promise<any>
Defined in generated/ensemble/StackingClassifier.ts:642
feature_names_in_
Get Signature
get feature_names_in_():
Promise<ArrayLike>
Names of features seen during fit. Only defined if the underlying estimators expose such an attribute when fit.
Returns Promise<ArrayLike>
Defined in generated/ensemble/StackingClassifier.ts:696
final_estimator_
Get Signature
get final_estimator_():
Promise<any>
The classifier which predicts given the output of estimators_.
Returns Promise<any>
Defined in generated/ensemble/StackingClassifier.ts:723
named_estimators_
Get Signature
get named_estimators_():
Promise<any>
Attribute to access any fitted sub-estimators by name.
Returns Promise<any>
Defined in generated/ensemble/StackingClassifier.ts:669
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/StackingClassifier.ts:75
stack_method_
Get Signature
get stack_method_():
Promise<any>
The method used by each base estimator.
Returns Promise<any>
Defined in generated/ensemble/StackingClassifier.ts:750
Methods
decision_function()
decision_function(
opts):Promise<ArrayLike>
Decision function for samples in X using the final estimator.
Parameters
| Parameter | Type | Description |
|---|---|---|
opts | object | - |
opts.X? | ArrayLike | Training vectors, where n_samples is the number of samples and n_features is the number of features. |
Returns Promise<ArrayLike>
Defined in generated/ensemble/StackingClassifier.ts:148
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/StackingClassifier.ts:131
fit()
fit(
opts):Promise<any>
Fit the estimators.
Parameters
| Parameter | Type | Description |
|---|---|---|
opts | object | - |
opts.sample_weight? | ArrayLike | Sample weights. If undefined, then samples are equally weighted. Note that this is supported only if all underlying estimators support sample weights. |
opts.X? | ArrayLike | Training vectors, where n_samples is the number of samples and n_features is the number of features. |
opts.y? | ArrayLike | Target values. Note that y will be internally encoded in numerically increasing order or lexicographic order. If the order matter (e.g. for ordinal regression), one should numerically encode the target y before calling fit. |
Returns Promise<any>
Defined in generated/ensemble/StackingClassifier.ts:184
fit_transform()
fit_transform(
opts):Promise<any[]>
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
Parameters
| Parameter | Type | Description |
|---|---|---|
opts | object | - |
opts.fit_params? | any | Additional fit parameters. |
opts.X? | ArrayLike[] | Input samples. |
opts.y? | ArrayLike | Target values (undefined for unsupervised transformations). |
Returns Promise<any[]>
Defined in generated/ensemble/StackingClassifier.ts:230
get_feature_names_out()
get_feature_names_out(
opts):Promise<any>
Get output feature names for transformation.
Parameters
| Parameter | Type | Description |
|---|---|---|
opts | object | - |
opts.input_features? | any | Input features. The input feature names are only used when passthrough is true. |
Returns Promise<any>
Defined in generated/ensemble/StackingClassifier.ts:276
get_metadata_routing()
get_metadata_routing(
opts):Promise<any>
Raise NotImplementedError.
This estimator does not support metadata routing yet.
Parameters
| Parameter | Type |
|---|---|
opts | object |
Returns Promise<any>
Defined in generated/ensemble/StackingClassifier.ts:314
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/StackingClassifier.ts:88
predict()
predict(
opts):Promise<ArrayLike>
Predict target for X.
Parameters
| Parameter | Type | Description |
|---|---|---|
opts | object | - |
opts.predict_params? | any | Parameters to the predict called by the final_estimator. Note that this may be used to return uncertainties from some estimators with return_std or return_cov. Be aware that it will only accounts for uncertainty in the final estimator. |
opts.X? | ArrayLike | Training vectors, where n_samples is the number of samples and n_features is the number of features. |
Returns Promise<ArrayLike>
Defined in generated/ensemble/StackingClassifier.ts:344
predict_proba()
predict_proba(
opts):Promise<any[] |ArrayLike[]>
Predict class probabilities for X using the final estimator.
Parameters
| Parameter | Type | Description |
|---|---|---|
opts | object | - |
opts.X? | ArrayLike | Training vectors, where n_samples is the number of samples and n_features is the number of features. |
Returns Promise<any[] | ArrayLike[]>
Defined in generated/ensemble/StackingClassifier.ts:383
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/StackingClassifier.ts:421
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/StackingClassifier.ts:469
set_output()
set_output(
opts):Promise<any>
Set output container.
See Introducing the set_output API for an example on how to use the API.
Parameters
| Parameter | Type | Description |
|---|---|---|
opts | object | - |
opts.transform? | "default" | "pandas" | "polars" | Configure output of transform and fit_transform. |
Returns Promise<any>
Defined in generated/ensemble/StackingClassifier.ts:507
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/StackingClassifier.ts:545
transform()
transform(
opts):Promise<ArrayLike[]>
Return class labels or probabilities for X for each estimator.
Parameters
| Parameter | Type | Description |
|---|---|---|
opts | object | - |
opts.X? | ArrayLike | Training vectors, where n_samples is the number of samples and n_features is the number of features. |
Returns Promise<ArrayLike[]>
Defined in generated/ensemble/StackingClassifier.ts:581