Introduction to AI Lesson 14 of 25

Part 2 · Lesson 4 · 5 min

Patterns: finding the line

Can you predict an ice cream shop's sales from the temperature?

You probably already can, roughly. That rough rule in your head is a model.

People have always drawn lines through stars to make constellations. The stars are scattered, but the shape is easy to see. Fitting a model is the same move: find the simple shape hiding in messy data.

Ice cream and heat

That red line is the model. It does not store every past day. It is a short summary, "hotter means more ice cream, by about this much", that you can use on a day you have never seen.

Real data never sits perfectly on a line, though.

Not a perfect fit

A model that bends itself to hit every single point usually predicts new days worse, not better. The goal is the trend, not a perfect fit to the past.

One more warning. A pattern is not a cause. Ice cream sales and swimming accidents both rise in summer, but ice cream does not cause drowning. Hot weather drives both, and a model looking only at those two columns cannot tell the difference.

Go deeper optional

The straight line here is called linear regression, one of the oldest tools in statistics; the method behind it goes back to the early 1800s. The line is written as

sales = a x temperature + b

where a is how much sales rise per degree and b is where the line starts. "Fitting" means choosing a and b so the line is as close as possible to all the points at once. The usual measure adds up the squared distances from each point to the line and makes that total as small as possible. Part 3 covers this visually.

Check yourself

1. What does "fitting a model" mean here?

2. Ice cream sales and drownings both rise in summer. Does ice cream cause drowning?

3. One day breaks the pattern badly. What should a good model do?