KatInterview

Why L1 Regularization Zeros Out Coefficients but L2 Does Not

Machine LearningModel answer
MediumModel answerMachine Learningregularizationlassoridge

Last updated

Compare Lasso and Ridge penalties on a 500-feature regression model, explaining mathematically and geometrically why one produces sparse weights and the other does not.

Predicting Sensor Failures with 500 Candidate Features

Your team is building a linear regression model to forecast equipment degradation scores from 500 candidate sensor readings. You have three modeling options on the table: plain Ordinary Least Squares (OLS), Lasso (L1 penalty), and Ridge (L2 penalty).

A colleague claims that both penalties simply "shrink the weights" and that the choice between them is mostly cosmetic. Your job is to explain why that characterization is wrong, and what actually differs between the two approaches.

Address the following in your answer:

  1. Write out the two penalized objective functions and identify what is structurally different about the penalty terms:

    • Lasso: RSS(w) + λ · ||w||₁
    • Ridge: RSS(w) + λ · ||w||₂²
  2. Explain why Lasso can set individual coefficients to exactly zero, while Ridge only shrinks them toward zero without ever reaching it. Ground your explanation in the behavior of the gradient (or subgradient) of each penalty at w_j = 0, and in the geometry of the corresponding constraint regions.

  3. Discuss what sparsity does and does not give you when the 500 input features are noisy sensor readings that may be correlated with each other.

Assumptions and setup

  • w is the vector of model coefficients.
  • λ > 0 is the regularization strength.
  • You may use the orthonormal design case (XᵀX = I) to derive closed-form solutions for each penalty, then generalize your reasoning to the full case.
  • Treat the constraint-region form (budget t, where ||w||₁ ≤ t or ||w||₂² ≤ t) as equivalent to the penalized form via Lagrangian duality.

Hints

Hint 1

Start with the orthonormal design simplification (XᵀX = I). Under this assumption the objective separates into one independent scalar problem per coefficient. Solve each one — you will get Ridge's closed form first, then Lasso's soft-thresholding operator. The two solutions look very different, and that difference is the core of your answer.

Hint 2

For the general case, ask what happens at the point w_j = 0. The L2 penalty's derivative there is 2λ·0 = 0, so it exerts no restoring force at the origin. The L1 penalty is not differentiable at 0 — its subgradient is the entire interval [−λ, λ]. Write the optimality condition for each and identify when zero is a valid solution.

Hint 3

For the geometric argument, think about what the constraint region looks like in two dimensions and then reason about what changes in 500 dimensions. The L1 ball has corners and flat faces aligned with the coordinate axes. Ask yourself: when an elliptical RSS contour expands outward from the OLS solution, where is it most likely to make first contact with each shape?