Nugget: L1 vs L2 regularization
Captured ahead of reading. This is a nugget — an application sketched before reaching the chapter. It has not been checked against §8.2.3 yet, and the numbers come from
scripts/explore_nugget_regularization.py, not from the book. Treat it as a pointer, not as verified notes.
The nugget
This one closes a loop left open by 2.3 Solving Systems of Linear Equations. When a system is underdetermined it has a whole family of exact solutions, and something must break the tie. The book’s phrase for the tie-break is “find the solution with the smallest weights”.
Smallest in which sense? That is not one question but two, and the two answers have completely different characters:
- L2 / Ridge — minimise , the sum of squares.
- L1 / Lasso — minimise , the sum of absolute values.
Both say “keep the weights small”. Only one of them produces zeros.
The geometric reason for the difference: the L2 penalty’s level sets are circles, so the optimum can land anywhere on the smooth boundary. The L1 penalty’s level sets are diamonds with corners on the axes, and an optimum is drawn towards a corner — and a corner means one or more coordinates are exactly zero.
In practice
This is a genuine modelling choice, not a numerical detail, and it maps onto a question a planner already asks: which drivers actually matter?
- L2 (Ridge) — use it when you believe every feature contributes a little. Nothing is discarded; the blame is spread evenly and no single weight dominates.
- L1 (Lasso) — use it when you believe most features are useless. It performs automatic feature selection by killing coefficients outright, giving a sparse and interpretable model.
In MRP terms: a demand model might start with dozens of candidate drivers — season, promotion, price, weather, competitor action. L2 gives you a model where all of them have small non-zero effects; L1 tells you which three actually matter and sets the rest to zero. The second is usually what a human wants to read, and it is the one you can hand to a planner.
The two are often combined as elastic net (), which keeps L1’s sparsity while letting correlated features share weight — L1 alone will arbitrarily pick one of two identical features and discard the other.
Worked example
An underdetermined system — 3 equations, 6 unknowns, so and there are infinitely many exact fits. A tie-break is genuinely forced.
At :
| Solution | exact zeros | fit | ||
|---|---|---|---|---|
| minimum-norm (no penalty) | 0 of 6 | 1.2147 | 2.3844 | exact |
| Ridge / L2 | 0 of 6 | 1.1431 | 2.2573 | approx () |
| Lasso / L1 | 3 of 6 | 1.2088 | 1.9669 | approx () |
The penalised rows fit worse than the unpenalised one — that is the point: they trade a little accuracy for smaller, simpler weights. Ridge shrinks but never selects; Lasso sets half the coefficients to exactly zero.
Sweeping the penalty strength:
| ridge zeros | lasso zeros | |||
|---|---|---|---|---|
| 1.2131 | 0 | 2.1272 | 3 | |
| 1.1431 | 0 | 1.9669 | 3 | |
| 0.7662 | 0 | 0.4953 | 3 | |
| 0.6365 | 0 | 0.0000 | 6 | |
| 0.3894 | 0 | 0.0000 | 6 |
Ridge shrinks smoothly and never reaches exact zero at any strength. Lasso holds a sparse solution across a wide range and then collapses entirely to zero once exceeds the largest entry.
Because the Lasso solution is computed iteratively (ISTA), every reported solution is checked against the subgradient optimality conditions before being quoted — a half-converged iterate would otherwise look like an answer.
All numbers above are produced by scripts/explore_nugget_regularization.py.
References
- Deisenroth, Faisal & Ong, Mathematics for Machine Learning, §8.2.3 “Regularization to Reduce Overfitting” (material to read; not yet checked); see also §9.2.4 “MAP Estimation as Regularization”. See References for the full citation and link.
- Reproducibility script:
scripts/explore_nugget_regularization.py. - Related notes: 2.3 Solving Systems of Linear Equations.