Simple Algorithm
Machine Learning · Convergence · 28 min

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 dj2/(dj2+λ)d_j^2/(d_j^2+\lambda). 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 ∑jdj2/(dj2+λ)\sum_jd_j^2/(d_j^2+\lambda).
  • Derive the bias, covariance and mean-squared-error matrix of ridge, and prove that it beats least squares in every direction when 0<λ<2σ2/∥w⋆∥20<\lambda<2\sigma^2/\norm{\mathbf w^\star}^2.
  • Identify ridge as a Gaussian posterior mean, and derive its dual form X⊤(XX⊤+λI)−1yX^\top(XX^\top+\lambda I)^{-1}\mathbf y, the doorway to kernel methods.
  • Prove the one-fit leave-one-out formula, derive generalized cross-validation, and describe ridge when p/np/n stays fixed: Bayes-optimal tuning, the ridgeless peak and implicit regularization.

Ridge as a spectral filter

Write the thin singular value decomposition X=UDV⊤X=UDV^\top: U∈Rn×rU\in\R^{n\times r} and V∈Rp×rV\in\R^{p\times r} have orthonormal columns uj\mathbf u_j and vj\mathbf v_j, and D=diag⁡(d1,…,dr)D=\diag(d_1,\dots,d_r) with d1≥⋯≥dr>0d_1\ge\dots\ge d_r>0, where r=rank⁡Xr=\rank X. For centered features the vj\mathbf v_j are the principal directions of the data and dj2/nd_j^2/n is the variance along vj\mathbf v_j (PCA in Depth). Ridge regression minimizes ∥y−Xw∥2+λ∥w∥2\norm{\mathbf y-X\mathbf w}^2+\lambda\norm{\mathbf w}^2: λ\lambda is on the sum-of-squares scale of Regularization: Ridge & Lasso, and the regpath widget's λ\lambda, which charges the penalty against the error per example, is this one divided by nn.

DerivationRidge through the SVD
  1. w^λ=(X⊤X+λI)−1VDU⊤y=∑j=1rvj djdj2+λ uj⊤y\hat{\mathbf w}_\lambda=(X^\top X+\lambda I)^{-1}VDU^\top\mathbf y=\sum_{j=1}^r\mathbf v_j\,\frac{d_j}{d_j^2+\lambda}\,\mathbf u_j^\top\mathbf y

    Since X⊤X=VD2V⊤X^\top X=VD^2V^\top, the inverse (X⊤X+λI)−1(X^\top X+\lambda I)^{-1} multiplies each vj\mathbf v_j by 1/(dj2+λ)1/(d_j^2+\lambda) (and the directions orthogonal to all vj\mathbf v_j by 1/λ1/\lambda, but X⊤=VDU⊤X^\top=VDU^\top never reaches them):

  2. Xw^λ=∑j=1ruj dj2dj2+λ⏟shrinkage factor uj⊤yX\hat{\mathbf w}_\lambda=\sum_{j=1}^r\mathbf u_j\,\underbrace{\frac{d_j^2}{d_j^2+\lambda}}_{\text{shrinkage factor}}\,\mathbf u_j^\top\mathbf y

    Multiply by XX. The fitted values keep each orthonormal direction uj\mathbf u_j of the data with a factor between 0 and 1:

  3. λ→0+: w^λ→X+y=∑j=1ruj⊤ydj vj,PCRk: factor 1{j≤k}\lambda\to0^+:\ \hat{\mathbf w}_\lambda\to X^+\mathbf y=\sum_{j=1}^r\frac{\mathbf u_j^\top\mathbf y}{d_j}\,\mathbf v_j,\qquad\text{PCR}_k:\ \text{factor }\mathbf 1\{j\le k\}

    Least squares is the limit λ→0+\lambda\to0^+: every factor becomes 1, the fit is the projection onto the column space of XX, and the weights become the minimum-norm solution X+yX^+\mathbf y. Principal components regression with kk components uses factors 11 for j≤kj\le k and 00 beyond: a hard cutoff where ridge has a smooth one.

  4. Var⁡(uj⊤ydj)=σ2dj2\Var\Big(\frac{\mathbf u_j^\top\mathbf y}{d_j}\Big)=\frac{\sigma^2}{d_j^2}

    Why crush the small-djd_j directions hardest? Least squares' coefficient along vj\mathbf v_j is uj⊤y/dj\mathbf u_j^\top\mathbf y/d_j, and the noise component uj⊤ε\mathbf u_j^\top\boldsymbol\varepsilon has variance σ2\sigma^2, so that coefficient is noisiest exactly where the inputs vary least:

The trace of the smoother matrix Hλ=X(X⊤X+λI)−1X⊤H_\lambda=X(X^\top X+\lambda I)^{-1}X^\top counts how many directions survive, and serves as the fit's effective number of parameters:

df(λ)=tr⁡Hλ=∑j=1rdj2dj2+λ,\mathrm{df}(\lambda)=\operatorname{tr}H_\lambda=\sum_{j=1}^r\frac{d_j^2}{d_j^2+\lambda},

falling continuously from rr at λ=0\lambda=0 to 00 as λ→∞\lambda\to\infty. For any linear smoother y^=Hy\hat{\mathbf y}=H\mathbf y with HH fixed, Cov⁡(y^,y)=σ2H\Cov(\hat{\mathbf y},\mathbf y)=\sigma^2H, so this trace equals the covariance definition of degrees of freedom, ∑iCov⁡(y^i,yi)/σ2\sum_i\Cov(\hat y_i,y_i)/\sigma^2, which Effective Complexity & Degrees of Freedom develops for any fitting procedure.

Predict before you look

XX has singular values 1010, 33, 11 and 0.10.1. What are ridge's effective degrees of freedom at λ=1\lambda=1?

Show the answer

2.4

100101+910+12+0.011.01=0.990+0.9+0.5+0.010=2.40\frac{100}{101}+\frac9{10}+\frac12+\frac{0.01}{1.01}=0.990+0.9+0.5+0.010=2.40. 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 y=Xw⋆+ε\mathbf y=X\mathbf w^\star+\boldsymbol\varepsilon with Eε=0\E\boldsymbol\varepsilon=\mathbf 0, Cov⁡ε=σ2I\Cov\boldsymbol\varepsilon=\sigma^2I and XX of full column rank, so that least squares (λ=0\lambda=0) exists. Write A=X⊤XA=X^\top X, Wλ=(A+λI)−1W_\lambda=(A+\lambda I)^{-1}, and αj=vj⊤w⋆\alpha_j=\mathbf v_j^\top\mathbf w^\star for the true coefficients in the eigenbasis.

DerivationThe mean-squared-error matrix
  1. Ew^λ−w⋆=−λ Wλw⋆\E\hat{\mathbf w}_\lambda-\mathbf w^\star=-\lambda\,W_\lambda\mathbf w^\star

    Ridge is linear in y\mathbf y with mean WλAw⋆W_\lambda A\mathbf w^\star, and WλA=I−λWλW_\lambda A=I-\lambda W_\lambda, so the bias is

  2. Cov⁡(w^λ)=σ2 WλAWλ\Cov(\hat{\mathbf w}_\lambda)=\sigma^2\,W_\lambda AW_\lambda

    Its covariance follows from Cov⁡(By)=σ2BB⊤\Cov(B\mathbf y)=\sigma^2BB^\top with B=WλX⊤B=W_\lambda X^\top:

  3. M(λ)=σ2WλAWλ+λ2Wλw⋆w⋆⊤Wλ,tr⁡M(λ)=∑j=1pσ2dj2+λ2αj2(dj2+λ)2M(\lambda)=\sigma^2W_\lambda AW_\lambda+\lambda^2W_\lambda\mathbf w^\star\mathbf w^{\star\top}W_\lambda,\qquad\operatorname{tr}M(\lambda)=\sum_{j=1}^p\frac{\sigma^2d_j^2+\lambda^2\alpha_j^2}{(d_j^2+\lambda)^2}

    The mean-squared-error matrix M(λ)=E[(w^λ−w⋆)(w^λ−w⋆)⊤]M(\lambda)=\E\big[(\hat{\mathbf w}_\lambda-\mathbf w^\star)(\hat{\mathbf w}_\lambda-\mathbf w^\star)^\top\big] adds covariance and the outer product of the bias. Its trace, the total error, splits into one term per eigendirection:

  4. ddλtr⁡M(λ)∣λ=0=−2σ2∑j=1p1dj4<0\frac{d}{d\lambda}\operatorname{tr}M(\lambda)\Big|_{\lambda=0}=-2\sigma^2\sum_{j=1}^p\frac1{d_j^4}<0

    At λ=0\lambda=0 the total is σ2∑j1/dj2\sigma^2\sum_j1/d_j^2. Differentiating term by term, the slope at the origin is negative: the variance falls at first order in λ\lambda while the squared bias grows only at second order.

DerivationProof
  1. A−1=Wλ(A+λI)A−1(A+λI)Wλ=Wλ(A+2λI+λ2A−1)WλA^{-1}=W_\lambda(A+\lambda I)A^{-1}(A+\lambda I)W_\lambda=W_\lambda\big(A+2\lambda I+\lambda^2A^{-1}\big)W_\lambda

    Factor A−1A^{-1} through WλW_\lambda, using Wλ−1=A+λIW_\lambda^{-1}=A+\lambda I:

  2. M(0)−M(λ)=λ Wλ[σ2(2I+λA−1)−λ w⋆w⋆⊤]WλM(0)-M(\lambda)=\lambda\,W_\lambda\Big[\sigma^2\big(2I+\lambda A^{-1}\big)-\lambda\,\mathbf w^\star\mathbf w^{\star\top}\Big]W_\lambda

    Subtract the ridge covariance σ2WλAWλ\sigma^2W_\lambda AW_\lambda from least squares' σ2A−1\sigma^2A^{-1}, then subtract the bias term:

  3. 0<λ<2σ2∥w⋆∥2⟹M(0)−M(λ)≻00<\lambda<\frac{2\sigma^2}{\norm{\mathbf w^\star}^2}\quad\Longrightarrow\quad M(0)-M(\lambda)\succ0

    The bracket equals (2σ2I−λw⋆w⋆⊤)+λσ2A−1\big(2\sigma^2I-\lambda\mathbf w^\star\mathbf w^{\star\top}\big)+\lambda\sigma^2A^{-1}. The first matrix has eigenvalues 2σ22\sigma^2 and 2σ2−λ∥w⋆∥22\sigma^2-\lambda\norm{\mathbf w^\star}^2, both positive under the hypothesis, and the second is positive definite. A congruence by the invertible WλW_\lambda preserves positive definiteness:

  4. M(0)−M(λ)≻0  ⟺  w⋆⊤(2λ−1I+A−1)−1w⋆<σ2M(0)-M(\lambda)\succ0\iff\mathbf w^{\star\top}\big(2\lambda^{-1}I+A^{-1}\big)^{-1}\mathbf w^\star<\sigma^2

    The same identity gives the exact condition, because for positive definite BB, B−λww⊤≻0B-\lambda\mathbf w\mathbf w^\top\succ0 exactly when λw⊤B−1w<1\lambda\mathbf w^\top B^{-1}\mathbf w<1:

Predict before you look

Orthonormal design (dj=1d_j=1), p=20p=20, σ2=1\sigma^2=1 and αj2=0.25\alpha_j^2=0.25 for every jj: twenty weak signals. With the best λ\lambda, what percentage of least squares' total error does ridge make?

Show the answer

20 %

Each term is (1+0.25λ2)/(1+λ)2(1+0.25\lambda^2)/(1+\lambda)^2, minimized at λ=σ2/αj2=4\lambda=\sigma^2/\alpha_j^2=4, where it equals σ2/(1+σ2/αj2)=0.2\sigma^2/(1+\sigma^2/\alpha_j^2)=0.2, against 11 for least squares: 20%. The best λ=4\lambda=4 is ten times Theobald's guaranteed-safe bound 2σ2/∥w⋆∥2=2/52\sigma^2/\norm{\mathbf w^\star}^2=2/5, which protects every direction at once and is far from necessary for the total error.

Posterior mean and dual form

Put a prior w∼N(0,τ2I)\mathbf w\sim\mathcal N(\mathbf 0,\tau^2I) on the weights and take y∣w∼N(Xw,σ2I)\mathbf y\mid\mathbf w\sim\mathcal N(X\mathbf w,\sigma^2I). The log posterior is −12σ2(∥y−Xw∥2+σ2τ2∥w∥2)-\frac1{2\sigma^2}\big(\norm{\mathbf y-X\mathbf w}^2+\frac{\sigma^2}{\tau^2}\norm{\mathbf w}^2\big) plus a constant, a quadratic in w\mathbf w, so the posterior is Gaussian:

w∣y ∼ N(w^λ, σ2(X⊤X+λI)−1),λ=σ2τ2.\mathbf w\mid\mathbf y\ \sim\ \mathcal N\Big(\hat{\mathbf w}_\lambda,\ \sigma^2(X^\top X+\lambda I)^{-1}\Big),\qquad\lambda=\frac{\sigma^2}{\tau^2}.

Ridge is the posterior mean, median and mode at once. If w⋆\mathbf w^\star really is drawn from this prior, no estimator of any kind has smaller average error E∥w^−w⋆∥2\E\norm{\hat{\mathbf w}-\mathbf w^\star}^2, so λ=σ2/τ2\lambda=\sigma^2/\tau^2 is the best possible tuning on average. Bayesian Linear Regression derives the predictive distribution and tunes λ\lambda by maximizing the evidence.

DerivationThe dual (kernel) form
  1. (X⊤X+λI)−1X⊤=X⊤(XX⊤+λI)−1(X^\top X+\lambda I)^{-1}X^\top=X^\top(XX^\top+\lambda I)^{-1}

    The push-through identity: (X⊤X+λI)X⊤=X⊤(XX⊤+λI)(X^\top X+\lambda I)X^\top=X^\top(XX^\top+\lambda I); multiply on the left and right by the two inverses.

  2. w^λ=X⊤α^=∑i=1nα^i xi,α^=(K+λI)−1y,K=XX⊤\hat{\mathbf w}_\lambda=X^\top\hat{\boldsymbol\alpha}=\sum_{i=1}^n\hat\alpha_i\,\mathbf x_i,\qquad\hat{\boldsymbol\alpha}=(K+\lambda I)^{-1}\mathbf y,\qquad K=XX^\top

    So the ridge weights are a combination of the training inputs, with coefficients from an n×nn\times n system instead of a p×pp\times p one:

  3. f^(x)=x⊤w^λ=∑i=1nα^i xi⊤x=k(x)⊤(K+λI)−1y\hat f(\mathbf x)=\mathbf x^\top\hat{\mathbf w}_\lambda=\sum_{i=1}^n\hat\alpha_i\,\mathbf x_i^\top\mathbf x=\mathbf k(\mathbf x)^\top(K+\lambda I)^{-1}\mathbf y

    Predictions need only inner products between inputs, the entries Kik=xi⊤xkK_{ik}=\mathbf x_i^\top\mathbf x_k of the Gram matrix and ki(x)=xi⊤xk_i(\mathbf x)=\mathbf x_i^\top\mathbf x:

  4. λ→0+:w^λ→X⊤(XX⊤)−1y=X+y\lambda\to0^+:\quad\hat{\mathbf w}_\lambda\to X^\top(XX^\top)^{-1}\mathbf y=X^+\mathbf y

    Replace xi⊤x\mathbf x_i^\top\mathbf x by a kernel k(xi,x)k(\mathbf x_i,\mathbf x) and the same formula is kernel ridge regression (The Kernel Trick). With p>np>n and rank⁡X=n\rank X=n, the limit λ→0+\lambda\to0^+ 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 n=500n=500 documents described by p=100,000p=100{,}000 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 K=XX⊤K=XX^\top takes about n2p=2.5×1010n^2p=2.5\times10^{10} operations and solving a 500×500500\times500 system about n3≈108n^3\approx10^8. The primal needs X⊤XX^\top X, about np2=5×1012np^2=5\times10^{12} operations, then a 100,000×100,000100{,}000\times100{,}000 solve, about p3=1015p^3=10^{15}. 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

DerivationProof by self-consistency
  1. J~(w)=∑k≠i(yk−xk⊤w)2+λ∥w∥2⏟minimized by w(−i)+(y~i−xi⊤w)2\tilde J(\mathbf w)=\underbrace{\sum_{k\ne i}(y_k-\mathbf x_k^\top\mathbf w)^2+\lambda\norm{\mathbf w}^2}_{\text{minimized by }\mathbf w_{(-i)}}+\big(\tilde y_i-\mathbf x_i^\top\mathbf w\big)^2

    Let w(−i)\mathbf w_{(-i)} be the ridge fit without example ii, and let y~\tilde{\mathbf y} equal y\mathbf y except that y~i=xi⊤w(−i)=y^(−i)\tilde y_i=\mathbf x_i^\top\mathbf w_{(-i)}=\hat y_{(-i)}: the deleted model's own prediction. The full ridge objective on y~\tilde{\mathbf y} is the leave-one-out objective plus one extra term:

  2. y^(−i)=(Hy~)i=∑k≠iHikyk+Hii y^(−i)=y^i−Hii yi+Hii y^(−i)\hat y_{(-i)}=(H\tilde{\mathbf y})_i=\sum_{k\ne i}H_{ik}y_k+H_{ii}\,\hat y_{(-i)}=\hat y_i-H_{ii}\,y_i+H_{ii}\,\hat y_{(-i)}

    At w(−i)\mathbf w_{(-i)} the first part has zero gradient and the extra term has zero residual, hence zero gradient. J~\tilde J is strictly convex, so w(−i)\mathbf w_{(-i)} is the full ridge fit to y~\tilde{\mathbf y}. Ridge predictions are linear in the targets, y^=Hy\hat{\mathbf y}=H\mathbf y, so

  3. y^(−i)=y^i−Hii yi1−Hii⟹yi−y^(−i)=yi−y^i1−Hii\hat y_{(-i)}=\frac{\hat y_i-H_{ii}\,y_i}{1-H_{ii}}\quad\Longrightarrow\quad y_i-\hat y_{(-i)}=\frac{y_i-\hat y_i}{1-H_{ii}}

    Hii<1H_{ii}<1 because H=∑jujdj2dj2+λuj⊤H=\sum_j\mathbf u_j\frac{d_j^2}{d_j^2+\lambda}\mathbf u_j^\top has all eigenvalues below 1. Solve for y^(−i)\hat y_{(-i)} and subtract from yiy_i:

The argument uses only two facts, that the fit is linear in y\mathbf y and that the objective is a strictly convex quadratic, so it also covers least squares with full-rank XX (whenever Hii<1H_{ii}<1), any quadratic penalty λw⊤Ωw\lambda\mathbf w^\top\Omega\mathbf w that keeps the objective strictly convex, and smoothing splines. Points of high leverage HiiH_{ii} get their residuals inflated most, because the full fit leaned toward them.

Generalized cross-validation replaces every HiiH_{ii} by the average tr⁡(H)/n=df(λ)/n\operatorname{tr}(H)/n=\mathrm{df}(\lambda)/n:

GCV(λ)=1n∥y−Hy∥2(1−df(λ)/n)2.\mathrm{GCV}(\lambda)=\frac{\frac1n\norm{\mathbf y-H\mathbf y}^2}{\big(1-\mathrm{df}(\lambda)/n\big)^2}.

Golub, Heath & Wahba (1979) studied it for choosing the ridge parameter: it needs no estimate of σ2\sigma^2, and unlike leave-one-out it is invariant under rotations of the data (y→Qy\mathbf y\to Q\mathbf y, X→QXX\to QX with QQ orthogonal leave the ridge problem unchanged but move the leverages). For small df/n\mathrm{df}/n, (1−df/n)−2≈1+2 df/n(1-\mathrm{df}/n)^{-2}\approx1+2\,\mathrm{df}/n, so GCV is the training error plus a charge of about 2 df/n2\,\mathrm{df}/n times itself, in the spirit of Mallows' CpC_p. 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 pp and let n→∞n\to\infty; then least squares is consistent and the best λ\lambda becomes negligible. Modern data often have pp comparable to nn or larger. The clean model for that regime: rows xi∼N(0,Ip)\mathbf x_i\sim\mathcal N(\mathbf 0,I_p), p/n→γ∈(0,∞)p/n\to\gamma\in(0,\infty), signal strength ∥w⋆∥2=r2\norm{\mathbf w^\star}^2=r^2, noise variance σ2\sigma^2.

EstimatorLimiting error ∥w^−w⋆∥2\norm{\hat{\mathbf w}-\mathbf w^\star}^2Comment
w^=0\hat{\mathbf w}=\mathbf 0r2r^2the baseline any useful method must beat
Ridgeless (λ→0+\lambda\to0^+), γ<1\gamma<1σ2 γ1−γ\sigma^2\,\dfrac{\gamma}{1-\gamma}least squares; explodes as γ→1\gamma\to1
Ridgeless (λ→0+\lambda\to0^+), γ>1\gamma>1r2(1−1γ)+σ2γ−1r^2\big(1-\tfrac1\gamma\big)+\dfrac{\sigma^2}{\gamma-1}minimum-norm interpolation; falls again beyond γ=1\gamma=1
Optimally tuned ridgesmooth in γ\gamma, no peakλ=pσ2/r2\lambda=p\sigma^2/r^2, i.e. γσ2/r2\gamma\sigma^2/r^2 per example
The ridgeless rows are from Hastie, Montanari, Rosset & Tibshirani (2022). The peak at γ=1\gamma=1, where XX is square and its smallest singular values approach zero, is the double-descent curve of Double Descent. For optimal tuning: under the prior w⋆∼N(0,(r2/p)I)\mathbf w^\star\sim\mathcal N(\mathbf 0,(r^2/p)I), step 3 makes ridge with λ=pσ2/r2\lambda=p\sigma^2/r^2 the best estimator outright; Nakkiran, Venkat, Kakade & Ma (2021) proved that in isotropic linear models optimally tuned ridge removes the peak, and Dobriban & Wager (2018) computed the limiting risk of ridge for general covariance spectra with the Marchenko–Pastur law.
Think first Take γ=2\gamma=2 and r2=σ2=1r^2=\sigma^2=1. Rank the three estimators by error: w^=0\hat{\mathbf w}=\mathbf 0, the minimum-norm interpolant, and optimally tuned ridge.

Optimal ridge, about 0.780.78 (a numerical evaluation of the limit), beats w^=0\hat{\mathbf w}=\mathbf 0 at r2=1r^2=1, which beats the interpolant at 1⋅12+12−1=1.51\cdot\frac12+\frac1{2-1}=1.5. Interpolating the noise is worse than not fitting at all here. With a stronger signal, r2=10r^2=10, the interpolant's error is 10⋅12+1=610\cdot\frac12+1=6, now well below the zero estimator's 1010: whether interpolation hurts depends on the signal-to-noise ratio.

Implicit ridge, and negative penalties. Append qq pure-noise features of small variance s2s^2 to the data, [X Z][X\ Z], and take the minimum-norm least-squares fit. By the dual form its weights on the real features are X⊤(XX⊤+ZZ⊤)−1yX^\top(XX^\top+ZZ^\top)^{-1}\mathbf y, and when q≫nq\gg n the law of large numbers gives ZZ⊤≈qs2InZZ^\top\approx qs^2I_n: the result is ridge on XX with λ=qs2\lambda=qs^2, 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 λ\lambda gives some of it back. Ridge with λ<0\lambda<0 is defined through the dual formula X⊤(XX⊤+λI)−1yX^\top(XX^\top+\lambda I)^{-1}\mathbf y, which makes sense whenever λ\lambda exceeds minus the smallest eigenvalue of XX⊤XX^\top, 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 uj\mathbf u_j by dj2/(dj2+λ)d_j^2/(d_j^2+\lambda), a smooth version of principal components regression, and its effective degrees of freedom are ∑jdj2/(dj2+λ)\sum_jd_j^2/(d_j^2+\lambda).
  • Ridge's bias is −λWλw⋆-\lambda W_\lambda\mathbf w^\star and its covariance σ2WλAWλ\sigma^2W_\lambda AW_\lambda; for 0<λ<2σ2/∥w⋆∥20<\lambda<2\sigma^2/\norm{\mathbf w^\star}^2 it beats least squares in every direction (Theobald), so some λ>0\lambda>0 always helps (Hoerl–Kennard).
  • Ridge is the posterior mean under N(0,τ2I)\mathcal N(\mathbf 0,\tau^2I) with λ=σ2/τ2\lambda=\sigma^2/\tau^2, and by the push-through identity it equals X⊤(XX⊤+λI)−1yX^\top(XX^\top+\lambda I)^{-1}\mathbf y, which needs only inner products: kernel ridge regression.
  • Leave-one-out residuals are (yi−y^i)/(1−Hii)(y_i-\hat y_i)/(1-H_{ii}) from a single fit; GCV replaces HiiH_{ii} by df/n\mathrm{df}/n and is rotation invariant.
  • With p/n→γp/n\to\gamma, the ridgeless fit peaks at γ=1\gamma=1 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.

Question 1

Ridge's shrinkage factor along the jj-th singular direction is dj2/(dj2+λ)d_j^2/(d_j^2+\lambda). If λ=dk2\lambda=d_k^2, what fraction of the least-squares fit along uk\mathbf u_k survives?

  1. One half
  2. 1/(1+λ)1/(1+\lambda)
  3. None: directions with dk2≤λd_k^2\le\lambda are removed
  4. All of it: ridge shrinks the weights, not the fitted values
Show the answer

A. One half

dk2/(dk2+dk2)=12d_k^2/(d_k^2+d_k^2)=\tfrac12. Ridge is a smooth filter: directions with dj2≫λd_j^2\gg\lambda pass almost untouched, those with dj2≪λd_j^2\ll\lambda are almost removed, and λ\lambda itself marks the halfway point.

Question 2

Why does the theorem that some λ>0\lambda>0 beats least squares not contradict the Gauss–Markov theorem?

  1. Gauss–Markov assumes Gaussian noise and the ridge theorem does not
  2. Ridge is a nonlinear function of y\mathbf y
  3. Gauss–Markov compares only unbiased linear estimators, and ridge is biased
  4. 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 0<λ<2σ2/∥w⋆∥20<\lambda<2\sigma^2/\norm{\mathbf w^\star}^2.

Question 3

You rotate the data, y→Qy\mathbf y\to Q\mathbf y and X→QXX\to QX for an orthogonal n×nn\times n matrix QQ. Which of these can change?

  1. The ridge coefficients
  2. The effective degrees of freedom
  3. The GCV score
  4. The leave-one-out error
Show the answer

D. The leave-one-out error

∥Qy−QXw∥=∥y−Xw∥\norm{Q\mathbf y-QX\mathbf w}=\norm{\mathbf y-X\mathbf w}, so the ridge problem, its coefficients and tr⁡H\operatorname{tr}H are unchanged, and GCV depends only on those. Leave-one-out depends on the individual leverages HiiH_{ii}, which the rotation reshuffles: it deletes rotated "examples" that mix the original ones.

Question 4

On a dataset with n=100n=100 samples and p=20,000p=20{,}000 features, cross-validation picks λ≈0\lambda\approx0 for ridge. What is a plausible explanation?

  1. The data must be noise-free
  2. Many low-variance features already act as an implicit ridge penalty, so no explicit penalty is needed
  3. Ridge cannot be fitted when p>np>n, so the software fell back to λ=0\lambda=0
  4. Cross-validation always selects λ=0\lambda=0 when p>np>n
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 [X Z][X\ Z] behaves like ridge on XX with λ≈qs2\lambda\approx qs^2 when ZZ 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.