Why does adding a penalty to the loss function improve model generalization?

Last updated 3 November 2026

A penalty makes the optimizer trade a little training fit for simpler parameters. Simpler models are less able to memorize noise in the training set, so their variance drops more than their bias rises, and test error falls.

  • Constrains the hypothesis space:

    • Minimizing loss + λ·Ω(w) is equivalent to minimizing loss subject to Ω(w) ≤ t. The model can only use a smaller set of functions.

    • Large weights let a model produce sharp, wiggly functions that fit individual noisy points. Small weights force smoother functions.

  • Bias-variance trade-off:

    • Shrinkage adds some bias, but it greatly reduces how much the fitted model changes across different training samples (variance).

    • When the model is flexible relative to the amount of data, the drop in variance dominates, so expected test error goes down.

  • Bayesian view: The penalty acts as a prior: L2 corresponds to a Gaussian prior and L1 to a Laplace prior. The result is a MAP estimate that encodes the belief that weights should be small.

  • Numerical stability: L2 makes XᵀX + λI invertible. This stabilizes estimates when features are collinear or when there are more features than samples (p > n).

  • Caveat: it only helps when λ is tuned, for example by cross-validation. Too large a λ causes underfitting.

  • https://www.geeksforgeeks.org/machine-learning/machine-learning-interview-questions/
  • https://blog.stackademic.com/crack-ml-interviews-with-confidence-regularization-20-q-a-ae23b2c7c2a8
  • https://pub.towardsai.net/crack-ml-interviews-with-confidence-regularization-20-q-a-1378ef4de2eb
All Regularization interview questions