Lesson 3.6core3 h⚡ live demo

Regularization and generalization

Three views of one idea: constraint, shrinkage and prior

Regularization is how you keep a flexible model from memorizing noise, and it is the same idea whether it appears as a penalty term in ridge regression, as weight decay in a transformer (4.7 Regularization in deep nets), as a KL term in RLHF (8.3 Alignment: RLHF, PPO, DPO, GRPO and Constitutional AI) or as early stopping. Seeing it three ways — geometry, shrinkage, Bayesian prior — makes every later instance obvious, and the modern twist (double descent) explains why billion-parameter models generalize at all.

You'll be able to

  • Derive the ridge closed form and explain, via the SVD, which directions it shrinks and why it fixes collinearity
  • Explain why the L1 penalty produces sparse solutions, geometrically and via soft-thresholding
  • Show that L2 and L1 regularization are MAP estimation under Gaussian and Laplace priors
  • Explain why early stopping, data augmentation and noise injection act as regularizers
  • Describe the classical U-curve, the interpolation threshold and double descent
  • Tune λ with cross-validation and read a regularization path

Key ideas

  1. Regularization is anything that lowers test error without lowering training error; the classical form adds λ·Ω(w) to the empirical risk.
  2. Ridge: w_λ = (XᵀX + λI)⁻¹Xᵀy; always invertible; via the SVD it shrinks direction j by σⱼ²/(σⱼ²+λ), damping the noisy low-variance directions most.
  3. Lasso soft-thresholds coefficients (subtract λ/2, zero the small ones) and selects features; the diamond-shaped ℓ₁ ball's corners are why.
Show 5 more key ideas
  1. Penalty ⇔ constraint (Lagrange duality) ⇔ prior: Gaussian prior gives ridge with λ = σ²/τ², Laplace prior gives lasso.
  2. Early stopping ≈ ridge with λ ≈ 1/(ηt): low-curvature (noisy) directions never get fitted.
  3. More data, augmentation (encoding invariances) and noise injection are regularizers without penalty terms.
  4. Double descent: test error peaks at the interpolation threshold and falls again for over-parameterized models because gradient descent finds min-norm, smooth interpolants.
  5. Tune λ on a log grid with cross-validation, standardize features, never penalize the intercept, and read the regularization path.

Suggested path through this lesson