Log inStart free
LESSON 4.15 · 6 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

L1, L2 and elastic net

Watch a penalty pull two weights toward 0, and see which ones get there.


Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 4.15 · WEIGHT BAYleast squares (2.02, 0.32) · MSE 1.31
01
Stage 1 of 6 · Least squares
Least squares picks ŵ = (2.02, 0.32): the lowest training mean squared error. Each ring joins weights with equal error.
Explain it simply

Each spot on the map is one choice of the two weights, w1 and w2. The shade shows the training error for that choice. Least squares takes the lowest spot, ŵ. Both features were scaled to the same spread first, so a penalty treats both weights fairly.

The map shows the training error over the weights w1 and w2. The lowest point is ŵ = (2.02, 0.32), with an error of 1.31. The chart shows the 12 training points; their correlation is −0.13.

data point, ρweights and penaltyerrorbest λring of equal error
training error (MSE) over the weights w1, w2−1−100112233weight w1 →w2 ↑ŵ (2.02, 0.32)the 12 training points · correlation r = −0.13−2−1012−2−1012feature x1 (standardized)feature x2smallest y = −3.38largest y = 3.89training error (MSE) over the weights w1, w2−1−100112233weight w1 →w2 ↑ŵ (2.02, 0.32)the 12 training points · correlation r = −0.13−2−1012−2−1012feature x1 (standardized)feature x2smallest y = −3.38largest y = 3.89
Toy: 12 training points · 100 validation points · 2 standardized features
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
w^=arg⁡min⁡w MSE(w),MSE(w)=1n∑i(yi−yˉ−w⋅zi)2\sy{what}{param}{\hat w} = \arg\min_{w}\ \sy{mse}{grad}{\mathrm{MSE}(w)},\quad \mathrm{MSE}(w) = \tfrac{1}{n}\textstyle\sum_i (\sy{y}{data}{y_i} - \bar y - \sy{w}{param}{w}\cdot \sy{z}{data}{z_i})^2
w^=(2.02, 0.32),MSE(w^)=1.31\hat w = (2.02,\ 0.32),\quad \mathrm{MSE}(\hat w) = 1.31

Least squares picks the weights with the lowest mean squared error.

Common mix-ups

MYTHA strong L2 penalty sets small weights to exactly 0.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01Does the L2 weight w2 reach exactly 0 at λ = 1?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.