Lesson 1 · 12 minutes · nothing to install
The smallest brain that learns
Eight taxi receipts. Two unknown numbers. By the end of this page you will have trained a model by hand, and you will know what that sentence means.
What do we actually have?
Eight receipts and no fare chart
You have taken eight taxi rides across the city and kept every receipt. Each one records two things: how far you went, and what you paid.
Nobody has given you the fare chart. But you suspect there is one, because the prices are not random — longer rides cost more, and they seem to climb steadily.
Here is the whole of machine learning in one question: can you recover the rule from the receipts alone?
What would a guess even look like?
Two dials is the whole model
Guess that the fare works the way most fares work: a fixed amount when you get in, plus a fixed amount per kilometre.
Written down, that is price = rate × km + base. Two numbers you do not know: the rate and the base fare.
That is your model. Not a metaphor for a model — that *is* one. A rule with adjustable numbers in it. Turn the two dials and watch the line move through your receipts.
Every model ever built has this shape. ChatGPT is this equation with several hundred billion dials instead of two.
How wrong am I right now?
Measure the misses, then square them
For each receipt, your line predicts a price. The real receipt says something else. The gap between them is your error on that ride.
Eight receipts, eight errors, some too high and some too low. To combine them into a single score, square each one first — squaring makes every error positive, and it punishes one terrible miss far more than several small ones.
Average the squares and you have one number describing how wrong your model currently is. That number is called the loss, and shrinking it is the entire job.
Watch the red squares. Their total area *is* the loss.
Where does a better answer live?
Every pair of dials has a height
Pick any rate and any base fare, and you get a loss. So loss is a landscape: two dials across the ground, and height above each point telling you how wrong that setting is.
For this model the landscape is a bowl, and the bottom of the bowl is the best fare chart the receipts can support.
You are standing somewhere on its side. You cannot see the whole bowl — a real model has billions of dials and nobody has ever seen its landscape. But you can always feel which way is downhill.
Which way is downhill?
This is training. There is nothing else.
At any point on the landscape you can work out, with arithmetic you already know, how steeply the loss rises if you nudge each dial. That pair of slopes is the gradient.
The gradient points straight uphill. So go the other way, a little, and both dials get slightly less wrong. Then measure again. Then step again.
Press play. What you are watching is called gradient descent, and it is what every model in the story you just watched does — the perceptron, the cheque reader, the transformer behind every chatbot.
Notice that it fixes the rate almost immediately, then spends the rest of the run inching the base fare upward. That is not a bug. The bowl is a long narrow canyon, and that shape is exactly why practitioners rescale their data before training.
How big should each step be?
Too timid crawls. Too bold explodes.
One setting decides everything: how far you move each step. It is called the learning rate, and it is the first thing anyone tunes.
Set it too small and the model creeps — technically correct, and it will still be creeping when your compute budget runs out.
Set it too large and each step overshoots the valley floor and lands higher up the far side. The next step overshoots harder. The loss climbs to infinity in a few dozen steps.
Drag the slider past the marked line and watch it happen. Every practitioner has done this by accident.
So what did I just do?
You trained a model
You started with a rule that had two unknown numbers. You measured how wrong it was. You worked out which way to turn each dial. You turned them, and repeated until the loss stopped falling.
That is training. Every term you were probably nervous about — model, parameter, loss, gradient, learning rate — you have now used for real, on numbers you could see.
The receipts came from a genuine fare rule: ₹40 to get in, ₹18 a kilometre. Compare that to what your model found. It will not be exact, and it should not be — the receipts carry noise, and a model that matched them perfectly would have learned the noise instead of the rule. That mistake has a name too, and it is the next lesson.
Do it for real
Do it again in ten lines of Python
The same eight receipts, the same descent, written out in NumPy — then swapped for a real dataset. Runs free on Colab; you need no GPU and no account beyond a Google login.
Open the notebook · 20 min →Runs on Google Colab’s free tier. We never charge you, and we never pay for your compute either — that is how this stays free.
What you now hold
Model
A model is a rule with adjustable numbers in it.
Parameter
A parameter is one of those adjustable numbers — a dial.
Prediction
A prediction is what the rule says before you check the answer.
Loss
Loss is one number saying how wrong the model currently is.
Gradient
A gradient says which way to turn each dial to make loss smaller.
Gradient descent
Turn every dial a little downhill, over and over. That is training.
Learning rate
How far you turn the dials each step — too small crawls, too big explodes.
Loss landscape
Every setting of the dials has a height; training walks downhill on that terrain.
Linear regression
Fit a straight line. The smallest model that genuinely learns.