sortedl1.Slope

final class sortedl1.Slope(lam: None | 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: LinearModel

Sorted 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

cv

Tune SLOPE with k-folds repeated cross-validation.

fit

Fit the model according to the given training data.

get_metadata_routing

Get metadata routing of this object.

get_params

Get parameters for this estimator.

path

Fit the SLOPE path

predict

Generate predictions for new data.

set_params

Set the parameters of this estimator.

Attributes

DType

cv(X, y, n_folds=10, n_repeats=1, predefined_folds=None, metric='mse', alphas=None, q=[0.1, 0.2], gamma=[1.0], **kwargs) CvResults[source]

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) – Number of folds for cross-validation.

  • n_repeats (int) – Number of times to repeat the cross-validation.

  • alphas – 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) – 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) – The relaxation parameter.

  • **kwargs – Additional parameters passed on to the path method.

Returns:

cv_results – A dictionary containing cross-validation results.

Return type:

dict

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 MetadataRequest encapsulating 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, **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: ArrayLike | sparse.sparray) np.ndarray[source]

Generate predictions for new data.

Parameters:

X – The feature matrix to predict from.

Returns:

Returns predicted values.

Return type:

y_pred

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