Lessons › Chapter 5: Generalization
Bias and variance
Train the same kind of model on different samples of data and each version guesses a little differently. Picture each guess as a dart. The bullseye is the true answer. Ideally the darts land tight and centered.
Watch it move. This lesson is interactive on Gradient Lab: every step is an animated scene you can replay.
Start the interactive lessonStep by step
Stubborn or jumpy?
Leo has two models. One predicts nearly the same thing every time; the other changes wildly with each retrain.
The dartboard picture
Train the same kind of model on different samples of data and each version guesses a little differently. Picture each guess as a dart. The bullseye is the true answer. Ideally the darts land tight and centered.
High bias: wrong the same way
A too-simple model makes the same mistake every time: a tight group in the wrong place. That is high bias, and it’s what underfitting looks like.
High variance: all over the place
A too-flexible model changes a lot depending on which data it saw. Its darts are centered on average, but scattered everywhere. That is high variance, and it’s what overfitting looks like.
The trade-off
Make a model more flexible and bias falls while variance rises. Total error is lowest somewhere in the middle. Finding that sweet spot is a big part of a data scientist’s job.
In real life: two weather forecasters
One forecaster always says “mild, 20°C”: steady, but often wrong (high bias). Another changes their forecast wildly at every tiny change in the data (high variance). Good forecasting models sit in between.
Quick check: A model gives very different answers every time you retrain it on a new sample. It has high…
- Bias
- Variance (correct)
- Accuracy
Scattered results that depend on the exact training data are the sign of high variance.
Pseudocode
# imagine training the same model on many different samples
for each sample of data:
model = train(sample)
record its guess for one test point
bias = how far the average guess is from the truth
variance = how much the guesses scatter
total error ≈ bias² + variance + noise
Key terms
- bias
- Being wrong in the same direction every time, usually because the model is too simple.
- variance
- How spread out numbers are: the average squared distance from the mean.