Ridge Regression in Depth
SVD shrinkage, effective degrees of freedom and the Bayesian view.
Ridge regression is short enough to memorize and simple enough to analyze completely. Through the singular value decomposition it is a filter that damps each direction of the data by . Its error has an exact formula and a theorem attached, it is a Bayesian posterior mean, its leave-one-out error costs a single fit, and when features vastly outnumber examples its best penalty can be zero or even negative.
What you’ll learn
- Write ridge as a spectral filter through the SVD, compare it with principal components regression, and compute its effective degrees of freedom .
- Derive the bias, covariance and mean-squared-error matrix of ridge, and prove that it beats least squares in every direction when .
- Identify ridge as a Gaussian posterior mean, and derive its dual form , the doorway to kernel methods.
- Prove the one-fit leave-one-out formula, derive generalized cross-validation, and describe ridge when stays fixed: Bayes-optimal tuning, the ridgeless peak and implicit regularization.
Ridge as a spectral filter
Write the thin singular value decomposition : and have orthonormal columns and , and with , where . For centered features the are the principal directions of the data and is the variance along (PCA in Depth). Ridge regression minimizes : is on the sum-of-squares scale of Regularization: Ridge & Lasso, and the regpath widget's , which charges the penalty against the error per example, is this one divided by .
Since , the inverse multiplies each by (and the directions orthogonal to all by , but never reaches them):
Multiply by . The fitted values keep each orthonormal direction of the data with a factor between 0 and 1:
Least squares is the limit : every factor becomes 1, the fit is the projection onto the column space of , and the weights become the minimum-norm solution . Principal components regression with components uses factors for and beyond: a hard cutoff where ridge has a smooth one.
Why crush the small- directions hardest? Least squares' coefficient along is , and the noise component has variance , so that coefficient is noisiest exactly where the inputs vary least:
The trace of the smoother matrix counts how many directions survive, and serves as the fit's effective number of parameters:
falling continuously from at to as . For any linear smoother with fixed, , so this trace equals the covariance definition of degrees of freedom, , which Effective Complexity & Degrees of Freedom develops for any fitting procedure.
has singular values , , and . What are ridge's effective degrees of freedom at ?
Show the answer
2.4
. Four coefficients, but the fit spends only 2.4 degrees of freedom: the strongest direction is kept almost whole, the weakest is essentially discarded, and the two in between are kept at 90% and 50%.
Bias, variance and a theorem
Work in the fixed-design model with , and of full column rank, so that least squares () exists. Write , , and for the true coefficients in the eigenbasis.
Ridge is linear in with mean , and , so the bias is
Its covariance follows from with :
The mean-squared-error matrix adds covariance and the outer product of the bias. Its trace, the total error, splits into one term per eigendirection:
At the total is . Differentiating term by term, the slope at the origin is negative: the variance falls at first order in while the squared bias grows only at second order.
Factor through , using :
Subtract the ridge covariance from least squares' , then subtract the bias term:
The bracket equals . The first matrix has eigenvalues and , both positive under the hypothesis, and the second is positive definite. A congruence by the invertible preserves positive definiteness:
The same identity gives the exact condition, because for positive definite , exactly when :
Orthonormal design (), , and for every : twenty weak signals. With the best , what percentage of least squares' total error does ridge make?
Show the answer
20 %
Each term is , minimized at , where it equals , against for least squares: 20%. The best is ten times Theobald's guaranteed-safe bound , which protects every direction at once and is far from necessary for the total error.
Posterior mean and dual form
Put a prior on the weights and take . The log posterior is plus a constant, a quadratic in , so the posterior is Gaussian:
Ridge is the posterior mean, median and mode at once. If really is drawn from this prior, no estimator of any kind has smaller average error , so is the best possible tuning on average. Bayesian Linear Regression derives the predictive distribution and tunes by maximizing the evidence.
The push-through identity: ; multiply on the left and right by the two inverses.
So the ridge weights are a combination of the training inputs, with coefficients from an system instead of a one:
Predictions need only inner products between inputs, the entries of the Gram matrix and :
Replace by a kernel and the same formula is kernel ridge regression (The Kernel Trick). With and , the limit is the interpolant of minimum norm, the point that gradient descent from zero converges to (The Implicit Bias of Gradient Descent):
Think first You have documents described by word counts. Should you solve ridge in the primal or the dual form, and roughly how large is the difference in cost?
The dual. Forming takes about operations and solving a system about . The primal needs , about operations, then a solve, about . Sparsity shrinks both, but a gap of several orders of magnitude remains, and the push-through identity guarantees the same coefficients either way.
Leave-one-out in a single fit
Let be the ridge fit without example , and let equal except that : the deleted model's own prediction. The full ridge objective on is the leave-one-out objective plus one extra term:
At the first part has zero gradient and the extra term has zero residual, hence zero gradient. is strictly convex, so is the full ridge fit to . Ridge predictions are linear in the targets, , so
because has all eigenvalues below 1. Solve for and subtract from :
The argument uses only two facts, that the fit is linear in and that the objective is a strictly convex quadratic, so it also covers least squares with full-rank (whenever ), any quadratic penalty that keeps the objective strictly convex, and smoothing splines. Points of high leverage get their residuals inflated most, because the full fit leaned toward them.
Generalized cross-validation replaces every by the average :
Golub, Heath & Wahba (1979) studied it for choosing the ridge parameter: it needs no estimate of , and unlike leave-one-out it is invariant under rotations of the data (, with orthogonal leave the ridge problem unchanged but move the leverages). For small , , so GCV is the training error plus a charge of about times itself, in the spirit of Mallows' . Craven & Wahba (1978) introduced the same criterion for smoothing splines; Cross-Validation: Theory & Pitfalls compares these estimates in general.
Ridge when p/n stays fixed
Classical asymptotics fix and let ; then least squares is consistent and the best becomes negligible. Modern data often have comparable to or larger. The clean model for that regime: rows , , signal strength , noise variance .
| Estimator | Limiting error | Comment |
|---|---|---|
| the baseline any useful method must beat | ||
| Ridgeless (), | least squares; explodes as | |
| Ridgeless (), | minimum-norm interpolation; falls again beyond | |
| Optimally tuned ridge | smooth in , no peak | , i.e. per example |
Think first Take and . Rank the three estimators by error: , the minimum-norm interpolant, and optimally tuned ridge.
Optimal ridge, about (a numerical evaluation of the limit), beats at , which beats the interpolant at . Interpolating the noise is worse than not fitting at all here. With a stronger signal, , the interpolant's error is , now well below the zero estimator's : whether interpolation hurts depends on the signal-to-noise ratio.
Implicit ridge, and negative penalties. Append pure-noise features of small variance to the data, , and take the minimum-norm least-squares fit. By the dual form its weights on the real features are , and when the law of large numbers gives : the result is ridge on with , although nobody added a penalty. Real high-dimensional data often look like this, a few high-variance directions that carry the signal plus a long tail of low-variance ones, and Kobak, Lomond & Sanchez (2020) found that the cross-validated best ridge penalty on such data can be zero or even negative: the tail already over-regularizes, and a negative gives some of it back. Ridge with is defined through the dual formula , which makes sense whenever exceeds minus the smallest eigenvalue of , although the penalized objective is then unbounded below. They proved that the optimum is negative in a spiked covariance model whose high-variance directions carry the signal.
Key takeaways
- Through the SVD, ridge multiplies the fit along each direction by , a smooth version of principal components regression, and its effective degrees of freedom are .
- Ridge's bias is and its covariance ; for it beats least squares in every direction (Theobald), so some always helps (Hoerl–Kennard).
- Ridge is the posterior mean under with , and by the push-through identity it equals , which needs only inner products: kernel ridge regression.
- Leave-one-out residuals are from a single fit; GCV replaces by and is rotation invariant.
- With , the ridgeless fit peaks at while optimally tuned ridge has no peak; many low-variance directions act as implicit ridge, which can make the best explicit penalty zero or negative.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Ridge's shrinkage factor along the -th singular direction is . If , what fraction of the least-squares fit along survives?
- One half
- None: directions with are removed
- All of it: ridge shrinks the weights, not the fitted values
Show the answer
A. One half
. Ridge is a smooth filter: directions with pass almost untouched, those with are almost removed, and itself marks the halfway point.
Why does the theorem that some beats least squares not contradict the Gauss–Markov theorem?
- Gauss–Markov assumes Gaussian noise and the ridge theorem does not
- Ridge is a nonlinear function of
- Gauss–Markov compares only unbiased linear estimators, and ridge is biased
- The ridge theorem measures prediction error, while Gauss–Markov measures coefficient error
Show the answer
C. Gauss–Markov compares only unbiased linear estimators, and ridge is biased
Least squares is the best unbiased linear estimator. Ridge gives up unbiasedness, and the trade pays off: its mean-squared-error matrix is smaller than least squares' whenever .
You rotate the data, and for an orthogonal matrix . Which of these can change?
- The ridge coefficients
- The effective degrees of freedom
- The GCV score
- The leave-one-out error
Show the answer
D. The leave-one-out error
, so the ridge problem, its coefficients and are unchanged, and GCV depends only on those. Leave-one-out depends on the individual leverages , which the rotation reshuffles: it deletes rotated "examples" that mix the original ones.
On a dataset with samples and features, cross-validation picks for ridge. What is a plausible explanation?
- The data must be noise-free
- Many low-variance features already act as an implicit ridge penalty, so no explicit penalty is needed
- Ridge cannot be fitted when , so the software fell back to
- Cross-validation always selects when
Show the answer
B. Many low-variance features already act as an implicit ridge penalty, so no explicit penalty is needed
The minimum-norm fit on behaves like ridge on with when holds many low-variance directions. If that implicit penalty is already about right, or too strong, the best explicit penalty is zero or negative (Kobak, Lomond & Sanchez, 2020).
Further reading
- A. E. Hoerl & R. W. Kennard, "Ridge regression: biased estimation for nonorthogonal problems," Technometrics 12(1), 55–67 (1970).
- G. H. Golub, M. Heath & G. Wahba, "Generalized cross-validation as a method for choosing a good ridge parameter," Technometrics 21(2), 215–223 (1979).
- T. Hastie, A. Montanari, S. Rosset & R. J. Tibshirani, "Surprises in high-dimensional ridgeless least squares interpolation," Annals of Statistics 50(2), 949–986 (2022).
- D. Kobak, J. Lomond & B. Sanchez, "The optimal ridge penalty for real-world high-dimensional data can be zero or negative due to the implicit ridge regularization," Journal of Machine Learning Research 21(169), 1–16 (2020).
- T. Hastie, R. Tibshirani & J. Friedman, The Elements of Statistical Learning, 2nd ed. (Springer, 2009), §3.4.