TL;DR
Lasso regression fits a linear model by minimising squared error plus a penalty equal to the sum of the absolute values of the weights. The penalty shrinks every weight towards zero, and because its corners sit on the axes, it often drives some weights exactly to zero. The result is a model that uses only a few of the available features, which makes it easier to read and less prone to overfitting when many features are noise.
Where you'll see it: in genomics, where thousands of gene measurements are used to predict a trait from a few dozen samples; in economics and marketing models with many candidate variables; and as a feature-selection step before a more complicated model.
Intuition
Suppose you have two hundred candidate features and only a few truly matter. Ordinary linear regression uses all two hundred, and each one picks up a little of the noise in the training data. The fitted model looks perfect on the data it was trained on and does poorly on new data. This is overfitting, and the usual cure is to penalise large weights.
Ridge regression, which uses an L2 penalty, shrinks all the weights smoothly. It makes them smaller but almost never zero. A lasso penalty works differently. It charges a fixed price for each unit of weight, whether the weight is large or small. Near zero, that price is relatively expensive compared with the gain in fit from keeping a tiny weight. So many weights are pushed all the way to zero.
The picture is geometric. Imagine the error as a bowl centred on the least-squares solution, and the penalty as a region around the origin. For L2 the region is a disc, with no corners. For L1 it is a diamond, with corners on the axes. The first point where the expanding bowl touches the region is usually a corner of the diamond, and a corner means some weights are zero.
The plot below shows the one-dimensional version, which captures the whole mechanism. The soft-threshold map takes an unpenalised weight and returns . Small weights are set to zero, and large ones are shrunk by .
- lasso, lambda = 1
- ridge-style shrink, factor 1/2
- no penalty
The math
Definition
Given examples with feature matrix , targets , and a penalty strength , the lasso chooses weights to minimise
The first term is the average squared error of the linear regression model. The second term is the L1 norm of the weights, scaled by . Setting recovers ordinary least squares. As grows, the penalty dominates and more weights are driven to zero.
The factor is a convention. Some texts omit it or use a sum rather than an average, which changes the meaning of by a constant. Always check which scaling a source uses before comparing values of .
Why the L1 penalty is convex
The squared-error term is convex in , and the absolute value is convex. Their sum is convex, so the lasso has no bad local minima. This matters for the algorithms, which can rely on the optimality conditions of subgradients. The objective is not differentiable where any , so gradient descent alone is not enough, and the usual solvers use coordinate descent.
Optimality condition
For each coordinate , the subgradient condition at the minimiser says that zero lies in the subdifferential of the objective. Write for the average product of feature (column of ) and the residual that remains when all other features are used. Under the standard normalisation, with each column of having average squared value 1, the condition gives
If , the weight is exactly zero. Otherwise it is shrunk by from the value that ordinary regression would give. This is the same soft-threshold rule that solves the one-dimensional problem in L1 Minimization.
Coordinate descent
Coordinate descent solves the lasso by cycling through the weights. For each , hold the other weights fixed, compute from the current residual, and apply the soft-threshold rule to update . Repeat until nothing changes much. Each update is exact and cheap, and the method converges for the lasso because the objective is convex and the penalty is separable across coordinates. See Coordinate Descent for the general idea.
Choosing lambda
The penalty is a hyperparameter, so it is chosen by validation, not by fitting to the training data. A common approach fits the lasso over a grid of values from large to small, which starts with an all-zero model and adds features one at a time, then picks the value with the best error on held-out data. Cross-validation over the same grid is the standard tool, as described in Train, Validation and Test Sets.
Worked examples
Minimise with and . This is the one-dimensional lasso with an unpenalised weight of .
- Optimality: , where if .
- Since , the solution is nonzero. Use : .
- Check the condition: . The subgradient is , which is a valid value, so is the minimiser.
- Compare with the unpenalised answer . The penalty shrank the weight by exactly .
Interpretation: the penalty did not remove this feature, but it made the weight smaller. If had been instead, the same calculation would give , and the feature would be dropped.
Suppose the features are orthonormal, so the least-squares weights are and . Use the penalty strength , with each penalty applied in the same units as the squared error.
- Lasso: apply the soft threshold to each weight. . .
- Ridge with the penalty : the minimiser for each weight is . So and .
- Compare. Ridge keeps both features, shrunk by the same factor. Lasso keeps the strong feature, shrunk by a fixed amount, and drops the weak one entirely.
- Count the nonzero weights as rises. Feature survives exactly when . With , the count is 3 at , 2 at , and 1 at .
Interpretation: under orthonormal features the lasso's selection rule is transparent. Only features whose unpenalised weight beats in size survive. Real features are correlated, and then the pattern is less clean, as the next section explains.
Two features are nearly copies of each other, so their correlation is close to 1. Both would carry the same signal, and the least-squares weights are unstable: small changes in the data can move weight between them.
- Two exact copies of one signal give the same fit for any pair of weights with the same sum . The L1 penalty is at least and equals for every split where both weights share a sign. So the penalty alone does not choose a split, and the lasso solution is not unique.
- Small differences between the copies, or noise in the data, break the tie. The lasso may then put nearly all the weight on one copy, and which copy it picks can change when the data are resampled.
- Ridge's penalty is smallest for a fixed sum when the two weights are equal, so ridge splits the weight roughly evenly and is stable here.
Interpretation: lasso selection is stable across many distinct features but can be unstable among near-duplicates. This is why elastic net, which mixes L1 and L2 penalties, is often preferred when features come in correlated groups.
Tradeoffs and failure modes
| Situation | What goes wrong | Better choice |
|---|---|---|
| Many noisy features and few samples | Ordinary regression overfits badly | Lasso, with chosen by cross-validation |
| Features are correlated in groups | Lasso picks one member and drops the others, and the choice can be unstable | Elastic net, which adds an L2 term |
| Signal is spread over many small effects | Lasso zeros out real but weak effects and loses predictive power | Ridge, which keeps all features with shrinkage |
| Features on different scales | The penalty charges large-scale features less, so results depend on units | Standardise the features before fitting |
| Reading the selected features as causes | Selection reflects prediction, and correlated variables can be swapped | Treat the selection as a prediction tool, and test causal claims separately |
| Choosing lambda on the training data | The smallest penalty always fits best, so the model is never sparse | Choose on validation data or by cross-validation |
The main tradeoff is between sparsity and stability. The lasso gives a short, interpretable model, but the set of selected features can change when the data changes. Ridge is more stable and keeps everything, which can be better when no feature is truly irrelevant. The right choice depends on whether the goal is a compact model or the best prediction.
History
Least squares was developed by Legendre and Gauss around 1800, and ridge-style shrinkage was introduced by Hoerl and Kennard in 1970. Those methods shrink coefficients but keep all of them. The idea of an L1 penalty for selection appeared earlier in signal processing and geophysics, where people wanted sparse solutions.
Robert Tibshirani's 1996 paper gave the lasso its name and its statistical framing. It showed that an L1 penalty on the coefficients both shrinks and selects, and it gave a practical algorithm. The name is an acronym for "least absolute shrinkage and selection operator".
In the early 2000s, Donoho and collaborators connected L1 minimisation to compressed sensing, where a signal can be recovered from far fewer measurements than usual if it is sparse. That work gave the lasso a theoretical foundation and made sparse modelling standard in signal processing and machine learning. Efficient coordinate-descent solvers, popularised around 2010, made it practical for very large problems.
Check yourself
QuestionWhat does the lasso penalty add to the squared-error objective, and what does setting lambda to zero give?Show answer
It adds times the sum of the absolute values of the weights. With the penalty vanishes and the objective is ordinary least squares, so the lasso reduces to linear regression.
QuestionWith an unpenalised weight of y = 2 and lambda = 0.5 in the one-dimensional lasso, what is the fitted weight? What about y = 0.3?Show answer
For , the solution is . For , , so and the fitted weight is . The feature is dropped.
QuestionUnder orthonormal features with unpenalised weights 4, 1.5 and 0.2, how many weights remain nonzero at lambda = 1?Show answer
A weight survives when its absolute value exceeds lambda. Here and survive, while does not. Two weights remain nonzero. The surviving weights are shrunk to and .
QuestionTwo nearly identical features carry the same signal. Why is the lasso's choice between them unstable, while ridge's is stable?Show answer
For a fixed total weight, the L1 penalty is the same for many splits between the copies, so the penalty cannot decide and small differences in the data do. The choice can then shift when the data are resampled. Ridge's squared penalty is smallest when the weight is shared evenly, so it gives a unique, stable split.
QuestionIn a practical study with many candidate features, why must lambda be chosen on data not used to fit the weights?Show answer
The training error always decreases as lambda decreases, so the training data alone would choose no penalty and keep every feature. Validation or cross-validation measures how well the model predicts new data, which is the quantity that the penalty is meant to improve.