spe.relaxed_lasso.RelaxedLasso#
- class spe.relaxed_lasso.RelaxedLasso(lambd=1.0, fit_intercept=False, precompute=False, copy_X=True, max_iter=1000, tol=0.0001, warm_start=False, positive=False, random_state=None, selection='cyclic')#
Relaxed lasso linear regression model.
Fits the usual lasso, then refits an unpenalized linear regression on features selected by the lasso. Additionally is a subclass of
AdaptiveLinearSmoother
.Documentation is heavily lifted from
Lasso
andLinearRegression
classes, both of which are utilized by this class.- Parameters:
- lambdfloat, optional
Constant that multiplies the L1 term, controlling regularization strength.
lambd
must be a non-negativefloat
i.e. in[0, inf)
.- fit_interceptbool, optional
Whether to calculate the intercept for this model. If set to
False
, no intercept will be used in calculations (i.e. data is expected to be centered). Default isTrue
.- precomputebool or array-like of shape (n_features, n_features), optional
Whether to use a precomputed Gram matrix to speed up calculations. The Gram matrix can also be passed as argument. For sparse input this option is always
False
to preserve sparsity. Default isFalse
.- copy_Xbool, optional
If True,
X
will be copied; else, it may be overwritten. Default isTrue
.- max_iterint, optional
The maximum number of iterations. Default is
1000
.- tolfloat, optional
The tolerance for the optimization: if the updates are smaller than
tol
, the optimization code checks the dual gap for optimality and continues until it is smaller thantol
. Default is1e-4
.- warm_startbool, optional
When set to
True
, reuse the solution of the previous call to fit as initialization, otherwise, just erase the previous solution. Default isFalse
.- positivebool, optional
When set to
True
, forces the coefficients to be positive. Default isFalse
.- random_stateint, optional
The seed of the pseudo random number generator that selects a random feature to update. Used when
selection
israndom
. Pass anint
for reproducible output across multiple function calls. Default isNone
.- selection{‘cyclic’, ‘random’}, optional
If set to
random
, a random coefficient is updated every iteration rather than looping over features sequentially by default. This (setting torandom
) often leads to significantly faster convergence especially when tol is higher than 1e-4. Default is ‘cyclic’.
Methods
__init__
([lambd, fit_intercept, precompute, ...])fit
(X, lasso_y[, lin_y, sample_weight, ...])fit_linear
(X, y[, sample_weight])get_linear_smoother
(X, tr_idx, ts_idx[, ...])Get fitted adaptive linear smoother matrix \(S(W)\).
Get metadata routing of this object.
get_params
([deep])Get parameters for this estimator.
predict
(X[, tr_idx, ts_idx, y_refit])Compute \(S(W)y_{refit}\) as predictions.
set_fit_request
(*[, check_input, lasso_y, ...])Request metadata passed to the
fit
method.set_params
(**params)Set the parameters of this estimator.
set_predict_request
(*[, tr_idx, ts_idx, y_refit])Request metadata passed to the
predict
method.- __init__(lambd=1.0, fit_intercept=False, precompute=False, copy_X=True, max_iter=1000, tol=0.0001, warm_start=False, positive=False, random_state=None, selection='cyclic')#
- fit(X, lasso_y, lin_y=None, sample_weight=None, check_input=True)#
- fit_linear(X, y, sample_weight=None)#
- get_linear_smoother(X, tr_idx, ts_idx, ret_full_P=False)#
Get fitted adaptive linear smoother matrix \(S(W)\).
- get_metadata_routing()#
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
- routingMetadataRequest
A
MetadataRequest
encapsulating routing information.
- get_params(deep=True)#
Get parameters for this estimator.
- Parameters:
- deepbool, default=True
If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns:
- paramsdict
Parameter names mapped to their values.
- get_selected_X(X)#
- predict(X, tr_idx=None, ts_idx=None, y_refit=None)#
Compute \(S(W)y_{refit}\) as predictions.
Computes predictions as adaptive linear smoothing where \(S(W)\) is the output of instance’s
AdaptiveLinearSmoother()
.
- set_fit_request(*, check_input: bool | None | str = '$UNCHANGED$', lasso_y: bool | None | str = '$UNCHANGED$', lin_y: bool | None | str = '$UNCHANGED$', sample_weight: bool | None | str = '$UNCHANGED$') RelaxedLasso #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
- check_inputstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
check_input
parameter infit
.- lasso_ystr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
lasso_y
parameter infit
.- lin_ystr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
lin_y
parameter infit
.- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weight
parameter infit
.
- Returns:
- selfobject
The updated object.
- set_params(**params)#
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.- Parameters:
- **paramsdict
Estimator parameters.
- Returns:
- selfestimator instance
Estimator instance.
- set_predict_request(*, tr_idx: bool | None | str = '$UNCHANGED$', ts_idx: bool | None | str = '$UNCHANGED$', y_refit: bool | None | str = '$UNCHANGED$') RelaxedLasso #
Request metadata passed to the
predict
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed topredict
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it topredict
.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.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
- tr_idxstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
tr_idx
parameter inpredict
.- ts_idxstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
ts_idx
parameter inpredict
.- y_refitstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
y_refit
parameter inpredict
.
- Returns:
- selfobject
The updated object.