← capítulo

Overfitting and the bias-variance tradeoff

Every model has a flexibility knob. Turn it up and training error keeps falling — but test error falls, bottoms out, and climbs back. That U is the most important picture in supervised learning.

The three fits, one dataset

A straight line can't bend (bias). A degree-11 curve chases the noise (variance). Degree 5 finds the sine.

The decomposition

Expected squared error splits into three pieces:

E[(yf^(x))2]=(E[f^(x)]f(x))2+E[(f^(x)E[f^(x)])2]+σ2\mathbb{E}\big[(y - \hat{f}(x))^2\big] = \big(\mathbb{E}[\hat{f}(x)] - f(x)\big)^2 + \mathbb{E}\big[(\hat{f}(x) - \mathbb{E}[\hat{f}(x)])^2\big] + \sigma^2

Total error is their sum. The sweet spot minimizes the sum, not either alone.

Watch the U form

One real refit per frame, degree 1 → 11. Fit tightens up top; test error carves its U down below.

Train MSE slides to 0.038; test MSE bottoms at 0.061 (degree 5) then climbs to 0.817 (degree 11) — target units².

Bias falls, variance rises, they cross

Bias² 0.123 → 0.003. Variance 0.012 → 1.602. They cross near degree 4; total error is the U.

The cost of the wrong degree

Degree 11 scores 0.817 vs. the sweet spot's 0.061 — 13× the error — yet looks better on training data. Judge on held-out data or ship the worse model.

Takeaways