Become the algorithm

See bad fits and good fits, watch the mistakes shrink as you tune the knob, then meet the algorithm that does the searching for you.

Updated 24 May

Become the algorithm

This line is bad — and you can see it

Here's the pizza data again, but the knob is set badly. The red bars are the machine's mistakes: the gap between each guess and the real price.

size (inches)price

Drag the knob — watch the line tilt and the red misses shrink.

total mistake: 106.0

smaller = better fit (0 would be perfect)

You didn't need a formula to know that's a bad fit — the misses are huge. Now drag the knob down and watch the red bars shrink. Stop when the line hugs the dots.

Three things happened together:

  • the line went from clearly wrong to clearly right,
  • the red mistakes shrank,
  • the total mistake number dropped toward zero.

That total mistake — every guess's miss, added up — is the most important number in machine learning. In ML it's called the loss. Smaller loss = better fit. That's the entire meaning of the word.

You've done this before. Adjusting the shower temperature. Nudging the volume. Tasting a sauce and adding salt. You try, you notice how far off you are, you adjust. That is fitting a model.

Searching for the best knob

You found a good knob by feel. Now imagine doing it methodically: try every possible slope, and for each one write down the total mistake. Some slopes predict terribly; a few fit surprisingly well. Plot the mistake for every slope and you get a landscape — high where the fit is bad, low where it's good.

Loss curve over a single weight w
learning rate η0.060
too slowconvergesovershoots

The bottom of the valley is the best knob.

Predict before you press: the ball starts on the left wall. Before you press Step — which way will it roll, and will the loss go up or down?

Now press Step a few times. The ball keeps moving toward lower loss — exactly what your hand was doing a minute ago. Press Run to let it search on its own.

You searched by hand; the ball searches automatically. That automatic search has a name: gradient descent. (The name comes last — you already understand the thing it names.)

How big a step? (the learning rate)

The learning rate — the η slider — sets how big each step is.

  • Tiny → cautious baby steps; correct, but slow.
  • Just right → a smooth slide to the bottom.
  • Too big → it leaps clear across the valley and overshoots.

Challenge: can you find a learning rate where the ball never settles — bouncing across the valley forever?

And notice: near the bottom the steps get tiny and it reads Converged ✓. Close to a good answer, progress naturally slows.

So what is "training"?

No magic. Training a model is four steps on repeat:

  1. Make a prediction.
  2. Measure the mistake (the loss).
  3. Adjust the knobs a little to lower it.
  4. Repeat.

That's it — and it's one of the most important intuitions in all of ML. Every model in this course, and every model at OpenAI or Google, is doing exactly this, just with more knobs.

The one piece we hand-waved: how does the algorithm know which way is downhill without trying both directions? That's the next module — and it's just slope.

Test your understanding

Prof is ready

Prof will ask you questions about judging a model's fit (loss) and searching for the parameter that fits best; gradient descent as automated search — not explain it. You'll be surprised what you don't know until you have to say it.

Finished this lesson?

Read through the lesson first (0/20s).