2.2.13 · D2Linear & Logistic Regression

Visual walkthrough — L1 (Lasso) regularization

1,771 words8 min readBack to topic

We derive the soft-thresholding rule from absolute zero.


Step 1 — Draw the two costs we are balancing

WHAT. We have a single number we are allowed to choose (one feature's weight). Two things pull on it:

  • a data-fit cost that wants near a special number ,
  • a penalty cost that wants near .

WHY start with one weight? In the simplest setting (features that don't interfere — orthonormal features), every weight optimizes on its own. So mastering one is mastering the whole problem. That is exactly the value would take with no penalty — the plain least-squares answer.

PICTURE. Two chalk curves. The data-fit cost is a parabola (a valley) centred at : pull toward . The penalty cost is a V-shape centred at : pull toward .

Figure — L1 (Lasso) regularization

Step 2 — Add the curves: the total cost has a KINK

WHAT. The thing we actually minimize is the sum of the parabola and the V. We add them pointwise to get one total-cost curve.

WHY does the shape matter? A smooth valley has a smooth bottom you find by "slope ". But the V has a sharp point at . When we add a V to a parabola, that sharp point can survive and become the lowest point of the whole thing. A sharp lowest point sitting exactly at is the entire secret of Lasso.

PICTURE. Three curves stacked: the parabola (blue), the V (pink), and their sum (yellow). Notice the yellow sum still has a corner at — the V's kink pokes through.

Figure — L1 (Lasso) regularization

Step 3 — Slope hunting on the right side ()

WHAT. Assume for now . Then (absolute value of a positive number is itself), so the penalty is just , which is smooth. Take the slope and set it to zero.

WHY the slope tool? The derivative answers exactly one question: "at this , is the cost still going down?" The minimum of a smooth valley is where the cost stops falling — slope . We use it because on the region there is no kink to worry about.

  • ::: how far right of the valley bottom we are; pulls back left.
  • ::: the penalty's constant rightward-pull that shifts the answer.

The catch: we assumed . The answer is only allowed if , i.e. . If isn't that big, this solution is a lie and we discard it.

PICTURE. The parabola's bottom sits at ; adding the penalty slides the true minimum left by exactly , landing at — but only when that point is still positive.

Figure — L1 (Lasso) regularization

Step 4 — Slope hunting on the left side ()

WHAT. Now assume . Then (absolute value flips the sign of a negative), so the penalty is and its slope is .

WHY redo it? Absolute value is a different function on each side of zero. Honesty demands we check both. This is the mirror image of Step 3.

  • ::: now the penalty pulls rightward (toward zero from the left).

The catch: valid only if , i.e. . If is not negative enough, discard.

PICTURE. Mirror of Step 3: valley bottom at negative , penalty slides the minimum right by to , valid only while it stays negative.

Figure — L1 (Lasso) regularization

Step 5 — The trapped case:

WHAT. What if is small — between and ? Then Step 3 wanted (false) and Step 4 wanted (false). Neither smooth solution is allowed. The minimum has nowhere to go but the kink: .

WHY does it get stuck at zero? At the kink the "slope" isn't a single number — it's a whole range (the subgradient): anything from to . The minimum sits at the kink whenever the parabola's pull there, which is , is small enough to be cancelled by some slope in that range. That condition is precisely .

PICTURE. For small , both one-sided walks (left and right of ) go uphill. The bottom of the yellow total-cost curve is the sharp corner sitting right on .

Figure — L1 (Lasso) regularization

Step 6 — Stitch the three cases into one formula

WHAT. Collect all three regions into a single rule.

Region Winner Result
Step 3
Step 4
Step 5

WHY one formula? All three lines say the same thing: move toward by , but never past . That's captured by:

  • ::: if , if — remembers which side we came from.
  • ::: the shrink: pull the magnitude in by .
  • ::: the clamp: if shrinking would cross zero, stop at zero.

PICTURE. The soft-threshold graph: input (x-axis) vs output (y-axis). A flat dead-zone pinned to , and two 45° lines offset by outside it. Overlaid: Ridge's line through the origin that never flattens.

Figure — L1 (Lasso) regularization

Step 7 — Why the geometry agrees: diamond corners

WHAT. The penalized problem is equivalent to "minimize the data-fit cost while keeping " for some budget . In 2-D that budget region is a diamond (rotated square). Ridge's budget is a circle.

WHY does shape decide sparsity? The data-fit cost has oval contours (level sets of constant error). The solution is where the smallest oval first kisses the budget region. A diamond has sharp corners sitting on the axes — and a corner on the -axis means . Ovals reach out and touch a corner very easily. A circle is smooth: the touch point almost never lands exactly on an axis.

PICTURE. Left: blue diamond, pink ovals, first contact at a corner. Right: blue circle, ovals touch on a smooth edge ⇒ both weights nonzero.

Figure — L1 (Lasso) regularization

The one-picture summary

WHAT. One figure compressing the whole story: the total-cost curve for three values of (big positive → shrunk, small → zeroed, negative → sign-kept), with arrows showing where each minimum lands, and the soft-threshold map beside it.

Figure — L1 (Lasso) regularization
Recall Feynman retelling — the whole walkthrough in plain words

You have one dial, . A spring pulls it toward (the answer with no rules). A second, constant-strength rubber band pulls it toward . If is far from zero, the rubber band just drags the dial a fixed amount closer to zero — that's shrinkage. But if is already close to zero (within ), the rubber band wins completely and snaps the dial to exactly — the feature is deleted. Add a second dial and this "snap to zero" becomes the sharp corner of a diamond that the error-ovals love to land on. That corner-love is Lasso's whole magic: it doesn't just shrink weights, it deletes the small ones, leaving a short, honest model.

Recall Where do the three regions come from?

is a different smooth function on each side of , giving two "slope " answers ( and ), each valid only on its own side. When neither is valid — — the minimum is trapped at the non-differentiable kink .

Compare with Elastic Net when features are correlated, and note the same corner mechanism works for Logistic Regression with an L1 penalty — the kink is in the penalty, not the loss.