Categories &

Functions List

Function Reference: lasso

statistics: B = lasso (X, y)
statistics: [B, FitInfo] = lasso (X, y)
statistics: […] = lasso (…, Name, Value)

Lasso and elastic-net regularized least-squares regression.

B = lasso (X, y) fits a series of regularized linear models of the response y on the predictor matrix X by lasso, over a sequence of values of the regularization parameter Lambda. B is a P×L matrix whose column k holds the coefficient estimates for the k-th Lambda, in ascending order of Lambda.

[B, FitInfo] = lasso (…) additionally returns a structure FitInfo with fields Intercept, Lambda, Alpha, DF (number of non-zero coefficients), and MSE (mean squared error), one entry per value of Lambda.

The following Name-Value pairs are supported:

NameValue
'Alpha'The elastic-net mixing parameter in (0, 1]. 1 (default) is the lasso penalty; smaller values add a ridge penalty.
'Lambda'A vector of non-negative regularization parameters. By default a geometric sequence of 'NumLambda' values is used, from the smallest value that drives all coefficients to zero down to 'LambdaRatio' times that value.
'NumLambda'The number of Lambda values in the default sequence (default 100).
'LambdaRatio'The ratio of the smallest to the largest Lambda in the default sequence (default 1e-4, or 1e-2 when the number of observations is below the number of predictors).
'Standardize'Whether to standardize X to zero mean and unit variance before fitting (default true). Coefficients are always returned on the original scale.
'Weights'A vector of non-negative observation weights.
'RelTol'Convergence tolerance for the coordinate descent (default 1e-4).
'MaxIter'Maximum number of coordinate-descent iterations (default 1e5).
'DFmax'The maximum number of non-zero coefficients; the default sequence stops once this is exceeded.
'Intercept'Whether to fit a constant term (default true).
'PredictorNames'A cell array of predictor names, kept in FitInfo.
'CV'The number of folds K for K-fold cross-validation of the mean squared error, or a cvpartition object.
'MCReps'The number of Monte-Carlo repetitions of the cross-validation (default 1).

Source Code: lasso

When 'CV' is used, FitInfo.MSE is the cross-validated error, plus SE, LambdaMinMSE, IndexMinMSE, Lambda1SE, and Index1SE, which report the Lambda with the lowest error and the largest Lambda within one standard error of it. The fold assignment is random, so these selections are not reproducible without fixing the random seed.

See also: ridge, regress, lassoglm

Source Code: lasso

Lasso path drives coefficients to zero as the penalty grows

 rand ("seed", 1);
 X = rand (50, 6);
 b = [3; 0; -2; 0; 1.5; 0];
 y = X * b + 0.1 * randn (50, 1);
 [B, FitInfo] = lasso (X, y);
 plot (log (FitInfo.Lambda), B');
 xlabel ("log (Lambda)");  ylabel ("coefficient");
plotted figure