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

Quick Overview

Asks why adding a penalty term such as L1 or L2 to a training loss usually lowers test error. Tests whether you can explain the constrained hypothesis space, the bias-variance trade-off, the Bayesian prior view, and how the penalty strength is tuned.

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

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: easy

Interview Round: Other

Why does adding a penalty to the loss function improve model generalization? Take a penalty such as an L1 or L2 term on the weights, added to the training loss with a strength $\lambda$. Explain why the model trained this way often does better on new data even though it fits the training data less closely. ```hint Look at what large weights allow What kind of function can a model with very large weights fit through noisy points? Then think about what a penalty does to the bias and the variance of the fitted model. ``` ### What a Strong Answer Covers - How the penalty restricts the set of functions the model can fit, including the equivalent constrained-optimization view. - The bias-variance argument for why test error can fall while training error rises. - At least one other interpretation, such as the Bayesian prior view or the numerical stability of ridge regression. - How the penalty strength is chosen, and what happens when it is too large or too small. ### Follow-up Questions - Why does an L1 penalty set some weights exactly to zero while L2 does not? - Why should features be standardized before fitting a penalized linear model? - Is an L2 penalty in the loss the same as weight decay when training with Adam? - With far more training data than parameters, would you still expect a penalty to help?

Overview: Asks why adding a penalty term such as L1 or L2 to a training loss usually lowers test error. Tests whether you can explain the constrained hypothesis space, the bias-variance trade-off, the Bayesian prior view, and how the penalty strength is tuned.

PracHub logo
General
Nov 24, 2026
easyMachine Learning EngineerOtherMachine Learning
0
0

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

Take a penalty such as an L1 or L2 term on the weights, added to the training loss with a strength λ\lambda. Explain why the model trained this way often does better on new data even though it fits the training data less closely.

What a Strong Answer Covers Guidance

  • How the penalty restricts the set of functions the model can fit, including the equivalent constrained-optimization view.
  • The bias-variance argument for why test error can fall while training error rises.
  • At least one other interpretation, such as the Bayesian prior view or the numerical stability of ridge regression.
  • How the penalty strength is chosen, and what happens when it is too large or too small.

Follow-up Questions Guidance

  • Why does an L1 penalty set some weights exactly to zero while L2 does not?
  • Why should features be standardized before fitting a penalized linear model?
  • Is an L2 penalty in the loss the same as weight decay when training with Adam?
  • With far more training data than parameters, would you still expect a penalty to help?