← Pinterest Interview Insights
I knew the answer lived somewhere in the geometry of the penalty terms but I started rambling about sparsity before actually explaining the 'why'.
Explain the geometric and mathematical reasons behind L1 producing sparse solutions while L2 does not. Start with the optimization objective, then contrast the shape of the constraint regions and the behavior of gradients near zero. Conclude with practical implications for feature selection and model interpretability.
Pro tip: Mention that L1's sparsity is not just due to the diamond shape but also because the subgradient at zero includes zero, allowing exact zeros, whereas L2's gradient at zero is zero but the solution is rarely exactly zero due to the smoothness of the penalty. This shows deep understanding beyond the typical geometric explanation.
Write the regularized loss function: L1 adds λ∑|w_i|, L2 adds λ∑w_i^2. Explain that both aim to minimize loss while keeping weights small.
Describe the constraint region: L1 is a diamond (or polytope) with corners on axes, L2 is a circle. The loss contours often touch the diamond at corners, where some weights are exactly zero.
For L1, the gradient of the penalty is λ sign(w), which is constant magnitude for non-zero w and undefined at zero (subgradient includes zero). For L2, gradient is 2λw, which goes to zero as w→0. Thus L1 can push weights to exactly zero, while L2 only shrinks them.
Explain that L1's ability to zero out weights leads to sparse models and automatic feature selection, while L2 results in dense models with small but non-zero weights.
Mention when to use each: L1 for interpretability and high-dimensional data, L2 for preventing overfitting when all features are useful, and Elastic Net for combining both.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.