Bias & variance

Every model that fails, fails in one of two opposite ways: it's too simple to see the pattern (bias) or so flexible it memorizes the noise (variance). Diagnosing which one you have — from two numbers — is the single most useful skill in practical ML.

overfittingunderfitting train vs test errormodel capacity

Drag the polynomial degree and watch train error (blue) and test error (red) move as the model gains flexibility — a stand-in for every "is this model too simple or too flexible?" question you'll ever ask.

Fit a polynomial — watch both errors at once

train err
test err

Two ways to be wrong

Imagine hiring two weather forecasters. The first says "32°C" every single day — winter, monsoon, doesn't matter. He's consistent but consistently wrong: his mental model is too simple for the world. That's high bias. The second memorized last year's weather to the decimal and replays it — he was perfect on last year, but this year's rain arrives a week late and he's lost. He learned the noise of one specific year, not the seasonal pattern. That's high variance.

Models are exactly these forecasters. A straight line through curvy data can't bend enough — no amount of training data fixes a shape it cannot make. A degree-15 polynomial through 20 points can bend through every single one — including the measurement errors — and the wiggles it invents between points are pure fiction. The tragedy is that the second model looks better on the data it trained on. That's why we hold out a test set: the truth only appears on data the model has never seen.

Drag the degree slider slowly and narrate what you see. At degree 0–1 both bars are tall: the model can't follow the curve for anyone — underfitting hurts train and test alike. Around degree 3–4 both bars bottom out: enough flexibility for the true shape, not enough to chase noise. Past degree 8 the blue train bar keeps shrinking toward zero while the red test bar climbs — the polynomial is now weaving through individual noisy points, and every wiggle it invents is a mistake on fresh data. Hit new random sample at high degree: the fitted curve changes wildly with each sample. That instability — the fit depending on which noisy points you happened to draw — is what "variance" literally means.

The error curve every interviewer draws

Plot train and test error against model capacity and you get the most famous picture in ML: train error only ever goes down as capacity grows (a bigger model can always memorize more), while test error is U-shaped — it falls while the model learns signal, bottoms out, then rises as the model starts learning noise. The sweet spot is the bottom of the U, and everything to the right of it is overfitting.

Error vs capacity — the U-curve, traced from the widget above

Averaged over 40 random samples per degree, so the U is smooth. Your current degree is the vertical marker.

Diagnose from two numbers

In practice you rarely plot curves — you read two numbers and act:

Train low, validation much worse (99% / 68%): variance. The gap is memorization. Cures: more data, regularization (see the Ridge/Lasso explainer), early stopping, a simpler model, dropout in deep nets.
Train and validation both bad, and close (62% / 61%): bias. There is no gap to close — the model can't even fit what it sees. Cures: more capacity, better features, less regularization. Note the cures are opposites — which is why you must diagnose before treating.

⚠️ Exam & interview trap: "more data" fixes variance, never bias. A straight line stays straight with a million more points. And "add regularization" makes an underfit model strictly worse — always ask "what's the train error?" first.
Takeaways: bias = too simple (bad at train AND test) · variance = too flexible (great at train, bad at test) · train error only falls with capacity; test error is U-shaped · diagnose from the train/val gap, then pick the cure that matches the disease — they're opposites.

Curated companion (our inspiration — different visuals, same truth): MLU-Explain — Bias & Variance.