Class: StackingRegressor
Stack of estimators with a final regressor.
Stacked generalization consists in stacking the output of individual estimator and use a regressor 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 StackingRegressor()
new StackingRegressor(
opts?):StackingRegressor
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. |
opts.final_estimator? | any | A regressor which will be used to combine the base estimators. The default regressor is a RidgeCV. |
opts.n_jobs? | number | The number of jobs to run in parallel for fit of all estimators. 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.verbose? | number | Verbosity level. |
Returns StackingRegressor
Defined in generated/ensemble/StackingRegressor.ts:27
Properties
| Property | Type | Default value | Defined in |
|---|---|---|---|
_isDisposed | boolean | false | generated/ensemble/StackingRegressor.ts:25 |
_isInitialized | boolean | false | generated/ensemble/StackingRegressor.ts:24 |
_py | PythonBridge | undefined | generated/ensemble/StackingRegressor.ts:23 |
id | string | undefined | generated/ensemble/StackingRegressor.ts:20 |
opts | any | undefined | generated/ensemble/StackingRegressor.ts:21 |
Accessors
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/StackingRegressor.ts:530
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/StackingRegressor.ts:584
final_estimator_
Get Signature
get final_estimator_():
Promise<any>
The regressor to stacked the base estimators fitted.
Returns Promise<any>
Defined in generated/ensemble/StackingRegressor.ts:611
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/StackingRegressor.ts:557
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/StackingRegressor.ts:66
stack_method_
Get Signature
get stack_method_():
Promise<any>
The method used by each base estimator.
Returns Promise<any>
Defined in generated/ensemble/StackingRegressor.ts:638
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/StackingRegressor.ts:120
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. |
Returns Promise<any>
Defined in generated/ensemble/StackingRegressor.ts:137
fit_transform()
fit_transform(
opts):Promise<ArrayLike[]>
Fit the estimators and return the predictions for X for each estimator.
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. |
Returns Promise<ArrayLike[]>
Defined in generated/ensemble/StackingRegressor.ts:181
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/StackingRegressor.ts:227
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/StackingRegressor.ts:265
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/StackingRegressor.ts:79
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/StackingRegressor.ts:295
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/StackingRegressor.ts:336
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/StackingRegressor.ts:384
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/StackingRegressor.ts:422
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/StackingRegressor.ts:460
transform()
transform(
opts):Promise<ArrayLike[]>
Return the predictions 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/StackingRegressor.ts:496