5.6.3 · D2Machine Learning (Aerospace Applications)

Visual walkthrough — Regularization — L1 (lasso), L2 (ridge), dropout

2,774 words13 min readBack to topic

This page rebuilds the single most important picture in regularization from nothing: why does the diamond-shaped penalty (L1) snap weights to exactly zero, while the round penalty (L2) only makes them smaller? We assume you have never seen a contour, a norm, or a gradient. We build each one, in order, on a picture.


Step 1 — Two knobs, and what "the loss" even is

WHAT. Our model has just two adjustable numbers, the weights and . Think of them as two dials. Every possible pair is a single point on a flat sheet of paper — the horizontal axis is , the vertical axis is .

WHY. Before we can talk about penalties or shapes, we need a stage to draw them on. That stage is the plane of all possible weight choices. We use two weights (not one, not fifty) purely because a plane is the largest thing we can honestly draw.

PICTURE. Look at the figure: the sheet is the space of choices. One dot is marked — that is one particular model, say .

Figure — Regularization — L1 (lasso), L2 (ridge), dropout

Step 2 — The data loss is a bowl; its shadow is a nest of ellipses

WHAT. For each choice there is a number: how badly the model fits the training data. Call it . Small = good fit. If we plot that number upward out of the sheet, we get a bowl — low in one spot (the best fit) and rising as we move away.

WHY. The parent note wrote the data loss as an average of per-example errors,

Let us define every symbol here, on this page:

  • ::: the true target of training example (e.g. the measured drag).
  • ::: the model's prediction for that example — for our linear model , so it depends on the dials.
  • ::: the per-example loss, a number saying how far one prediction missed; we use the squared miss .
  • ::: average that miss over all training examples.

Because is linear in , a squared miss is a quadratic in the dials, and a quadratic in two variables is always a bowl (a paraboloid). We need this shape because it hands us the one tool that decodes the picture: contour lines.

PICTURE. We slice the bowl at equal heights and drop the slices flat onto the sheet. Each slice is an ellipse — a ring of "equally-bad" models. The tiny centre dot is the unconstrained best fit (bottom of the bowl).

Figure — Regularization — L1 (lasso), L2 (ridge), dropout

Here is just a constant level value we pick — "show me every dial-setting whose badness equals exactly ." Sweep upward and you get the whole nest of rings.

Why an ellipse and not a circle? Because the data usually pins down one combination of dials more tightly than another, so the bowl is steeper along one direction in weight space and flatter along another. A steeper direction means loss rises fast (a squashed ring); a flatter direction rises slowly (a stretched ring). A lopsided bowl gives lopsided rings — that is all "ellipse" means here.


Step 3 — "Dislike big weights" needs a ruler: the norm

WHAT. We now add a second wish: keep the weights small. To keep something small we must measure its size. A rule that turns a pair into a single "size" number is called a norm.

WHY. We cannot penalize bigness without first defining bigness — and there is more than one honest way to measure it. That choice of ruler is exactly what separates L1 from L2. So we introduce two rulers side by side.

PICTURE. Two rulers, two shapes of "all points of size 1":

  • The L2 ruler (straight-line distance from the origin): . All points at distance form a circle.
  • The L1 ruler (add up the sideways + up moves, like walking city blocks): . All points of size form a diamond.
Figure — Regularization — L1 (lasso), L2 (ridge), dropout

Term-by-term: the L2 ruler is Pythagoras (a straight flight). The L1 ruler forbids diagonals — you must move along the axes, so a diagonal costs more. That extra cost on diagonals is precisely what pushes the diamond's corners onto the axes.


Step 4 — The constraint view: a fence around the origin

WHAT. There are two equivalent ways to say "keep weights small." One: add a penalty to the loss (the parent note's view, where = regularization strength). The equivalent, easier-to-draw way: forbid the weights from leaving a fenced region of size around the origin. Formally, minimise subject to .

WHY. The penalty view lives up out of the page (it adds a bump to the bowl's height). The fence view lives flat on the page (a region you may not leave). Flat is drawable, so we pick it.

Why the two views are the same trade-off (intuitive sketch). Suppose the constrained answer lands on the fence (it does, whenever is outside). At that touching point the two views must agree on the balance between "fit better" and "stay small." Push the fence outward a little (raise ): you are allowed slightly bigger weights, so you can fit a little better — exactly what lowering the penalty lets you do. Shrink the fence (lower ): you must accept a worse fit for smaller weights — exactly what raising forces. So there is a monotone pairing:

PICTURE. Draw the fence for each ruler:

  • L2 fence = a filled disc of radius .
  • L1 fence = a filled diamond with corners at and .

The best fit sits outside both fences (that is why we needed regularization). So we cannot sit at ; we must find the best allowed point touching the fence.

Figure — Regularization — L1 (lasso), L2 (ridge), dropout
  • ::: search over all dial-settings.
  • ::: the allowed region — inside or on the fence only.

Step 5 — Where an ellipse first kisses the fence

WHAT. Start the ellipses tiny at and let them grow outward. The first place a growing ellipse touches the fence is our answer: it is the lowest-loss point we are still allowed to occupy.

WHY. Growing the ellipse = accepting more data-error. We want the least extra error, so we stop the instant we reach the fence. Whichever point the ellipse touches first is the constrained solution — no picture-free algebra needed.

PICTURE (L2, the circle). The ellipse rolls out and first grazes the round fence at a point on its smooth edge. Nothing special happens there: both and are generally nonzero, just smaller than at . Round fence → smooth touch → shrunk, but nonzero.

Figure — Regularization — L1 (lasso), L2 (ridge), dropout

Step 6 — The diamond kisses at a corner → an exact zero

WHAT. Repeat Step 5 with the diamond fence. Now the growing ellipse almost always meets the diamond at one of its sharp corners — and a corner of the L1 diamond lies exactly on an axis, where one weight is precisely .

WHY. A corner sticks out furthest toward the origin's incoming ellipses. An ellipse sweeping in from the outside reaches that protruding corner before it reaches the flat sides. This is a geometric fact about pointy shapes, not luck. And the corners of are the four points — each has a coordinate equal to zero.

PICTURE. The ellipse touches the top corner : there exactly. The model drops dial 1 completely — automatic feature selection, live, in one picture.

Figure — Regularization — L1 (lasso), L2 (ridge), dropout

The same corner-snapping shows up algebraically as a soft-threshold rule when we optimise by gradient descent. We do not need it to see the zero — the picture already gave it — but it is worth naming, and it needs one new symbol:

Here is the rule, derived in the parent note's L1 section (we only quote and read it):

Contrast the L2 rule : that multiplies by a factor just under , so — like halving repeatedly — it scales toward zero but never lands on it. Round fence, round rule, no exact zeros.


Step 7 — The degenerate & edge cases (nothing left unshown)

We must cover the corners the reader could hit. Each gets its own panel in the figure.

Case A — (no fence). The fence has infinite size ( suffices); the ellipse sits happily at . No shrinkage. Overfitting risk returns.

Case B — (fence shrinks to a dot). : the only allowed point is the origin. Both weights are zero — the model predicts a constant. Useless, as the parent warned.

Case C — the ellipse touches an L1 edge, not a corner. It can happen: if the loss ellipses are aligned just right, the first touch is on a flat side, giving two nonzero weights. So L1 does not guarantee zeros — it makes them overwhelmingly likely, because corners are reached first from almost every direction.

Case D — exactly, where has a kink. The absolute-value ruler has no single slope at (a sharp "V"). We handle it with the subgradient: any slope between and is allowed there. That undefined slope is exactly what lets a weight rest at zero instead of being pushed off it — a feature, not a bug.

Figure — Regularization — L1 (lasso), L2 (ridge), dropout

The one-picture summary

Figure — Regularization — L1 (lasso), L2 (ridge), dropout

The final figure lays the two fences side by side under the same incoming ellipses:

  • Left (L2, circle): smooth touch, both weights shrunk, neither zero → weight decay.
  • Right (L1, diamond): corner touch on the axis, one weight exactly zero → sparse selection.

Same loss, same -sized fence — only the shape of the ruler changed, and that shape decided everything.

Recall Feynman retelling — say it to a 12-year-old

You have two dials and you want the machine to guess flight fuel well. Some dial settings guess well, some badly; draw that on paper as rings — inner rings are good guesses, outer rings bad. The best guess is a dot, but that dot uses huge, twitchy dials that break on new flights. So we draw a fence around the safe middle and say "you must stay inside." Now let the good-guess rings grow until one touches the fence — that touch is your answer. If the fence is a circle, the ring touches somewhere smooth and both dials come out small-but-on. If the fence is a diamond, the ring almost always hits a pointy corner, and those corners sit right on the lines where one dial is turned completely OFF. That is why the diamond ruler (L1) throws away useless dials, and the round ruler (L2) just turns everyone down a notch. Turn the fence tiny and both dials die; remove the fence and you're back to twitchy overfitting. Choosing the fence size is the only real decision.

Recall

What does the round (L2) fence do to the weights? ::: Shrinks both toward zero smoothly, but rarely to exactly zero (weight decay). Why does the diamond (L1) fence produce exact zeros? ::: Its corners lie on the axes, and a growing loss-ellipse touches a corner first from almost any direction, forcing a weight to be exactly 0. What is in these pictures? ::: The unconstrained best fit — the bottom of the data-loss bowl, centre of the ellipses. What does a larger mean in the fence picture? ::: A smaller fence — a tighter constraint that shrinks weights more. What is in the soft-threshold rule? ::: The learning rate — the step size gradient descent takes each update. Give one case where L1 fails to zero anything. ::: When the ellipses touch a flat edge of the diamond instead of a corner, both weights stay nonzero (Case C).


Prerequisite & neighbour links: Gradient Descent Variants (the update rules whose geometry we drew), Feature Engineering (L1's automatic selection), Overfitting Detection (why we fence at all), Ensemble Methods and Neural Network Architectures (dropout as an ensemble of sub-networks), Bayesian Inference (penalties as priors), and pick via Cross-Validation.