Computes the regularization path for the specified loss function and penalty function.
fit_sparse_regression(
x,
y,
penalty = "L0",
algorithm = "CD",
regulators_num = ncol(x),
cross_validation = FALSE,
n_folds = 10,
seed = 1,
loss = "SquaredError",
nLambda = 100,
nGamma = 5,
gammaMax = 10,
gammaMin = 1e-04,
partialSort = TRUE,
maxIters = 200,
rtol = 1e-06,
atol = 1e-09,
activeSet = TRUE,
activeSetNum = 3,
maxSwaps = 100,
scaleDownFactor = 0.8,
screenSize = 1000,
autoLambda = NULL,
lambdaGrid = list(),
excludeFirstK = 0,
intercept = TRUE,
lows = -Inf,
highs = Inf,
verbose = TRUE,
...
)
The matrix of regulators.
The vector of target.
The type of regularization, default is L0
.
This can take either one of the following choices: L0
, L0L1
, and L0L2
.
For high-dimensional and sparse data, L0L2
is more effective.
The type of algorithm used to minimize the objective function, default is CD
.
Currently CD
and CDPSI
are supported.
The CDPSI
algorithm may yield better results, but it also increases running time.
The number of non-zore coefficients, this value will affect the final performance. The maximum support size at which to terminate the regularization path.
Logical value, default is FALSE
, whether to use cross-validation.
The number of folds for cross-validation, default is 10
.
The random seed for cross-validation, default is 1
.
The loss function.
The number of Lambda values to select.
The number of Gamma values to select.
The maximum value of Gamma when using the L0L2
penalty.
For the L0L1
penalty this is automatically selected.
The minimum value of Gamma when using the L0L2
penalty.
For the L0L1
penalty, the minimum value of gamma in the grid is set to gammaMin * gammaMax.
Note that this should be a strictly positive quantity.
If TRUE
, partial sorting will be used for sorting the coordinates to do greedy cycling.
Otherwise, full sorting is used.
The maximum number of iterations (full cycles) for CD
per grid point.
The relative tolerance which decides when to terminate optimization, based on the relative change in the objective between iterations.
The absolute tolerance which decides when to terminate optimization, based on the absolute L2 norm of the residuals.
If TRUE
, performs active set updates.
The number of consecutive times a support should appear before declaring support stabilization.
The maximum number of swaps used by CDPSI
for each grid point.
This parameter decides how close the selected Lambda values are.
The number of coordinates to cycle over when performing initial correlation screening.
Ignored parameter. Kept for backwards compatibility.
A grid of Lambda values to use in computing the regularization path.
This parameter takes non-negative integers.
If FALSE
, no intercept term is included in the model.
Lower bounds for coefficients.
Upper bounds for coefficients.
Logical value, default is TRUE
, whether to print progress messages.
Parameters for other methods.
An S3 object describing the regularization path
Hazimeh, Hussein et al. “L0Learn: A Scalable Package for Sparse Learning using L0 Regularization.” J. Mach. Learn. Res. 24 (2022): 205:1-205:8.
Hazimeh, Hussein and Rahul Mazumder. “Fast Best Subset Selection: Coordinate Descent and Local Combinatorial Optimization Algorithms.” Oper. Res. 68 (2018): 1517-1537.
https://github.com/hazimehh/L0Learn/blob/master/R/fit.R
data("example_matrix")
fit <- fit_sparse_regression(
example_matrix[, -1],
example_matrix[, 1]
)
head(coef(fit))
#> 6 x 9 sparse Matrix of class "dgCMatrix"
#>
#> intercepts 1.985357 2.123864 1.668191 1.664802 1.66545500 1.66245399
#> . . . . . .
#> . . . . . .
#> . . . . 0.01047924 0.01345722
#> . . . . . .
#> . . . . . .
#>
#> intercepts 1.66218384 1.662335607 1.662162452
#> 0.01029233 0.007523953 0.006073601
#> . 0.005339557 0.006290166
#> 0.01271126 0.012662684 0.010752371
#> . -0.002983770 -0.001518502
#> -0.01337606 -0.013514219 -0.013052947