Lasso Regression (L1)
Lasso Regression (L1) — Drive some coefficients exactly to zero for feature selection.
Lasso uses a different penalty than ridge — one that pushes weak coefficients all the way to exactly zero. That means it doesn’t just shrink features, it deletes them, doing automatic feature selection.
Coefficients at λ = 0.00100 (click one to trace it)
- x1
- x2
- x3
- x4
- x5
- x6
Lasso controls
The idea in plain words
Lasso penalizes the absolute value of the weights instead of their squares. That one change lets it drive weak coefficients all the way to exactly zero — so it doesn’t just shrink features like ridge, it deletes them, performing automatic feature selection.
The reason is geometric: the L1 constraint region is a diamond with sharp corners on the axes. The elliptical loss contours almost always first touch that region at a corner, where one coordinate is zero. Toggle between ridge and lasso to see the circle-vs-diamond difference directly.
Now, the math
Lasso swaps the squared penalty for an absolute-value (L1) penalty:
There’s no closed form; coordinate descent applies a soft-threshold to each weight:
- the L1 penalty — the diamond-shaped constraint that yields sparsity.
- the least-squares update for weight j before penalizing.
- the threshold — any weight with |z| below it is set to exactly zero.
▸ Show the derivation
Soft-thresholding is the exact solution of the one-coordinate lasso problem: whenever a weight’s correlation with the residual falls below λ, the subgradient of |w| pins it to zero. Cycling this over all coordinates converges to the global optimum. With correlated features, though, lasso keeps one and zeroes the others somewhat arbitrarily — which motivates elastic net.
Trace it by hand
The exact same tiny problem as the ridge walk-through: columns x1 equal to (-1, -1, 1, 1) and x2 equal to (-1, 1, -1, 1), targets y equal to 2 x1 plus 0.5 x2, so the per-weight least-squares values are z equal to (2, 0.5). Now the penalty is L1 and the solver is the repo's coordinate descent with soft-thresholding.
Step 1 — start from the unpenalized weights
With orthonormal columns, each coordinate update sees exactly zj — the least-squares value for that weight from the page equation.
Step 2 — soft-threshold with a small lambda
Lasso subtracts lambda from every weight's magnitude — a flat tax, unlike ridge's percentage cut.
Step 3 — raise lambda past the small weight
0.5 minus 1 is negative, so the max clamps w two to exactly 0 — not merely small. Feature x2 has been deleted from the model.
Step 4 — ridge on the same problem, same lambda
Identical data, identical lambda: ridge divides 0.5 down to 0.25, lasso subtracts past zero and clamps. That is the circle-versus-diamond corner, in numbers.
What just happened: Soft-thresholding turned (2, 0.5) into (1, 0): any weight whose least-squares value is smaller in magnitude than lambda gets set to exactly zero. Lasso performed feature selection with nothing but subtract-and-clamp arithmetic.
Now Break It
Try this: With correlated features, lasso arbitrarily picks one and zeroes the rest, which can be unstable.
Control: Lambda slider with correlated features enabled
What happens: Instability! With correlated features, lasso arbitrarily keeps one and drops the others.
Where lasso regression (l1) is used
Lasso regression is prized when you want a model that is not just accurate but also sparse and interpretable, because its L1 penalty drives many coefficients exactly to zero and effectively selects features. In genomics and biomarker discovery, researchers use it to pick a handful of relevant genes from thousands of candidates. Text classification and sentiment analysis rely on it to keep only the most predictive words out of huge vocabularies. Signal processing uses the same sparsity idea in compressed sensing to reconstruct signals from few measurements. Economists and social scientists use lasso to prune large sets of candidate variables down to a defensible short list. Whenever storage, cost, or explanation matters and you suspect only a few inputs truly drive the outcome, lasso regression delivers a compact model.
A key misconception is that the features lasso keeps are the definitively correct ones. When predictors are correlated, lasso tends to arbitrarily pick one and zero out the others, so the selected set can change with small perturbations in the data and should not be read as a stable causal story. Another pitfall is that lasso can be unstable or underperform ridge when features are highly collinear, which is precisely why elastic net was invented. People also forget that lasso, like ridge, requires standardized features so the L1 penalty treats them fairly, and that the penalty strength must be cross-validated. Finally, a zeroed coefficient means unselected under this penalty, not proven irrelevant.
Frequently asked questions
What is lasso regression?
Why does lasso set some coefficients exactly to zero?
When should I use lasso instead of ridge?
What are the limitations of lasso with correlated features?
Does lasso require feature scaling?
Written & reviewed by the ML Visualization team · Last updated .