Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Ridge Regression

Ridge adds a quadratic penalty to least squares. It produces a unique coefficient vector even with redundant columns when all coefficients are penalized and λ>0\lambda>0. Its main benefit is a controlled tradeoff between bias and variance.

Penalized Least Squares

For the all-coefficients-penalized convention,

β^λ=arg⁡min⁡β{∥y−Xβ∥2+λ∥β∥2},λ>0.\widehat\beta_\lambda=\arg\min_\beta \{\lVert y-X\beta\rVert^2+\lambda\lVert\beta\rVert^2\},\qquad\lambda>0.

Differentiation gives

−2X⊤(y−Xβ^λ)+2λβ^λ=0,-2X^\top(y-X\widehat\beta_\lambda)+2\lambda\widehat\beta_\lambda=0,

hence

β^λ=(X⊤X+λIp)−1X⊤y.\boxed{\widehat\beta_\lambda=(X^\top X+\lambda I_p)^{-1}X^\top y.}

For any nonzero aa,

a⊤(X⊤X+λI)a=∥Xa∥2+λ∥a∥2>0.a^\top(X^\top X+\lambda I)a=\lVert Xa\rVert^2+\lambda\lVert a\rVert^2>0.

Thus the penalized system is positive definite regardless of the rank of XX, including when p>np>n. In computation, solve the system rather than form its inverse.

Constrained Form

The related constrained problem is

min⁡β ∥y−Xβ∥2subject to∥β∥2≤t.\min_\beta\ \lVert y-X\beta\rVert^2 \quad\text{subject to}\quad\lVert\beta\rVert^2\leq t.

Its Lagrangian is

L(β,λ)=∥y−Xβ∥2+lambda(∥β∥2−t).\mathcal L(\beta,\lambda)=\lVert y-X\beta\rVert^2+lambda(\lVert\beta\rVert^2-t).

For t>0t>0, convexity and a strictly feasible point give the usual Lagrange-multiplier characterization. When the constraint is active, an appropriate multiplier yields a penalized solution. If the constraint is loose enough to contain an OLS minimizer, the multiplier may be zero. The relation between tt and λ\lambda depends on the data; they are not the same numerical parameter.

Geometrically, squared-error contours are ellipsoids and the constraint is a ball. The constrained optimum occurs where the smallest attainable contour meets the ball, unless an unconstrained minimizer already lies inside.

Spectral Shrinkage

Using the compact SVD X=UrDrVr⊤X=U_rD_rV_r^\top,

β^λ=Vrdiag⁡ ⁣(sjsj2+λ)Ur⊤y,\widehat\beta_\lambda =V_r\operatorname{diag}\!\left(\frac{s_j}{s_j^2+\lambda}\right)U_r^\top y,
y^λ=Hλy,Hλ=Urdiag⁡ ⁣(sj2sj2+λ)Ur⊤.\widehat y_\lambda=H_\lambda y,\qquad H_\lambda=U_r\operatorname{diag}\!\left(\frac{s_j^2}{s_j^2+\lambda}\right)U_r^\top.

For positive singular values, the ridge coefficient component equals its minimum-norm OLS counterpart times

wj(λ)=sj2sj2+λ∈(0,1).w_j(\lambda)=\frac{s_j^2}{s_j^2+\lambda}\in(0,1).
LimitCoefficientsFitted values
λ↓0\lambda\downarrow0Minimum-norm least-squares coefficients.OLS projection UrUr⊤yU_rU_r^\top y.
λ→∞\lambda\to\inftyZero, if all coefficients are penalized.Zero under the same convention.

HλH_\lambda is symmetric but generally not idempotent. Ridge shrinks a vector already in the fitted subspace, so it is a smoother rather than an orthogonal projection. Its residuals satisfy X⊤eλ=λβ^λX^\top e_\lambda=\lambda\widehat\beta_\lambda, not the OLS orthogonality condition.

Bias, Variance & Sampling Distribution

Assume Y=Xβ+εY=X\beta+\varepsilon with E[ε∣X]=0E[\varepsilon\mid X]=0 and covariance σ2I\sigma^2I. Let Bλ=(X⊤X+λI)−1B_\lambda=(X^\top X+\lambda I)^{-1}. Then

E[β^λ∣X]=BλX⊤Xβ,E[\widehat\beta_\lambda\mid X]=B_\lambda X^\top X\beta,
Bias⁡(β^λ∣X)=−λBλβ,\boxed{\operatorname{Bias}(\widehat\beta_\lambda\mid X)=-\lambda B_\lambda\beta,}
Cov⁡(β^λ∣X)=σ2BλX⊤XBλ.\boxed{\operatorname{Cov}(\widehat\beta_\lambda\mid X) =\sigma^2B_\lambda X^\top XB_\lambda.}

With Gaussian errors, the estimator is multivariate normal with this mean and covariance, possibly degenerate in null-space directions. These formulas assume fixed λ\lambda; selecting it using YY makes the overall procedure adaptive.

Derive the Bias & Covariance

Write Mλ=BλX⊤M_\lambda=B_\lambda X^\top, so β^λ=MλY\widehat\beta_\lambda=M_\lambda Y. Linearity gives its expectation and covariance. For the bias, use

BλX⊤X=Bλ[(X⊤X+λI)−λI]=I−λBλ.B_\lambda X^\top X=B_\lambda[(X^\top X+\lambda I)-\lambda I]=I-\lambda B_\lambda.

Subtracting β\beta yields −λBλβ-\lambda B_\lambda\beta. For covariance,

Mλ(σ2I)Mλ⊤=σ2BλX⊤XBλ,M_\lambda(\sigma^2I)M_\lambda^\top =\sigma^2B_\lambda X^\top XB_\lambda,

since BλB_\lambda is symmetric.

Mean Squared Error in a Singular Direction

For full column rank, let θj=vj⊤β\theta_j=v_j^\top\beta. Then

Bias⁡(vj⊤β^λ)=−λθjsj2+λ,Var⁡(vj⊤β^λ)=σ2sj2(sj2+λ)2,\operatorname{Bias}(v_j^\top\widehat\beta_\lambda) =-\frac{\lambda\theta_j}{s_j^2+\lambda},\qquad \operatorname{Var}(v_j^\top\widehat\beta_\lambda) =\frac{\sigma^2s_j^2}{(s_j^2+\lambda)^2},
MSE⁡(vj⊤β^λ)=λ2θj2+σ2sj2(sj2+λ)2.\boxed{\operatorname{MSE}(v_j^\top\widehat\beta_\lambda) =\frac{\lambda^2\theta_j^2+\sigma^2s_j^2}{(s_j^2+\lambda)^2}.}

The variance is no larger than OLS’s σ2/sj2\sigma^2/s_j^2, but the bias is generally nonzero. The best tradeoff depends on unknown signal strength, so prediction-based tuning is needed.

For example, with sj=0.1s_j=0.1, σ2=1\sigma^2=1, θj=1\theta_j=1, and λ=1\lambda=1, OLS MSE is 100. Ridge MSE is 1/1.01≈0.99011/1.01\approx0.9901. This is an illustrative weak-signal direction, not a guarantee of improvement for every true coefficient or penalty.

Intercepts & Scaling

Penalize all coefficients
Leave the intercept free

Use X⊤X+λIX^\top X+\lambda I. As λ→∞\lambda\to\infty, all coefficients and fitted values tend to zero.

In practice, fit

min⁡β0,b ∥y−β01−Zb∥2+λ∥b∥2,\min_{\beta_0,b}\ \lVert y-\beta_0\mathbf1-Zb\rVert^2+\lambda\lVert b\rVert^2,

leaving the intercept unpenalized. Let Zc=Z−1zˉ⊤Z_c=Z-\mathbf1\bar z^\top and yc=y−yˉ1y_c=y-\bar y\mathbf1. Then

b^λ=(Zc⊤Zc+λI)−1Zc⊤yc,β^0=yˉ−zˉ⊤b^λ.\widehat b_\lambda=(Z_c^\top Z_c+\lambda I)^{-1}Z_c^\top y_c,\qquad \widehat\beta_0=\bar y-\bar z^\top\widehat b_\lambda.

As λ→∞\lambda\to\infty, slopes approach zero and predictions approach the training mean yˉ\bar y, not zero.

Ridge depends on predictor units. Rescaling a column changes the coefficient norm required to represent the same prediction. Standardize predictors when equal treatment across scales is intended, and estimate centering/scaling using only the training portion of each validation split. Remove or otherwise handle zero-variance columns before standardization.

If the objective is n−1RSS⁡+α∥b∥2n^{-1}\operatorname{RSS}+\alpha\lVert b\rVert^2, multiplying by nn shows that the sum-scale penalty here is λ=nα\lambda=n\alpha.

Redundant Predictors: Stable Does Not Mean Invariant

Ridge remains solvable if a predictor is duplicated, but duplicating it generally changes the fit at fixed λ\lambda.