The Geometry of L1 vs L2 Penalties
L1 and L2 regularization both shrink model weights, but only L1 pushes weights all the way to exactly zero — and the reason is entirely geometric: one penalty has sharp corners on the coordinate axes, the other is a smooth circle.
Prerequisites: Regularization as a Prior
Both L1 (lasso) and L2 (ridge) regularization add a penalty term to a regression's loss to discourage large weights, and both are often taught as "roughly the same idea, different exponent." They are not the same in the one way that matters most in practice: L2 shrinks every weight a little, while L1 shrinks some weights to exactly zero, deleting features from the model entirely. Two formulas that look one exponent apart produce completely different kinds of models, and the reason is not algebra — it's geometry.
The analogy: a rubber band pulling toward a diamond vs. a circle
Picture the loss function's best-fit point sitting somewhere in weight-space, and a "budget region" around the origin the regularized solution must stay inside — a shrinking balloon squeezed onto the loss surface's contours. If that region is a smooth circle (L2), the point where the loss contours first touch it can land anywhere on the edge, including points with every coordinate nonzero. If it's a diamond with sharp corners on the coordinate axes (L1), the loss contours are disproportionately likely to first touch at a corner — and a corner on an axis means one coordinate is exactly zero. The corners are where sparsity comes from; a circle has no corners.
The formal setup
Both add a penalty to the ordinary least-squares loss, controlled by strength :
In words: both penalize how large the weights are, but L2 penalizes the square of each weight (a smooth, ever-steepening cost as a weight grows) while L1 penalizes the absolute value (a cost that grows at a constant rate, with a sharp kink exactly at zero). That kink is the algebraic fingerprint of the diamond's corner: the L1 penalty's derivative does not vanish smoothly as a weight approaches zero — it stays at a constant right up to the corner, which is enough to shove a small weight the rest of the way to exactly , something the ever-softening L2 penalty near zero never has the force to do.
Worked example 1: single-weight shrinkage by hand
Take a small weight with penalty strength and step size . Ridge's gradient contribution is , so the update is — a small pull, and as keeps shrinking the pull shrinks proportionally with it, so it takes infinitely many tiny steps to actually reach zero. Lasso's gradient contribution is a constant regardless of 's size: , which a real implementation clips to exactly rather than overshooting past it. The constant-force penalty reaches zero in one step from small ; the proportional-force one never quite does.
Worked example 2: which features survive
A model with 5 correlated momentum features is fit with lasso at a moderate . Because the diamond's corners sit on individual axes, lasso tends to pick one representative per correlated cluster and zero out the rest — fitted weights might come out , an automatic feature selector. Ridge on the same data instead spreads the credit: roughly , keeping all five active but shrunk. Neither is "wrong" — lasso gives an interpretable, sparse model; ridge gives a stable, evenly-shared one — but they are structurally different outputs from a nearly identical formula.
Drag the exponent above between 1 (a cone, like L1's absolute-value shape) and 2 (a smooth bowl, like L2's square) and watch the corner at the origin appear and disappear — that corner is the entire mechanism behind sparsity.
L1 and L2 differ by exponent in the formula but by shape in weight-space: L2's circular constraint region has no corners, so it shrinks weights smoothly toward zero without reaching it; L1's diamond has corners on the axes, and the loss surface disproportionately settles there, forcing some weights to exactly zero and performing automatic feature selection.
What this means in practice
Use L1 when you suspect only a handful of your features actually matter and want the model to tell you which — a sparse factor model with 3 nonzero loadings out of 50 candidates is far easier to reason about and monitor than one with 50 small nonzero weights. Use L2 when features are genuinely all somewhat informative and correlated, since it avoids the somewhat arbitrary "pick one, zero the rest" behavior lasso exhibits among near-duplicate features. Elastic net, a weighted combination of both penalties, is the common practical compromise.
The common confusion is assuming L1's zeros mean "these features are unimportant." Among a cluster of highly correlated features, lasso's choice of which one survives is close to arbitrary and can flip with a small data perturbation or a different random seed — a zeroed-out feature may be just as predictive as the one that got the nonzero weight, it simply lost a near-coin-flip. Don't read L1 sparsity as a definitive ranking of feature importance without checking stability across resamples.
Related concepts
Practice in interviews
Further reading
- Hastie, Tibshirani & Friedman, The Elements of Statistical Learning, ch. 3