Bias-variance tradeoff

core 12 minfundamentalsgeneralization

Builds on:Linear regression

The idea

Under squared-error loss, a model's expected prediction error at a point can be split into three pieces that add together:

E[(y−f^(x))2]=Bias[f^(x)]2+Var[f^(x)]+σ2\mathbb{E}[(y - \hat{f}(x))^2] = \text{Bias}[\hat{f}(x)]^2 + \text{Var}[\hat{f}(x)] + \sigma^2

You never observe bias and variance directly — you only ever see one fitted model and its error on one test set. What you can observe is the gap between training error and test error, and that gap is your best working proxy: a model with training error close to test error (both mediocre) is underfitting and needs more capacity; a model with training error far below test error is overfitting and needs less capacity, more data, or more regularization. Increasing model flexibility — deeper trees, more features, weaker regularization, a higher-degree polynomial — typically pushes bias down and variance up. Finding the sweet spot on that curve is what "model selection" means in practice.

Worked example

Fit polynomials of increasing degree to noisy data generated from a smooth underlying curve with irreducible noise variance σ2=0.01\sigma^2 = 0.01. Measured mean squared error on a held-out test set looks like this:

DegreeTrain MSETest MSEDiagnosis
1 (line)0.420.45high bias — both errors high and close together
30.090.11near the sweet spot — small, stable gap
90.010.35high variance — tiny train error, large gap

Reading the table the way an interviewer wants:

The shape to remember: test error traces a U as capacity increases — bias dominates the left arm, variance dominates the right arm, and the minimum sits wherever their sum is smallest.

Cheat sheet

Formula: E[(y−f^(x))2]=Bias[f^(x)]2+Var[f^(x)]+σ2\mathbb{E}[(y-\hat{f}(x))^2] = \text{Bias}[\hat{f}(x)]^2 + \text{Var}[\hat{f}(x)] + \sigma^2

SymptomTermFix
Train error high, test error ≈ train errorhigh bias / underfittingmore capacity, more features, less regularization, longer training
Train error low, test error ≫ train errorhigh variance / overfittingmore data, regularization, simpler model, bagging, early stopping, dropout
Both errors high and far apartoften a bug — check leakage, labels, preprocessing; but can be genuine: a misspecified model on noisy data, or train/test distribution shiftdebug the pipeline first, then suspect misspecification or distribution shift