How a Model Learns
Learning sounds mysterious. It is not. Drag one number, watch total error rise and fall, and find the bottom of the bowl yourself.
“The model learns from the data” is the sentence that makes machine learning sound like magic. It is not magic, and this lesson is the whole of it: pick a setting, measure how wrong you are, notice which way is downhill, take a step. Repeat.
A model with one number
Say you want to predict how much fuel a car trip will use. You have thirty-six past trips: how far each went, and how many litres it burned.
The simplest useful model is one number — litres per 100 kilometres. Pick that number and you can predict any trip: multiply, done. A 150 km trip at 8 L/100km is 12 litres.
Measuring how wrong you are
Before you can improve a guess you need to score it. For each past trip, compare what the model predicts against what actually happened. The difference is the miss.
Add up all the misses and you have a single number describing how wrong the whole model is. That number is the only thing the learning process ever looks at.
One wrinkle worth knowing now: misses are usually squared before they are added. Squaring makes every miss positive, so overshooting by two does not cancel out undershooting by two — and it makes one large miss count for more than several small ones, which is usually what you want.
The shape of being wrong
Now try it. Drag the slider to change the one number the model has, and watch two things at once: the rust sticks in the top chart, and the dot moving along the curve underneath.
Thirty-six car trips, plotted as distance driven against fuel used. The model is a single number — litres per 100 km — and the rust sticks show how far it misses each trip. Underneath, the total error at every setting you could have chosen.
6.00 litres per 100 km
Average miss
2.43How far off the line is on a typical trip, in litres.
sum of every miss ÷ 36 = 2.43 L
Total error
7.98Each miss squared, then averaged. Squaring is why one big miss hurts more than two small ones.
lowest possible = 1.98 at 7.87
Which way is downhill?
raise the number →Pulling the line up: 83.4 L · pulling it down: 4.0 L. Far from the bottom one side dominates completely. Near it they roughly balance — not exactly, because a trip four times as long pulls four times as hard.
One small step downhill would move the setting to 6.25. A real learner takes thousands of steps this small, and it is the only thing it knows how to do.
That is the whole trick
The curve underneath is the important part, and it is worth saying plainly what it is: the total error at every setting you could have picked. The dots are scattered and messy. The curve is a smooth bowl.
That smoothness is the entire reason a machine can do this without understanding anything about cars. It does not need to know what fuel is. It only needs to be able to ask “is the error smaller if I nudge this number up, or down?” and then step that way. Thousands of times, very quickly.
Real models have millions of numbers instead of one, and the bowl becomes a landscape in millions of dimensions that nobody can picture. But the move is identical, and you have now done it by hand.
Key takeaways
- A model is a setting, or a set of them. Learning means searching for good values.
- You cannot improve a guess until you can score it. That score is the total error.
- Misses are squared so they cannot cancel out, and so one big miss outweighs several small ones.
- The error landscape is smooth even when the data is not — that is what makes searching it possible.
- The best fit touches almost no points. It minimises total error, which is not the same thing.