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.
Ordinary least squares is unbiased, but its variance explodes when:
there are many features relative to samples (p close to or larger than n),
features are strongly correlated (multicollinearity), so X⊤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 intercept is not penalised (centre y or include an unpenalised column).
Equivalent constrained form: minimise SSE subject to ∑βj2≤t.
Closed form
With centred data, setting the gradient −2X⊤(y−Xβ)+2λβ to zero:
β^ridge=(X⊤X+λI)−1X⊤y.
X⊤X has non-negative eigenvalues; adding λI shifts each up by λ, so the matrix is always invertible for λ>0. Ridge was invented precisely to fix singular or ill-conditioned X⊤X.
How shrinkage works: the SVD view
With X=UDV⊤:
Xβ^ridge=j∑ujdj2+λdj2uj⊤y.
Compared with OLS (factor 1), each principal direction is shrunk by dj2+λdj2 — strongly when dj is small, i.e. in directions where the data has little variance and estimates are noisiest. The effective degrees of freedomdf(λ)=∑jdj2+λdj2 falls smoothly from p to 0.
Ridge coefficient paths: smooth shrinkage, no coefficient becomes exactly zero.
Bias–variance effect
λ
Bias
Variance
Model
0
low (OLS is unbiased)
high
possibly overfit
moderate
some
much lower
usually best test error
→∞
high
→ 0
predicts the mean (underfit)
Training error increases monotonically with λ; test error is typically U-shaped. Choose λ by cross-validation.
Bayesian interpretation
With Gaussian noise ε∼N(0,σ2) and a prior βj∼N(0,τ2), the posterior mode (MAP estimate) is the ridge solution with λ=σ2/τ2. A stronger prior belief that coefficients are small (smaller τ) means larger λ.
Ridge vs lasso vs elastic net
Ridge (L2)
Lasso (L1)
Elastic net
Penalty
λ∑βj2
λ∑∣βj∣
λ1∑∣βj∣+λ2∑βj2
Closed form
yes
no (coordinate descent)
no
Exact zeros (feature selection)
no
yes
yes
Correlated features
shares weight among them
tends to pick one arbitrarily
groups them
Bayesian prior
Gaussian
Laplace
mixture
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, minw∑i(yi−wxi)2+λw2, is fitted to the points (1,2) and (2,4) with λ=5. The fitted w is ______.
Q2MCQ1 mark
As the ridge penalty λ→∞, 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 d is multiplied by the shrinkage factor d2+λd2. For d=3 and λ=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⊤y=(83) and λ=1, the first coefficient w^1 is ______.
Q8MCQ2 marks
How should the ridge penalty λ be chosen?
Q9NAT1 mark
A ridge regression with 5 standardised features has effective degrees of freedom df(λ)=∑jdj2+λdj2. When λ=0, df equals ______.