Your first model

Turn a knob, watch a model's prediction change — then run the same model in real Python. No math, no install.

Updated 24 May

Your first model

A pizza-pricing machine

Imagine a tiny machine that guesses a pizza's price from its size. It has exactly one knob: how aggressively the price grows as the pizza gets bigger.

Turn the knob and watch two things move together — the line (the machine's rule) and its prediction for a 12-inch pizza. Try to land the prediction near the real price (the green ring).

size (inches)price

Drag the knob — watch the line tilt and the prediction move.

A 12-inch pizza → predicted $24 · real $15

✗ too high — the rule is too aggressive

  • Turn the knob up → the line gets steeper → prices rise faster.
  • Turn it down → the line flattens.
  • Somewhere in the middle, the line slides right through the dots — the machine's guesses match real pizzas.

That knob is the model's parameter. A model is just a rule with adjustable knobs — and you've been turning one. Written out, that's the whole definition: prediction = model(input, knobs). Once it's familiar, that gets shortened to f(x, w) — same idea, fewer letters.

Mental hooks (we reuse these all course): model = a recipe · parameter = a knob · prediction = a guess · data = real examples · training = tasting and adjusting.

Predict before you run

Commit to an answer before touching any code — guessing first is what makes it stick.

Check your understanding

1 / 2

Keep the knob fixed and make the pizza bigger. The predicted price…

Now run the exact same machine — in real Python

The knob you turned is one line of code. Here it's called slope (in math, this number is the slope — same idea, fancier name). Run it, then change slope from 2 to 5 and run again.

Python
First run loads the Python runtime (~10 MB) — takes ~5–10 seconds. Subsequent runs are instant.

Was the machine right?

A real 12-inch pizza costs about 15.Withslope=2,themachineguessed15**. With `slope = 2`, the machine guessed **24too aggressive. Turn the knob down near 1.25 and it lands on $15.

So a model can be wrong, and how wrong depends on the knob. Measuring that wrongness — and fixing it automatically — is the next two modules.

Why machine learning exists

You just tuned the knob by hand because you could see the right answer. But in real problems nobody knows the right knob in advance — there are too many knobs and too much data to eyeball.

Machine learning is the process of discovering the best knob values from data — automatically.

That's the whole game. The rest of the course is how.

What you just did

✅ Ran a model   ✅ Changed a parameter   ✅ Changed a prediction

That's machine learning. Modern AI models do the exact same thing — just with billions of knobs instead of one.

Play for two minutes

Curiosity builds intuition faster than instruction. In the code above, try:

  • slope = 0 — what does the machine predict for every pizza?
  • slope = -2 — what could a negative knob even mean?
  • size = 100 — a giant pizza.
  • slope = 1.25 — the "just right" knob. How close does it get?

Test your understanding

Prof is ready

Prof will ask you questions about what a model is: an input, a tunable parameter, and a prediction; and why we learn the parameter from data — 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).