Linear, Ridge and Lasso Regression
The normal equations as orthogonal projection, the exact bias and variance of ridge, and why the unbiased estimator is rarely the best one.
Least squares
Given with and , minimise .
is minimised uniquely at
characterised by the normal equations . The fitted values are with the orthogonal projector onto , and the residual is orthogonal to every column of .
Key idea
Least squares is projection; no calculus is needed. The normal equations are the statement "the residual is orthogonal to the model space", which is the projection theorem. Everything else — the Pythagorean decomposition of the sum of squares, the statistic, the geometry of ANOVA — follows from the same picture.
Suppose with and . Then is unbiased, , and for every other estimator of the form that is unbiased for all ,
Ridge regression
and if is the SVD with singular values , then
The solution exists and is unique for every , even when .
Key idea
The shrinkage factor is near for and near for . Ridge leaves the well-determined directions alone and suppresses the poorly-determined ones — precisely the directions where, by Marchenko–Pastur, the sample covariance is least trustworthy. The effective number of parameters is , continuously interpolating between at and as .
Under the Gauss–Markov assumptions with , define . Then is differentiable at with
so for all sufficiently small .
Key idea
Read the two terms. Bias grows like — second order — while variance falls like — first order. So at there is always a free lunch, and the unbiased estimator is inadmissible in mean squared error. The effect is largest when some is small, since the derivative scales as , which is exactly the ill-conditioned case. This computation is the regression counterpart of the shrinkage result on the covariance estimation page, and both are instances of the James–Stein phenomenon.
Ridge versus lasso
Consider the orthogonal design , where both problems decouple across coordinates. With ,
Ridge multiplies; lasso subtracts and truncates. Only the second can return exactly zero.
| Ridge | Lasso | |
|---|---|---|
| Penalty | ||
| Closed form | yes | only for orthogonal design |
| Sparse | no | yes |
| Strictly convex objective | yes | no (unique solution not guaranteed) |
| Works when | yes | yes |
| Rate under sparsity | ||
| Prox operator | scaling | soft threshold |
The rate comparison is the content of the lasso theorem: when the truth is sparse, lasso's beats ridge's ; when it is dense, ridge wins.
Problems
Least squares as orthogonal projectionProof · Foundation · 15 min Prove the Gauss–Markov theoremProof · Intermediate · 30 min Ridge regression in the SVD basisProof · Intermediate · 30 min There is always a ridge parameter beating least squaresProof · Advanced · 1 hour Implement ridge and find the optimal lambdaCoding · Intermediate · 1 hourReferences
- BookTrevor Hastie, Robert Tibshirani and Jerome Friedman (2009). The Elements of Statistical Learning
- PaperArthur E. Hoerl and Robert W. Kennard (1970). Ridge Regression: Biased Estimation for Nonorthogonal Problems
- PaperRobert Tibshirani (1996). Regression Shrinkage and Selection via the Lasso
These works are cited as sources to read, not reproduced. All exposition, examples and problems on this site are written independently; where an argument is standard, the citation points to a canonical treatment.
Results stated on this page
- TheoremNormal equations and the projection interpretationproof includedThe least-squares fit is the orthogonal projection of y onto the column space of X.
- TheoremGauss–Markov theoremproof includedAmong linear unbiased estimators, least squares has the smallest variance.
- PropositionRidge regression in closed form and in the SVD basisproof includedRidge shrinks each singular direction by a factor depending on its singular value.
- TheoremThere is always a ridge parameter that beats least squaresproof includedThe derivative of the mean squared error with respect to the ridge parameter is strictly negative at zero.
- PropositionWhy lasso is sparse and ridge is notproof includedThe geometry of the l1 and l2 balls, and the closed forms of the two proximal operators.
Problems (5)
All problems- Prove the Gauss–Markov theoremProofIntermediate⏱ 30 min
- Implement ridge and find the optimal lambdaCodingIntermediate⏱ 1 hour
- Least squares as orthogonal projectionProofFoundation⏱ 15 min
- There is always a ridge parameter beating least squaresProofAdvanced⏱ 1 hour
- Ridge regression in the SVD basisProofIntermediate⏱ 30 min
Papers that use this mathematics
Deep Double Descent: Where Bigger Models and More Data Hurt
Preetum Nakkiran, Gal Kaplun, Yamini Bansal, Tristan Yang, Boaz Barak, Ilya Sutskever · 2020
Dropout: A Simple Way to Prevent Neural Networks from Overfitting
Nitish Srivastava, Geoffrey Hinton, Alex Krizhevsky, Ilya Sutskever, Ruslan Salakhutdinov · 2014