sortedl1.Slope¶
- final class sortedl1.Slope(lam: None | TypeAliasForwardRef('ArrayLike') = None, alpha: float = 1.0, fit_intercept: bool = True, loss: str = 'quadratic', lambda_type: str = 'bh', q: float = 0.1, theta1: float = 1.0, theta2: float = 0.5, centering: str = 'none', scaling: str = 'none', max_iter: int = 100000, tol: float = 0.0001, solver: str = 'hybrid', update_clusters: bool = True, hybrid_cd_type: str = 'cyclical', screening: str = 'strong')[source]¶
Bases:
LinearModelSorted L-One Penalized Estimation.
- Parameters:
lam – The lambda parameter vector for the Sorted L1 Penalty.
alpha – A multiplier for the Sorted L1 Penalty.
fit_intercept – Whether to fit an intercept term.
loss – Loss (data-fitting) function to be used. One of “quadratic”, “logistic”, “multinomial”, and “poisson”.
lambda_type – Type of lambda sequence. One of “bh”, “gaussian”, “oscar”, and “lasso”.
q – FDR control parameter for the Sorted L1 Penalty. Must be between 0 and 1. Only has effect if lambda_type is “bh” or “gaussian”.
theta1 – Slope of the penalty sequence for OSCAR type sequences. Only has effect when lambda_type is “oscar”.
theta2 – Slope of the penalty sequence for OSCAR type sequences. Only has effect when lambda_type is “oscar”.
centering – Type of centering, one of “mean”, “min”, and “none”.
scaling – Type of scaling, one of “sd”, “l1”, “l2”, “max_abs”, and “none”.
max_iter – Maximum number of iterations.
tol – Tolerance for the stopping criterion.
solver – Solver to be used. One of “hybrid”, “pgd”, and “fista”
update_clusters – Wheter to update the clusters between hybrid coordinate descent steps.
hybrid_cd_type – Type of hybrid coordinate descent to be used. One of “cyclical” and “permuted” (random permutations). Only has effect when solver is “hybrid” or possibly “auto”.
screening – Type of feature screening to be used. One of “none” and “strong”.
- Variables:
intercept (float) – The estimated intercept.
coef (ndarray) – The estimated regression coefficients in a sparse format.
sparse_coef (scipy.sparse.csc_matrix) – The estimated regression coefficients in a dense format.
lambda (ndarray) – The lambda parameter vector for the Sorted L1 Penalty.
n_iter (int) – The total number of iterations from the inner loop.
n_features_in (int) – The number of features seen by the estimator.
Methods
Tune SLOPE with k-folds repeated cross-validation.
Fit the model according to the given training data.
Get metadata routing of this object.
Get parameters for this estimator.
Fit the SLOPE path
Generate predictions for new data.
Return R^2 for regression losses or accuracy for classification losses.
Set the parameters of this estimator.
Configure whether metadata should be requested to be passed to the
scoremethod.Attributes
DType- cv(X, y, n_folds=10, n_repeats=1, predefined_folds=None, metric='mse', alphas=None, q=None, gamma=None, refit: Literal[False] = False, **kwargs) CvResults[source]¶
- cv(X, y, n_folds=10, n_repeats=1, predefined_folds=None, metric='mse', alphas=None, q=None, gamma=None, refit: Literal[True] = True, **kwargs) tuple[CvResults, Slope]
Tune SLOPE with k-folds repeated cross-validation.
- Parameters:
X – Feature matrix, where n_samples is the number of samples and n_features is the number of features.
y – Response vector.
n_folds (int, default=10) – Number of folds for cross-validation.
n_repeats (int, default=1) – Number of times to repeat the cross-validation.
predefined_folds (array-like, optional) – Predefined fold indices for cross-validation.
metric (str, default="mse") – Metric to use for cross-validation.
alphas (array-like, optional) – An array of lambda values to use for cross-validation. If None, the lambda values are computed automatically from a run on the full data set.
q (array-like, default=[0.1, 0.2]) – FDR control parameter for the Sorted L1 Penalty. Must be between 0 and 1. Only has effect if lambda_type is “bh” or “gaussian”.
gamma (array-like, default=[1.0]) – The relaxation parameter.
refit (bool, default=False) – If True, also fit and return the best model on the full data using the best cross-validated hyperparameters.
**kwargs – Additional parameters passed on to the path method.
- Returns:
cv_results (CvResults) – Cross-validation results.
best_model (Slope) – Returned only when refit=True. A fitted estimator using the best cross-validated hyperparameters.
- fit(X: ndarray[tuple[Any, ...], dtype[number]] | csc_array, y: ndarray[tuple[Any, ...], dtype[number]] | list[float] | tuple[float, ...])[source]¶
Fit the model according to the given training data.
- Parameters:
X – Training vector, where n_samples is the number of samples and n_features is the number of features.
y – Target vector relative to X.
- Returns:
Fitted estimator.
- Return type:
self
- get_metadata_routing()[source]¶
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing – A
MetadataRequestencapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)[source]¶
Get parameters for this estimator.
- Parameters:
deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns:
params – Parameter names mapped to their values.
- Return type:
dict
- path(X: ndarray[tuple[Any, ...], dtype[number]] | csc_array, y: ndarray[tuple[Any, ...], dtype[number]] | list[float] | tuple[float, ...], alphas: None | ndarray[tuple[Any, ...], dtype[number]] = None, path_length: int = 100, alpha_min_ratio: None | number = None, tol_dev_change: float = 1e-05, tol_dev_ratio: float = 0.999, max_clusters: int | None = None, **kwargs) PathResults[source]¶
Fit the SLOPE path
- Parameters:
X – Feature matrix, where n_samples is the number of samples and n_features is the number of features.
y – Response vector.
alphas – An array of lambda values to use for the path. If None, the lambda values are computed automatically based on path_length and alpha_min_ratio.
path_length – The number of alpha values to compute for the path. This parameter is ignored if alphas is provided.
alpha_min_ratio – The minimum value of alpha to use for the path as a fraction of alpha_max (the value at which all coefficients are zero). If None, then the value is computed based on the dimension of the data: 1e-2 if there are more features than observations and 1e-4 otherwise. This parameter is ignored if alphas is provided.
tol_dev_change – Early path stopping criterion based on the change in deviance. If the fractional change in deviance is less than this value, the path is stopped early.
tol_dev_ratio – Early path stopping criterion based on the ratio of deviance. If the deviance ratio exceeds this value, the path is stopped early.
max_clusters – Early path stopping criterion based on the number of clusters (unique nonzero magnitudes among the coefficients). The default, None, sets this value to the number of observations plus one.
- Returns:
coefs (array, shape (n_features, n_alphas)) – The estimated coefficients for each alpha.
intercepts (array, shape (n_alphas,)) – The estimated intercepts for each alpha.
alphas (array, shape (n_alphas,)) – The lambda values for the path.
lambdas (array, shape (n_alphas,)) – The lambda values for the path.
- predict(X: TypeAliasForwardRef('ArrayLike') | sparray) ndarray[source]¶
Generate predictions for new data.
- Parameters:
X – The feature matrix to predict from.
- Returns:
Returns predicted values.
- Return type:
y_pred
- score(X: TypeAliasForwardRef('ArrayLike') | sparray, y: ArrayLike, sample_weight: TypeAliasForwardRef('ArrayLike') | None = None) float[source]¶
Return R^2 for regression losses or accuracy for classification losses.
- set_params(**params)[source]¶
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:
**params (dict) – Estimator parameters.
- Returns:
self – Estimator instance.
- Return type:
estimator instance
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') Slope[source]¶
Configure whether metadata should be requested to be passed to the
scoremethod.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 toscoreif 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.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter inscore.- Returns:
self – The updated object.
- Return type:
object