∑GATE DA Atlas

Ridge Regression and Regularization

Why least squares overfits with many or correlated features, the ridge objective and its closed-form solution, how the penalty λ shrinks coefficients (SVD view and effective degrees of freedom), the bias–variance effect, standardisation and the unpenalised intercept, the Bayesian MAP interpretation, and comparison with the lasso (L1) and elastic net.

Section 69 practice questions

Why regularise?

Ordinary least squares is unbiased, but its variance explodes when:

  • there are many features relative to samples (pp close to or larger than nn),
  • features are strongly correlated (multicollinearity), so X⊤XX^\top X is nearly singular.

The coefficients become huge, unstable and overfit noise. Regularisation adds a penalty on coefficient size, accepting a little bias for a large drop in variance.

The ridge objective

β^ridge=arg⁡min⁡β ∑i=1n(yi−β0−∑jβjxij)2+λ∑j=1pβj2,λ≥0.\hat{\boldsymbol\beta}^{\text{ridge}} = \arg\min_{\boldsymbol\beta}\ \sum_{i=1}^n\left(y_i - \beta_0 - \sum_j\beta_jx_{ij}\right)^2 + \lambda\sum_{j=1}^p\beta_j^2, \qquad \lambda \ge 0.
  • The intercept is not penalised (centre yy or include an unpenalised column).
  • Equivalent constrained form: minimise SSE subject to ∑βj2≤t\sum\beta_j^2 \le t.

Closed form

With centred data, setting the gradient −2X⊤(y−Xβ)+2λβ-2X^\top(\mathbf y - X\boldsymbol\beta) + 2\lambda\boldsymbol\beta to zero:

β^ridge=(X⊤X+λI)−1X⊤y.\hat{\boldsymbol\beta}^{\text{ridge}} = (X^\top X + \lambda I)^{-1}X^\top\mathbf y.

X⊤XX^\top X has non-negative eigenvalues; adding λI\lambda I shifts each up by λ\lambda, so the matrix is always invertible for λ>0\lambda > 0. Ridge was invented precisely to fix singular or ill-conditioned X⊤XX^\top X.

How shrinkage works: the SVD view

With X=UDV⊤X = UDV^\top:

Xβ^ridge=∑juj dj2dj2+λ uj⊤y.X\hat{\boldsymbol\beta}^{\text{ridge}} = \sum_{j}\mathbf u_j\,\frac{d_j^2}{d_j^2 + \lambda}\,\mathbf u_j^\top\mathbf y.

Compared with OLS (factor 1), each principal direction is shrunk by dj2dj2+λ\frac{d_j^2}{d_j^2 + \lambda} — strongly when djd_j is small, i.e. in directions where the data has little variance and estimates are noisiest. The effective degrees of freedom df⁡(λ)=∑jdj2dj2+λ\operatorname{df}(\lambda) = \sum_j\frac{d_j^2}{d_j^2 + \lambda} falls smoothly from pp to 0.

increasing λ →0 β₁β₂β₃ all coefficients shrink smoothly towards 0
Ridge coefficient paths: smooth shrinkage, no coefficient becomes exactly zero.

Bias–variance effect

λ\lambdaBiasVarianceModel
00low (OLS is unbiased)highpossibly overfit
moderatesomemuch lowerusually best test error
→∞\to\inftyhigh→ 0predicts the mean (underfit)

Training error increases monotonically with λ\lambda; test error is typically U-shaped. Choose λ\lambda by cross-validation.

Bayesian interpretation

With Gaussian noise ε∼N(0,σ2)\varepsilon \sim N(0, \sigma^2) and a prior βj∼N(0,τ2)\beta_j \sim N(0, \tau^2), the posterior mode (MAP estimate) is the ridge solution with λ=σ2/τ2\lambda = \sigma^2/\tau^2. A stronger prior belief that coefficients are small (smaller τ\tau) means larger λ\lambda.

Ridge vs lasso vs elastic net

Ridge (L2)Lasso (L1)Elastic net
Penaltyλ∑βj2\lambda\sum\beta_j^2λ∑∣βj∣\lambda\sum\lvert\beta_j\rvertλ1∑∣βj∣+λ2∑βj2\lambda_1\sum\lvert\beta_j\rvert + \lambda_2\sum\beta_j^2
Closed formyesno (coordinate descent)no
Exact zeros (feature selection)noyesyes
Correlated featuresshares weight among themtends to pick one arbitrarilygroups them
Bayesian priorGaussianLaplacemixture
ridge: ball lasso: diamond contours of the squared error first touch the L1 region at a corner (β₁ = 0)
The corners of the L1 region make zero coefficients likely; the round L2 region does not.

Quick revision

Practice questions

GATE-style questions: 3 one-mark and 6 two-mark. Wrong MCQs cost ⅓ of their marks in the real exam; MSQ and NAT have no negative marking. Attempt each before opening the solution.

Q1NAT2 marks

Ridge regression without intercept, min⁡w∑i(yi−wxi)2+λw2\min_w \sum_i(y_i - wx_i)^2 + \lambda w^2, is fitted to the points (1,2)(1, 2) and (2,4)(2, 4) with λ=5\lambda = 5. The fitted ww is ______.

Q2MCQ1 mark

As the ridge penalty λ→∞\lambda \to \infty, the ridge coefficient estimates (excluding the intercept)

Q3MSQ2 marks

Which statements about ridge regression are correct?

One or more options are correct.

Q4MCQ2 marks

Why does the lasso (L1 penalty) tend to produce sparse coefficient vectors while ridge (L2) does not?

Q5NAT2 marks

In the SVD view of ridge regression, the component of the fit along a singular direction with singular value dd is multiplied by the shrinkage factor d2d2+λ\dfrac{d^2}{d^2 + \lambda}. For d=3d = 3 and λ=9\lambda = 9, this factor is ______.

Q6MCQ1 mark

Ridge regression is equivalent to which Bayesian estimate?

Q7NAT2 marks

For a ridge regression with X⊤X=(4001)X^\top X = \begin{pmatrix}4 & 0\\0 & 1\end{pmatrix}, X⊤y=(83)X^\top\mathbf y = \begin{pmatrix}8\\3\end{pmatrix} and λ=1\lambda = 1, the first coefficient w^1\hat w_1 is ______.

Q8MCQ2 marks

How should the ridge penalty λ\lambda be chosen?

Q9NAT1 mark

A ridge regression with 5 standardised features has effective degrees of freedom df⁡(λ)=∑jdj2dj2+λ\operatorname{df}(\lambda) = \sum_j \dfrac{d_j^2}{d_j^2 + \lambda}. When λ=0\lambda = 0, df⁡\operatorname{df} equals ______.