MoonSay /Tutorials/Machine Learning Interview #4
Contents
  1. 01Introduction
  2. 02Overfitting and why we regularize
  3. 03L2 regularization
  4. 04L1 regularization
  5. 05The geometry
  6. 06Regularization paths
  7. 07A Bayesian view
  8. 08Early stopping
  9. 09Other ways to prevent overfitting
  10. 10Putting it all together
  11. 11Interview questions and model answers
  12. 12Summary
  13. References

12Summary

  • Regularized objective: J(w)=\|y-Xw\|_2^2+\lambda\,\Omega(w). \lambda trades bias for variance and is chosen by cross-validation. Some \lambda>0 always beats least squares (Theorem 1).
  • L2 (ridge, weight decay): \Omega=\|w\|_2^2, gradient 2\lambda w (spring), \hat w=(X^\top X+\lambda I)^{-1}X^\top y, shrinkage d_j/(d_j+\lambda) per eigen-direction, \mathrm{df}(\lambda)=\sum_jd_j/(d_j+\lambda); no exact zeros; Gaussian prior, \lambda=\sigma^2/\tau^2.
  • L1 (lasso): \Omega=\|w\|_1, push \lambda\operatorname{sign}(w) (flat tax); orthonormal solution S_{\lambda/2}(\hat w)=\operatorname{sign}(\hat w)(|\hat w|-\lambda/2)_+; w_j=0 iff |2x_{\cdot j}^\top(y-Xw)|\le\lambda; \lambda_{\max}=2\max_j|x_{\cdot j}^\top y|; coordinate descent; Laplace prior, \lambda=2\sigma^2/b.
  • Geometry: penalty \Leftrightarrow budget \Omega(w)\le t; the diamond’s corners lie on the axes, so contact at a corner gives zeros; the disc is smooth.
  • Elastic net: \lambda_1\|w\|_1+\lambda_2\|w\|_2^2: sparse, unique, keeps correlated groups together.
  • Early stopping: stop at the validation minimum (patience, restore the best weights); filter factor 1-(1-\eta h)^\tau versus h/(h+2\lambda), so \lambda\approx1/(2\eta\tau).
  • L2 in disguise: input noise of variance s^2 = ridge with \lambda=ns^2; dropout with keep probability p = ridge with \lambda_j=\frac{1-p}{p}\sum_iX_{ij}^2; weight decay = L2 for SGD but not for Adam (AdamW).
  • Practice: standardize, do not penalize the intercept, cross-validate \lambda on a log grid, test once.