4.2 Ridge Regression

DATA 442/642 · Week 4 · PDF · Slides

Shrink coefficients with an L2 penalty.

These notes walk through the lecture slides. The original deck is unchanged; use (slides) on the course hub if you want that PDF.

The figures follow Deisenroth, Faisal, and Ong, Mathematics for Machine Learning, and Theodoridis, Machine Learning: A Bayesian and Optimization Perspective.

1. Shrinkage methods

Among the ℓp-norms with p≥1, only ℓ1 treats small coordinates with any respect. The others squeeze small values further and spend their attention on large ones.

Regularization is also there to make an estimator easier to interpret.

Least squares fits θ0,θ1,…,θl by

∑n=1N(yn−θ0−∑j=1lθjxj)2.

Ridge instead minimizes

∑n=1N(yn−θ0−∑j=1lθjxj)2+λ∑j=1lθj2,

with hyper-parameter λ≥0.


2. What λ does

The penalty λ∑j=1lθj2 forces the fit to keep the coefficients small. Add it only while training. Evaluate the trained model with the unregularized metric.

λ Effect
λ=0 Ridge is ordinary least squares
λ→∞ Ridge coefficients approach zero (they do not hit zero for finite λ)

The penalty hits θ1,…,θl, not θ0. If every column of 𝐗∈ℝN×l is centered,

θ^0=y¯=∑n=1Nyn/N.

3. Geometry

Ridge geometry: ellipse and circle

For l=2 the ridge constraint is a circle

θ12+θ22≤t,

where t is the radius. The RSS contours are ellipses. The ridge estimate is the point where the ellipse and the circle touch.

  • λ=0: you only shrink the ellipse (inner ellipses have smaller RSS). Highly correlated features make that geometry unpleasant.
  • Small λ: more variance, less bias. Large λ: some bias, less variance.

4. The closed form

J(θ)=(𝐲−𝐗θ)⊤(𝐲−𝐗θ)+λθ⊤θ.

Expand:

J(θ)=𝐲⊤𝐲−𝐲⊤𝐗θ−θ⊤𝐗⊤𝐲+θ⊤𝐗⊤𝐗θ+λθ⊤θ.

Set the derivative to zero:

∂J(θ)∂θ=−2𝐗⊤𝐲+2𝐗⊤𝐗θ+2λθ=0.

Then

(𝐗⊤𝐗+λ𝐈)θ=𝐗⊤𝐲,

so

θ^R=(𝐗⊤𝐗+λ𝐈)−1𝐗⊤𝐲.

5. Comments

  1. Ridge gives accurate predictions and reduced variance.
  2. Penalizing coefficient size controls overfitting: the model is less free to memorize noise.
  3. Ridge is the usual tool for multicollinearity. Shrinking correlated coefficients stabilizes the estimates.

6. Computational complexity

You can use the closed form or gradient descent, as with linear regression. The closed form inverts an l×l matrix (Cholesky and friends). That gets slow when the number of features is large. If there are too many features, or too many rows to fit in memory, use gradient descent.


7. Practice

  1. Why can ridge shrink coefficients but not set them to zero?

  2. What happens as λ→∞, and which coefficient is never penalized?

  3. Why does adding λ𝐈 help when columns of 𝐗 are highly correlated?