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

10Putting it all together

10.1L1, L2, elastic net and early stopping side by side

Table 2 collects the main facts. The one-sentence summary: L2 is a spring that shrinks all weights smoothly and keeps them all; L1 is a flat tax that shrinks and selects; the elastic net does both and keeps correlated groups together; early stopping, input noise and dropout behave like L2.

L2 (ridge)L1 (lasso)Elastic netEarly stopping
Penalty\lambda\|w\|_2^2\lambda\|w\|_1\lambda_1\|w\|_1+\lambda_2\|w\|_2^2steps \tau
Force on a weight2\lambda w (spring)\lambda\operatorname{sign}(w) (tax)bothstop early
Exact zerosnoyesyesno
Correlated featuresshare the weightkeep onekeep the grouplike L2
Solutionclosed form (5)coordinate descent, LARScoordinate descentgradient descent
Uniqueyesnot alwaysyes–
Bayesian viewGaussian priorLaplace priormixed prior\approx Gaussian
Typical usecorrelated features; neural netsfeature selectionp\gg n; gene dataneural nets; boosting
Table 2. L2, L1, the elastic net and early stopping compared. Sources: Sections 3–8; Hastie et al. (2009); Zou and Hastie (2005); Goodfellow et al. (2016).

10.2A practical recipe

  1. Standardize the features (subtract the mean, divide by the standard deviation). The penalty treats all weights alike, but a weight’s size depends on its feature’s units: measured in grams instead of kilograms, a feature needs a weight 1{,}000 times smaller and would escape the penalty.
  2. Do not penalize the intercept. Shifting all targets by a constant should shift the predictions by the same constant; a penalized intercept would resist. Centre y, or leave the intercept out of \Omega.
  3. Choose \lambda by cross-validation on a logarithmic grid; consider the one-standard-error rule for a sparser, more stable model (Section 2).
  4. Pick the penalty by the goal. Need a small set of features, or interpretability? Lasso, or elastic net if features are correlated. Need the best predictions from many correlated features? Ridge. Deep network? Weight decay (AdamW with Adam), early stopping, data augmentation and dropout.
  5. Evaluate on a test set used once, after all choices are made.

10.3Common misconceptions

  • “L1 regularization is robust to outliers.” Robustness to outliers comes from the loss: the absolute error |y-\hat y| or the Huber loss grow slowly for large residuals. The L1 penalty acts on the weights, not on the residuals, and the lasso with squared error is as sensitive to outliers as least squares.
  • “Adding an L1 term to SGD gives a sparse model.” The subgradient push oscillates around zero; exact zeros need soft thresholding, as in coordinate descent or proximal gradient methods (Section 4).
  • “The lasso finds the true features.” Only under conditions on the correlations between features (Zhao and Yu, 2006); with correlated features it picks one almost arbitrarily, and the choice can change with small changes in the data (Section 6).
  • “Regularization reduces the training error.” For a problem solved exactly, such as penalized least squares, it always increases it (Pause and think in Section 2); its purpose is a lower error on new data. (In deep networks, where training is imperfect, a little weight decay can even help optimization: Krizhevsky et al. (2012) found that it lowered their network’s training error.)
  • “Weight decay and L2 regularization are the same.” Only for plain gradient descent. Under Adam and other adaptive methods they differ, which is why AdamW exists (Loshchilov and Hutter, 2019).
  • “Scaling the features does not matter.” It changes which weights are penalized most, and for the lasso which features are selected.
  • “The lasso can select as many features as it needs.” With p>n it selects at most n (Zou and Hastie, 2005).
  • “Early-stopping callbacks return the best model.” Not by default: Keras keeps the last weights unless restore_best_weights=True, and xgboost.train returns the last iteration (Keras team, 2026; XGBoost developers, 2026).
  • “Early stopping is only a heuristic.” For quadratic losses it is approximately ridge with \lambda\approx1/(2\eta\tau) (Goodfellow et al., 2016, §7.8).
  • “A larger \lambda is always safer.” Too large a \lambda underfits: in Figure 1 the validation error at \lambda=10^{2} is 0.473, almost four times the optimum.