Bias-Variance Tradeoff
Error splits into a systematic miss and sensitivity to the sample. How to measure each, and where the U-shaped curve stops applying.
Jump to a section
Two ways to miss the same curve
Fit from 20 evenly spaced points on , each with Gaussian noise of standard deviation 0.2 added. A straight line misses the curve the same way whichever noisy points it gets, because it cannot bend. A degree-15 polynomial can pass close to every point, but each new draw of noise leaves it with a different set of wiggles between them.
Those are the two failures the bias-variance decomposition separates. Bias is the error of the average prediction, averaged over many training sets drawn the same way. Variance is how far individual fits scatter around that average. Both describe the distribution of fitted models, not any single fit.
The dartboard picture is the usual shorthand. Bias is how far the cluster of shots sits from the bullseye, and variance is how spread out the shots are. A tight cluster in the wrong place is underfitting; a scattered cluster centred on the target is overfitting.
The decomposition, term by term
At a fixed test input , let , where , and . For a model fitted to a random training set independent of the test noise, expected squared error splits into three parts:
The expectation on the left runs over both the training set and the test noise. The bias and variance terms average over fitted models only. The last term is the noise variance given these input features: no model using them can beat it in expectation, though a single test error can land below it.
A small case makes the terms concrete. Suppose three equally likely training samples produce predictions 1, 2 and 3 at the same test input, and the true conditional mean there is 2.5. The mean prediction is 2, so squared bias is 0.25. Variance is . With independent test noise of variance 0.5, expected squared error is .
That variance is the spread of predictions from different fitted models at one input. It is not the spread of target values across different inputs, which is a common misreading.
Nothing in the equation forces a trade. More representative data can cut variance without adding bias, and a better feature can cut bias without adding variance. The trade-off appears when the only lever is model flexibility.
Twenty points, five degrees
Repeating the sine experiment 1,000 times, with fresh noise each time, measures every term directly. Averaged over 101 test inputs on , with a noise floor of :
| Polynomial degree | Bias² | Variance | Expected squared error |
|---|---|---|---|
| 1 | 0.207 | 0.004 | 0.251 |
| 3 | 0.005 | 0.007 | 0.053 |
| 5 | 0.000 | 0.010 | 0.050 |
| 9 | 0.000 | 0.019 | 0.059 |
| 15 | 0.000 | 0.375 | 0.415 |
Bias collapses early: by degree 5 a polynomial can follow one period of a sine almost exactly. Variance climbs steadily and then jumps. Degree 5 has the lowest error, but degrees 3 to 9 are within 0.01 of each other and within 0.02 of the noise floor, so the choice among them matters far less than avoiding either end.
Read the illustrative decomposition
Bias falls while variance rises; the total is their sum plus a constant noise floor, lowest near c ≈ 3.85.
Exact inputs and equations appear with the figure.
Preparing the scientific figure…
Illustrative analytic curves, not measurements. Noise is irreducible here. A U-shaped complexity curve is not universal.
Authored analytic exampleExperiment with related Studio inputs
Notice where the falling bias term and rising variance term give the lowest total error.
Illustrative curves, not fitted measurements. Real models can show different behavior, including double descent.
Inspect the related Studio values
x,y,series 1,4,Bias squared 1,0.035,Variance 1,0.3,Noise 1,4.335,Total 2,2,Bias squared 2,0.14,Variance 2,0.3,Noise 2,2.44,Total 3,1.3333333333333333,Bias squared 3,0.31500000000000006,Variance 3,0.3,Noise 3,1.9483333333333335,Total 4,1,Bias squared 4,0.56,Variance 4,0.3,Noise 4,1.86,Total 5,0.8,Bias squared 5,0.8750000000000001,Variance 5,0.3,Noise 5,1.9750000000000003,Total 6,0.6666666666666666,Bias squared 6,1.2600000000000002,Variance 6,0.3,Noise 6,2.2266666666666666,Total 7,0.5714285714285714,Bias squared 7,1.715,Variance 7,0.3,Noise 7,2.5864285714285713,Total 8,0.5,Bias squared 8,2.24,Variance 8,0.3,Noise 8,3.04,Total 9,0.4444444444444444,Bias squared 9,2.8350000000000004,Variance 9,0.3,Noise 9,3.5794444444444444,Total 10,0.4,Bias squared 10,3.5000000000000004,Variance 10,0.3,Noise 10,4.2,Total
The steady part of the climb has an exact formula. At the training inputs, the predictions of a least-squares fit with coefficients have variance averaging : the fit projects the noise onto a -dimensional space and keeps only that much of it. For degree 9 that is , and the simulation measures 0.0199.
The jump has no such formula. Between the training inputs a high-degree polynomial is unconstrained, and degree 15's variance halfway between neighbouring inputs is more than ten times its variance at the inputs themselves. The fit is good exactly where it was checked.
In code
The simulation behind the table. It holds the inputs fixed, redraws only the noise, and checks the result at the training inputs for every degree.
1import warnings
2
3import numpy as np
4from numpy.polynomial import polynomial as P
5
6warnings.simplefilter("ignore", np.exceptions.RankWarning) # degree 15 is ill-conditioned
7rng = np.random.default_rng(0)
8noise_sd, n, fits = 0.2, 20, 1000
9x_train = np.linspace(0, 1, n) # the same inputs for every training set
10x_test = np.linspace(0, 1, 101)
11
12
13def f(x):
14 return np.sin(2 * np.pi * x)
15
16
17results = {}
18for degree in (1, 3, 5, 9, 15):
19 test_preds, train_preds = [], []
20 for _ in range(fits): # a fresh draw of noise each time
21 y = f(x_train) + rng.normal(0, noise_sd, n)
22 coeffs = P.polyfit(x_train, y, degree)
23 test_preds.append(P.polyval(x_test, coeffs))
24 train_preds.append(P.polyval(x_train, coeffs))
25 test_preds, train_preds = np.array(test_preds), np.array(train_preds)
26 bias2 = np.mean((test_preds.mean(axis=0) - f(x_test)) ** 2)
27 variance = np.mean(test_preds.var(axis=0))
28 results[degree] = bias2 + variance + noise_sd**2
29 print(f"degree {degree:>2}: bias²={bias2:.3f} variance={variance:.3f} error={results[degree]:.3f}")
30 # At the training inputs, least-squares variance averages sigma² p / n.
31 p = degree + 1
32 assert abs(np.mean(train_preds.var(axis=0)) / (noise_sd**2 * p / n) - 1) < 0.15
33
34assert min(results, key=results.get) in (3, 5, 9)
35assert results[1] > 4 * results[5] and results[15] > 4 * results[5]What one split can tell you
In practice there is one training set, so none of those terms can be observed. What you see is a training error and a validation error, and they are clues rather than measurements. Noise, optimisation failure, distribution shift and leakage all move them too.
A single random split of the same sine problem shows the usual signatures. This version samples the inputs uniformly instead of fixing them:
1import numpy as np
2from numpy.polynomial import polynomial as P
3
4rng = np.random.default_rng(0)
5
6def true_f(x):
7 return np.sin(2 * np.pi * x)
8
9def make_data(n):
10 x = rng.uniform(0, 1, n)
11 y = true_f(x) + rng.normal(0, 0.2, n) # signal + irreducible noise
12 return x, y
13
14x_train, y_train = make_data(20)
15x_test, y_test = make_data(500)
16
17for degree in (1, 3, 9, 15):
18 coeffs = P.polyfit(x_train, y_train, degree)
19 train_mse = np.mean((P.polyval(x_train, coeffs) - y_train) ** 2)
20 test_mse = np.mean((P.polyval(x_test, coeffs) - y_test) ** 2)
21 print(f"degree {degree:>2}: train={train_mse:.3f} test={test_mse:.3f}")
22
23# degree 1: high train + high test -> underfit (high bias)
24# degree 3: low train + low test -> good fit (degree 9 tests about the same here)
25# degree 15: ~0 train + high test -> overfit (high variance)High training and validation error suggests underfitting, but an optimiser that has not converged or a high noise floor looks the same. Compare against a simple baseline and inspect the optimisation and the features before adding capacity.
Low training error with a large gap suggests overfitting, or a validation set that does not match the training data. Check the split for leakage and shift first, then try more data, stronger regularisation or less capacity.
Both errors near a credible noise floor means little reducible error is left under these conditions. Check held-out performance on the subgroups that matter before calling it done.
Cross-validation estimates generalisation under its sampling assumptions, but its folds share most of their training data. The spread of fold scores is therefore not the variance term in the decomposition.
Where the U-curve stops applying
The U-shaped curve is a pattern in this kind of experiment, not a law of model complexity. Belkin et al. showed that test error can peak near the interpolation threshold, where the model has just enough capacity to fit the training data exactly, and then fall again as capacity keeps growing. The sine experiment reaches that threshold at degree 19: twenty coefficients for twenty points, so the curve passes through every noisy value. Large neural networks train far beyond their interpolation threshold and still generalise, which the classical picture does not predict.
Other levers move one term without the other. Doubling the training set at fixed degree halves , while the bias, set by what a polynomial of that degree can represent, barely moves. Averaging models whose predictions each have variance and pairwise correlation gives variance while leaving the bias where it was. Bagging and random forests reduce variance this way, which is why random forests consider a random subset of features at each split: it decorrelates their trees.
Sources and further reading
- scikit-learn, Bias-variance decomposition example: repeated-dataset estimates of bias, variance, and noise.
- Belkin et al., Reconciling modern machine learning practice and the bias-variance trade-off: double descent and the limits of the classical U-curve.
- scikit-learn, Cross-validation: split assumptions and evaluating generalization.
Keep going
Ask your own question about Bias-Variance Tradeoff, or start a guided session on it: six short pages, from the big picture to code you can run.