Lesson 5.4 · 10 min read · about 55 min to master at a very slow pace
Ridge Regression (L2)
Ridge adds a penalty on the sum of squared coefficients. Its closed-form solution, why it shrinks, why it always has a solution, how it handles correlated predictors, and two worked examples.
Ridge objective and solution
The intercept is not penalised (center the data, or exclude it from the penalty).
Show the derivation
Why it shrinks
Adding makes the "denominator" bigger. In the simplest case (orthonormal predictors):
Every coefficient is divided by something larger than 1. In general all coefficients move towards zero as grows, and as . They never become exactly zero.
Example A: one predictor, by hand
Centred data , . , .
| 0 | 2 | 6 | ||
|---|---|---|---|---|
| slope | 2 | 1 | 0.5 | 0 |
| training RSS | 0 | 2 | 4.5 | 8 (= TSS) |
As grows, the slope shrinks and training RSS rises.
Example B: two correlated predictors
OLS: , so .
Ridge, : , , so .
Ridge shrinks the large coefficient and shares credit with its correlated twin. The sum barely moves (1.26 vs 1.12), while the split is much more even and stable.
Properties
- Always solvable: is invertible for any , even when is singular (, perfect collinearity). Adding to every eigenvalue makes them all positive.
- Bias–variance: as increases, bias increases and variance decreases.
- Correlated predictors: shares the credit instead of producing huge opposite-sign coefficients.
- Cons: many small but non-zero coefficients (no variable selection), and no convenient significance test for coefficients.
Cheatsheet
Ridge
Ridge properties
Check your understanding
Score 75% or more to master this lesson and earn XP. Answer first, then check.