Why does an L1 penalty give sparse weights while L2 shrinks them smoothly? When would you choose each, and what does elastic net add?
Answer
Model answer, written in a candidate's voice
In short
- Geometry: L1’s diamond constraint has corners on the axes, so the optimum often lands at zero; L2’s ball constraint is smooth and rarely touches an axis exactly.
- Subgradient: L1 applies a roughly constant pull towards zero, while L2’s pull is proportional to the weight, so small weights shrink slowly and large weights are pulled harder.
- Bayesian view: L1 is MAP with a Laplace prior, L2 with a Gaussian prior.
- Use cases: L1 for feature selection and sparse high-dimensional problems; L2 for correlated features, stability, and shrinkage without hard zeros.
- Elastic net mixes L1 and L2, keeps correlated feature groups together, and is more stable than pure L1.
- Standardise features before penalising: both penalties are scale-dependent.
In full
The core difference is geometry: an L1 penalty constrains weights to a diamond whose corners sit on the axes, so the constrained optimum often lands exactly on an axis and that weight becomes zero, while an L2 penalty constrains weights to a ball, which is smooth and shrinks weights towards zero without usually forcing exact zeros. In subgradient terms, L1 applies a roughly constant pull towards zero, so once a weight is small enough it can be pushed all the way to zero, whereas L2’s pull is proportional to the weight, so every weight is shrunk but none is typically set exactly to zero. In Bayesian terms, L1 corresponds to a Laplace prior and L2 to a Gaussian prior under MAP estimation. I would choose L1 when I want feature selection or a sparse model in high-dimensional data, and L2 when features are correlated or I want stable shrinkage without hard zeros. Elastic net adds both penalties, so it keeps the sparsity and selection behaviour of L1 while using L2 to stabilise correlated groups and reduce the instability of pure L1. In every case I standardise features first, because both penalties depend on the scale of each coefficient.
What a strong answer covers
- Geometry: the L1 diamond has corners on the axes, so the constrained optimum often lands at zero; L2 is a ball.
- Subgradient view: L1 applies a constant pull towards zero; L2’s pull is proportional to the weight.
- Bayesian view: Laplace vs Gaussian prior (MAP).
- Use cases: L1 for feature selection or high-dimensional sparse data; L2 for correlated features and stability.
- Elastic net mixes the two, handles groups of correlated features, and is more stable than pure L1.
Common mistakes
- saying L2 sets weights to zero
- forgetting to standardise features before penalising.