Bayes and uncertainty

AI from scratch · 19 of a series

Bayes and uncertainty: lesson transcript

1. Before you look

Will the café be busy today? Before any clue, the best you can do is history: of the last hundred days, forty were busy. So 40%. That number is your *prior*, the belief you hold before evidence arrives. Every model in this series has been producing numbers like it; this last explainer is about what those numbers mean and how they should move.

2. A clue arrives

You look out of the window: the sun is out. That is evidence, because sun and business are linked. History says 80% of busy days were sunny, but only 30% of quiet ones. Mark every day that was sunny. The clue is informative precisely because the marks are not spread evenly.

3. Keep only the days that match

Today is sunny, so the days that were not sunny are irrelevant: fade them out. Fifty days remain. Thirty-two of them were busy. The belief has moved from 40% to 64%, and that is the whole of Bayes' rule: restrict to the days consistent with the evidence, then count again.

4. The same thing as areas

Draw it as a square. Split the width by the prior: busy on the left, quiet on the right. Within each column, shade the fraction that is sunny. Today is sunny, so only the shaded parts count, and the belief is the blue area over all the shaded area. Slide any of the three numbers and watch the belief follow.

5. Clue after clue

Evidence keeps coming. The sun is out; then you remember it is a weekend; then that there is a festival in town. Each clue moves the belief, and each time the belief you had becomes the prior for the next clue. Updating is a chain, and it is the same rule every link. The final number is not a hunch; it is the arithmetic of everything you noticed.

6. When the thing is rare

Now a warning. Suppose busy days are rare, one in fifty, and your clue is good: it shows up on 90% of busy days and only 10% of quiet ones. The clue fires. How sure should you be? Slide the prior down and watch. With a rare event, most of the days that match the clue are quiet days that happened to match, and the belief stays low. A strong clue about a rare thing is mostly false alarms.

7. Name it: every chart was a belief

The neuron's output, the next-token chart, the spiral network's blue and red: all of them were *posteriors*, beliefs given the evidence in the input. That gives them a duty. When a model says 70%, it should be right about 70% of the time, no more and no less. Checking that, *calibration*, is how you learn whether a model's confidence means anything. An answer without a probability is a guess; a probability that does not track reality is worse.

8. Did it land?

An accurate test, a rare event.

Check your understanding

Busy days are 5% of all days. A detector is right 95% of the time on busy days and 95% of the time on quiet days. It says "busy". How likely is it that today is actually busy?

Out of 1000 days, 50 are busy and the detector catches about 48 of them. The other 950 are quiet, and 5% of those, about 48, set it off anyway. Of all the alarms, roughly half are real. The detector is fine; the event is rare, and the prior does half the work whatever the detector says.