Part IV — Supervised Learning: Regression & Linear Classifiers · Chapter 4

Lasso regression (L1 regularization)

Hook

Ridge regression shrinks correlated predictors toward each other, but it never drops one entirely — no matter how large the penalty, both weights stay some nonzero decimal. What would it take for a regularizer to actually decide "this predictor isn't worth keeping" and set its weight to exactly zero?

Intuition

Same two nearly-identical predictors as the ridge chapter. Push λ up and, past a small threshold, w2w_2 doesn't just shrink toward zero the way ridge's would — it lands exactly on it and stays there.

Formalize

Lasso swaps ridge's squared penalty for an absolute-value one:

MSE(w)+λjwj\text{MSE}(\mathbf{w}) + \lambda \sum_j |w_j|
  • MSE(w\mathbf{w}) — mean squared error (lasso conventionally penalizes the averaged error, not the raw sum ridge uses — so the same numeric λ lands at a different effective strength for each).
  • λ\lambda — the penalty strength, same role as in ridge.
  • wj|w_j| — the absolute value of the jj-th weight — the source of everything that follows.

Unlike ridge, this loss has no closed form — it's minimized by cyclic coordinate descent: repeatedly pick one weight, hold the others fixed, and solve for it via soft-thresholding, soft(ρ,γ)=sign(ρ)max(ργ,0)\text{soft}(\rho, \gamma) = \text{sign}(\rho)\max(|\rho|-\gamma, 0).

  1. A squared penalty is smooth at zero; an absolute-value one has a corner

    w2w^2 has zero slope at w=0w=0, so shrinking a weight that's already small barely pulls it further. w|w| has a constant-slope kink at w=0w=0 — that corner is what a coordinate update can land exactly on.

  2. Soft-thresholding is the algebraic form of that corner

    Solving the 1D optimality condition for one weight at a time gives exactly the soft-threshold rule: if the weight's "signal" ρ\rho is smaller in magnitude than γ\gamma, the optimal weight is precisely 00 — not close to it.

  3. Correlated predictors can make lasso's choice unstable

    When two predictors carry almost the same signal, which one gets zeroed can depend on arbitrary details like update order — a real quirk of lasso under collinearity, and the reason ElasticNet exists (next chapter).

Play

Same λ, fed to both penalties on the same data. Lasso routinely shows a flat 0.0000.000 for w2w_2; ridge, right below it, never does — its w2w_2 is always some nonzero decimal, however small.

Worked example

Same toy setup as ridge: x1=[1,2,3,4]x_1=[1,2,3,4], x2=[1,2,3,4.5]x_2=[1,2,3,4.5] (correlation 0.998\approx 0.998), y=[2,4,7,8]y=[2,4,7,8].

  1. Unregularized, lasso agrees with OLS

    At λ=0\lambda=0, coordinate descent converges to the same unstable fit as before: w13.929w_1\approx3.929, w21.714w_2\approx-1.714.

  2. A tiny penalty already zeroes w2 (λ = 0.03)

    The soft-threshold cutoff is γ=Nλ=4(0.03)=0.12\gamma=N\lambda=4(0.03)=0.12. Starting from w1=w2=0w_1=w_2=0:

    1. ρ1=ix1iyi=63\rho_1=\sum_i x_{1i}y_i=63 (since w2=0w_2=0), so w1=soft(63,0.12)/30=(630.12)/302.096w_1=\text{soft}(63,0.12)/30=(63-0.12)/30\approx2.096
    2. ρ2=ix2i(yiw1x1i)0.072\rho_2 = \sum_i x_{2i}(y_i-w_1x_{1i}) \approx -0.072 — inside the dead zone [0.12,0.12][-0.12,0.12], so w2=0w_2=0 exactly

    Plugging w2=0w_2=0 back into step 1 reproduces the same ρ1\rho_1, so this is already the fixed point — w12.096w_1\approx2.096 absorbs essentially the whole fit.

  3. It stays exactly zero across a wide range (λ = 0.5)

    The cutoff is now γ=4(0.5)=2\gamma=4(0.5)=2 — much wider. Starting from w1=w2=0w_1=w_2=0:

    1. ρ1=63\rho_1=63, so w1=soft(63,2)/30=(632)/302.033w_1=\text{soft}(63,2)/30=(63-2)/30\approx2.033
    2. ρ21.933\rho_2 \approx 1.933 — still inside the wider dead zone [2,2][-2,2], so w2=0w_2=0

    Again a fixed point immediately: lasso has picked predictor 1 and permanently discarded predictor 2, a form of automatic feature selection ridge structurally cannot do.

Checkpoint

Increase λ until w₂ drops to exactly zero.

Move the λ slider to try it
Summary
MSE(w)+λjwj\text{MSE}(\mathbf{w}) + \lambda \sum_j |w_j|

Lasso's wj|w_j| penalty has a corner at zero that ridge's smooth wj2w_j^2 doesn't — and coordinate-wise optimization tends to land exactly on that corner. The result is automatic feature selection: past a threshold λ, a weak predictor's weight isn't just small, it's exactly 00.