HuberRegressor
- class sklearn.linear_model.HuberRegressor(*, epsilon=1.35, max_iter=100, alpha=0.0001, warm_start=False, fit_intercept=True, tol=
L2-regularized linear regression model that is robust to outliers.
The Huber Regressor optimizes the squared loss for the samples where
|(y - Xw - c) / sigma| < epsilon and the absolute loss for the samples
where |(y - Xw - c) / sigma| > epsilon, where the model coefficients
w, the intercept c and the scale sigma are parameters
to be optimized. The parameter sigma makes sure that if y is scaled up
or down by a certain factor, one does not need to rescale epsilon to
achieve the same robustness. Note that this does not take into account
the fact that the different features of X may be of different scales.
The Huber loss function has the advantage of not being heavily influenced by the outliers while not completely ignoring their effect.
Read more in the User Guide
The parameter epsilon controls the number of samples that should be
classified as outliers. The smaller the epsilon, the more robust it is
to outliers. Epsilon must be in the range [1, inf).
Maximum number of iterations that
scipy.optimize.minimize(method="L-BFGS-B") should run for.
Strength of the squared L2 regularization. Note that the penalty is
equal to alpha * ||w||^2.
Must be in the range [0, inf).
Peter J. Huber, Elvezio M. Ronchetti, Robust Statistics Concomitant scale estimates, p. 172
Art B. Owen (2006), A robust hybrid of lasso and ridge regression.
>>> import numpy as np
>>> from sklearn.linear_model import HuberRegressor, LinearRegression
>>> from sklearn.datasets import make_regression
>>> rng = np.random.RandomState(0)
>>> X,
Fit the model according to the given training data.
Training vector, where n_samples is the number of samples and
n_features is the number of features.
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
A MetadataRequest encapsulating
routing information.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Predict using the linear model.
Samples.
Predicted values.
Return coefficient of determination on test data.
The coefficient of determination, , is defined as , where is the residual sum of squares and is the total sum of squares . 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 , disregarding the input features, would get a score of 0.0.
Configure whether metadata should be requested to be passed to the method.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects
(such as Pipeline). The latter have
parameters of the form <component>__<parameter> so that it’s
possible to update each component of a nested object.
Estimator parameters.
Configure whether metadata should be requested to be passed to the method.
HuberRegressor vs Ridge on dataset with strong outliers
Ridge coefficients as a function of the L2 Regularization
This is useful if the stored attributes of a previously used model has to be reused. If set to False, then the coefficients will be rewritten for every call to fit. See the Glossary.
Whether or not to fit the intercept. This can be set to False if the data is already centered around the origin.
The iteration will stop when
max{|proj g_i | i = 1, ..., n} <= tol
where pg_i is the i-th component of the projected gradient.
Features got by optimizing the L2-regularized Huber loss.
Bias.
The value by which |y - Xw - c| is scaled down.
Number of features seen during fit.
n_features_in_,)Names of features seen during fit. Defined only when X
has feature names that are all strings.
Number of iterations that
scipy.optimize.minimize(method="L-BFGS-B") has run for.
A boolean mask which is set to True where the samples are identified as outliers.
Target vector relative to X.
Weight given to each sample.
Fitted HuberRegressor estimator.
((y_true - y_pred)** 2).sum()((y_true - y_true.mean()) ** 2).sum()yTest 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.
of self.predict(X) w.r.t. y.
The 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).
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 (see sklearn.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 to fit if provided. The request is ignored if metadata is not provided.
False: metadata is not requested and the meta-estimator will not pass it to fit.
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.
Metadata routing for sample_weight parameter in fit.
The updated object.
Estimator instance.
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 (see sklearn.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 to score if provided. The request is ignored if metadata is not provided.
False: metadata is not requested and the meta-estimator will not pass it to score.
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.
Metadata routing for sample_weight parameter in score.
The updated object.