What is a model?

AI from scratch · 1 of a series

What is a model?: lesson transcript

1. Twelve days at a café

A café keeps a note of the temperature each day and how many cold drinks it sells. Twelve days in, a pattern shows up. Tomorrow will be 30°: how many should they stock?

2. Draw a rule

One way to answer: draw a straight line through the points and read off where it sits at 30°. That line is a *model*: a rule that turns a question into a guess. Move the two sliders and the rule changes.

3. How wrong is it?

Any line we draw misses most of the points. Each gap is a day the rule got wrong: the real count minus the guess. A good model is one where the gaps are small.

4. Square the gaps, add them up

Turn every gap into a square. Big misses become big squares, and above or below no longer matters. The total area is the model's error. Now watch the line move until that total is as small as it can be.

5. Now make the guess

With the best line in place, the question has an answer. Go up from 30° to the line, then across. The model has never seen a 30° day, yet it makes a sensible guess from the days it has seen.

6. Try to beat it

The dashed line is the best one the data allows. Move the sliders and try to get a lower error. You can match it; you cannot beat it. That is what "fitting a model" means: choosing the numbers that make the total error smallest.

7. This is what a model is

A model has two parts: a *shape* for the rule (here, a straight line) and *numbers* the data decides (here, w and b). This one is called linear regression and has two dials; the biggest AI models have billions. Every one of them is the same idea: a rule with dials, tuned until it fits what it has seen.

8. Did it land?

A new day arrives with a surprising number. Think about the squares before you answer.

Check your understanding

On a 20° day the café unexpectedly sells 100 drinks — far above the line. If we refit, what happens to the best line?

A gap that far from the line makes a huge square. The cheapest way to shrink the total area is to move the line part of the way toward the new point, even though that slightly grows the squares on the other days.