API Reference
SLOPE.SLOPE
— Modulemodule SLOPE
Sorted L-One Penalized Estimation
SLOPE.slope
— Functionslope(x, y; kwargs...) -> NamedTuple
Fit a SLOPE (Sorted L1 Penalized Estimation) model to the provided data.
SLOPE is a regularization method that combines the L1 norm with a sorted penalty, encouraging both sparsity and grouping of features.
Arguments
x
: Matrix of predictors (dense or sparse)y
: Response variable (vector)
Keyword Arguments
α::Union{AbstractVector,Real,Nothing}=nothing
: Alpha sequence for regularization pathλ::Union{AbstractVector,Nothing}=nothing
: Lambda sequence for regularization pathfit_intercept::Bool=true
: Whether to fit an intercept termloss::Symbol=:quadratic
: Type of loss functioncentering::Symbol=:mean
: Method for centering predictorsscaling::Symbol=:sd
: Method for scaling predictorspath_length::Int=100
: Number of regularization path pointstol::Float64=1e-5
: Convergence tolerance for optimizationmax_it::Int=10000
: Maximum number of iterationsq::Float64=0.1
: Parameter controlling the shape of the penalty weights sequence. Should be in the range (0, 1).max_clusters::Union{Int,Nothing}=nothing
: Early path stopping criteria for maximum number of clusters (defaults to n+1)dev_change_tol::Float64=1e-5
: Early path stopping criteria for tolerance for change in deviancedev_ratio_tol::Float64=0.999
: Early path stopping criteria for tolerance for ratio of devianceα_min_ratio::Union{Float64,Nothing}=nothing
: Fraction of maximumα
to use as minimum value in the regularization path. Defaults to1e-2
ifn > p * m
, otherwise1e-4
.
Returns
A SlopeFit
object.
SLOPE.SlopeFit
— TypeSlopeFit
A structure containing the results of fitting a SLOPE model.
Fields
intercepts::Vector{Vector{Float64}}
: A vector of intercept vectors along the regularization path. For each point in the path, contains a vector of lengthm
with class-specific intercepts.coefficients::Vector{SparseMatrixCSC{Float64,Int}}
: A vector of sparse coefficient matrices along the regularization path. Each matrix is of sizep×m
wherep
is the number of predictors andm
is the number of response classes (1 for regression).α::Vector{Float64}
: The alpha values used at each point of the regularization path.λ::Vector{Float64}
: The lambda values used at each point of the regularization path.m::Int
: The number of response classes (1 for regression, >1 for multinomial).loss::Symbol
: The loss function used in the model fitting process.classes::Union{Vector,Nothing}
: A vector of unique class labels for the response variable. This isnothing
for regression models (continuous responses).
SLOPE.slopecv
— Functionslopecv(
x,
y;
α=nothing,
λ=nothing,
γ=[0.0],
q=[0.1],
n_folds=10,
n_repeats=1,
metric=:mse,
kwargs...
)
Perform cross-validation for SLOPE to find optimal hyperparameters.
Arguments
x::Union{AbstractMatrix,SparseMatrixCSC}
: Input feature matrix, can be dense or sparse.y::AbstractVector
: Response vector.
Keyword Arguments
α::Union{AbstractVector,Real,Nothing}=nothing
: SLOPE regularization path. Ifnothing
, it's automatically generated.λ::Union{AbstractVector,Nothing}=nothing
: Sequence of regularization parameters. Ifnothing
, it's automatically generated.γ::Union{AbstractVector,Real}=[0.0]
: Parameter controlling the regularization sequence. Multiple values create a grid search.q::Union{AbstractVector}=[0.1]
: FDR parameter for BH sequence. Multiple values create a grid search.n_folds::Int=10
: Number of cross-validation folds.n_repeats::Int=1
: Number of times to repeat the CV process with different fold assignments.metric::Symbol=:mse
: Evaluation metric for cross-validation. Options include:mse
,:mae
,:accuracy
, etc.kwargs...
: Additional parameters passed to the SLOPE solver.
Returns
A SlopeCvResult
object.
Examples
# Basic usage with default parameters
result = slopecv(X, y)
# Cross-validation with custom parameters
result = slopecv(X, y, γ=[0.0, 0.1, 0.5], q=[0.1, 0.05], n_folds=5, metric=:accuracy)
# Access best parameters and score
best_q = result.best_params["q"]
best_γ = result.best_params["γ"]
best_score = result.best_score
See Also
slope
: For fitting a SLOPE model with fixed parameters.
SLOPE.SlopeGridResult
— TypeSlopeGridResult
Results for a specific hyperparameter combination in the SLOPE cross-validation grid search.
Fields
params::Dict{String,Any}
: Dictionary of hyperparameter values (e.g., "q", "γ")scores::Matrix{Real}
: Cross-validation scores for each fold and alpha valuealphas::Vector{Real}
: Sequence of alpha values for the regularization pathscores_means::Vector{Real}
: Mean score across folds for each alphascores_errors::Vector{Real}
: Standard errors of scores across folds
SLOPE.SlopeCvResult
— TypeSlopeCvResult
Result structure from SLOPE cross-validation.
Fields
metric::Symbol
: The evaluation metric used (e.g.,:mse
,:accuracy
)best_score::Real
: The best score achieved during cross-validationbest_ind::Int
: Index of the best parameter combinationbest_α_ind::Int
: Index of the best alpha value in the regularization pathbest_params::Dict{String,Any}
: Dictionary with the best parameter valuesresults::Vector{SlopeGridResult}
: Grid search results, of typeSlopeGridResult
for each parameter combination
Plotting
RecipesBase.apply_recipe
— Methodplot(cvresult::SlopeCvResult; xvar=:α, index=1; kwargs...)
Plots the cross-validation results from a cross-validated SLOPE model.
Arguments
cvresult::SLOPE.SlopeCvResult
: The result of a cross-validated SLOPE model, containing multiple cross-validation results for different parameters.xvar::Symbol=:α
: Variable for the x-axis, options::α
: Plot against the regularization parameter alpha (default):step
: Plot against the step number in the regularization path
index::Int=1
: Index of the cross-validation result to plot. If there are multiple values ofγ
orq
, this specifies which set of these to visualize.
Keyword Arguments
kwargs...
: Additional arguments passed to the plot, such as:title
: Title for the plotlegend
: Legend position (default::none
)lw
: Line widthcolor
: Color scheme
Returns
A plot object showing the cross-validation error, with ribbons for standard error.
RecipesBase.apply_recipe
— Methodplot(fit::SLOPE.SlopeFit; xvar=:α, response=1, kwargs...)
Plot the coefficient paths from a SLOPE model regularization path.
This function visualizes how the coefficients change along the regularization path, allowing you to see which variables enter the model and how their effects change as the regularization strength varies.
Arguments
fit::SLOPE.SlopeFit
: A fitted SLOPE model object containing the regularization pathxvar::Symbol=:α
: Variable for the x-axis, options::α
: Plot against the regularization parameter alpha (default):step
: Plot against the step number in the regularization path
response::Int=1
: For multi-response models, specifies which response's coefficients to plotlayout
: (DEPRECATED) Layout for multi-class plots, e.g., (rows, cols). Default is (m, 1) for m classes.
Keyword Arguments
kwargs...
: Additional arguments passed to the plot, such as:title
: Title for the plotlegend
: Legend position (default::none
)lw
: Line widthcolor
: Color scheme
Returns
A plot object showing the coefficient paths