Prediction voting regressor for unfitted estimators.
A voting regressor is an ensemble meta-estimator that fits several base regressors, each on the whole dataset. Then it averages the individual predictions to form a final prediction.
For a detailed example, refer to Plot individual and voting regression predictions.
Read more in the User Guide.
Added in version 0.21.
Invoking the fit
method on the VotingRegressor
will fit clones of those original estimators that will be stored in the class attribute self.estimators_
. An estimator can be set to 'drop'
using set_params
.
Changed in version 0.21: 'drop'
is accepted. Using None was deprecated in 0.22 and support was removed in 0.24.
Sequence of weights (float
or int
) to weight the occurrences of predicted values before averaging. Uses uniform weights if None
.
The number of jobs to run in parallel for fit
. None
means 1 unless in a joblib.parallel_backend
context. -1
means using all processors. See Glossary for more details.
If True, the time elapsed while fitting will be printed as it is completed.
Added in version 0.23.
The collection of fitted sub-estimators as defined in estimators
that are not ‘drop’.
Bunch
Attribute to access any fitted sub-estimators by name.
Added in version 0.20.
n_features_in_
int
Number of features seen during fit.
n_features_in_
,)
Names of features seen during fit. Only defined if the underlying estimators expose such an attribute when fit.
Added in version 1.0.
Examples
>>> import numpy as np >>> from sklearn.linear_model import LinearRegression >>> from sklearn.ensemble import RandomForestRegressor >>> from sklearn.ensemble import VotingRegressor >>> from sklearn.neighbors import KNeighborsRegressor >>> r1 = LinearRegression() >>> r2 = RandomForestRegressor(n_estimators=10, random_state=1) >>> r3 = KNeighborsRegressor() >>> X = np.array([[1, 1], [2, 4], [3, 9], [4, 16], [5, 25], [6, 36]]) >>> y = np.array([2, 6, 12, 20, 30, 42]) >>> er = VotingRegressor([('lr', r1), ('rf', r2), ('r3', r3)]) >>> print(er.fit(X, y).predict(X)) [ 6.8 8.4 12.5 17.8 26 34]
In the following example, we drop the 'lr'
estimator with set_params
and fit the remaining two estimators:
>>> er = er.set_params(lr='drop') >>> er = er.fit(X, y) >>> len(er.estimators_) 2
Fit the estimators.
Training vectors, where n_samples
is the number of samples and n_features
is the number of features.
Target values.
Parameters to pass to the underlying estimators.
Added in version 1.5: Only available if enable_metadata_routing=True
, which can be set by using sklearn.set_config(enable_metadata_routing=True)
. See Metadata Routing User Guide for more details.
Fitted estimator.
Return class labels or probabilities for each estimator.
Return predictions for X for each estimator.
Input samples.
Target values (None for unsupervised transformations).
Additional fit parameters.
Transformed array.
Get output feature names for transformation.
Not used, present here for API consistency by convention.
Transformed feature names.
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Added in version 1.5.
A MetadataRouter
encapsulating routing information.
Get the parameters of an estimator from the ensemble.
Returns the parameters given in the constructor as well as the estimators contained within the estimators
parameter.
Setting it to True gets the various estimators and the parameters of the estimators as well.
Parameter and estimator names mapped to their values or parameter names mapped to their values.
Dictionary to access any fitted sub-estimators by name.
Bunch
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.
The input samples.
The predicted values.
Return coefficient of determination on test data.
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.
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.
True values for X
.
Sample weights.
\(R^2\) of self.predict(X)
w.r.t. y
.
Notes
The \(R^2\) score used when calling score
on a regressor uses multioutput='uniform_average'
from version 0.23 to keep consistent with default value of r2_score
. This influences the score
method of all the multioutput regressors (except for MultiOutputRegressor
).
Set output container.
See Introducing the set_output API for an example on how to use the API.
Configure output of transform
and fit_transform
.
"default"
: Default output format of a transformer
"pandas"
: DataFrame output
"polars"
: Polars output
None
: Transform configuration is unchanged
Added in version 1.4: "polars"
option was added.
Estimator instance.
Set the parameters of an estimator from the ensemble.
Valid parameter keys can be listed with get_params()
. Note that you can directly set the parameters of the estimators contained in estimators
.
Specific parameters using e.g. set_params(parameter_name=new_value)
. In addition, to setting the parameters of the estimator, the individual estimator of the estimators can also be set, or can be removed by setting them to ‘drop’.
Estimator instance.
Configure whether metadata should be requested to be passed to the score
method.
Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True
(seesklearn.set_config
). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.
False
: metadata is not requested and the meta-estimator will not pass it toscore
.
None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.
str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Metadata routing for sample_weight
parameter in score
.
The updated object.
Return predictions for X for each estimator.
The input samples.
Values predicted by each regressor.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4