Skip to content
BIASED

What probability is

Where randomness enters machine learning, three readings of probability — equally likely outcomes, frequency and degree of belief — the rules they share, and simulation as a check on intuition.

Why machine learning needs probability

One question runs through this course: how do we reason exactly about what we cannot predict, and how do we learn about the world from random data? The first half builds a language for chance. The second half turns that language into statistics and simulation. This topic asks the most basic question first: what does the number "probability" mean at all?

Machine learning needs the answer because randomness is everywhere in it.

  • Data. A training set is one of many sets we could have collected. Collect another one and you get a slightly different model. The error rate on a test set is random for the same reason.
  • Noise. Labels contain mistakes, sensors are noisy, and two annotators disagree on the same image.
  • Training. Initial weights are random, minibatches come in a random order, and dropout switches off random units. Two runs that differ only in the random seed end with different networks.
  • Prediction and generation. A classifier outputs probabilities of the classes. A language model outputs a distribution over the next token, and generation draws the token from it.

So every model makes probabilistic claims, and we need to know what they mean and how to compute with them. There are several readings of the word "probability". We start with the oldest one.

Equally likely outcomes

Roll a fair die. Six outcomes can happen, and nothing distinguishes one face from another. It is natural to give each face the same share, 1/61/6. The event "an even number" happens on three faces out of six, so its probability is 3/6=1/23/6 = 1/2.

This is the classical reading. If an experiment has nn equally likely outcomes, and an event AA happens on kk of them, then

P(A)=kn.P(A) = \frac{k}{n}.

Probability becomes counting. A shuffled deck of cards, a lottery, and a training example chosen uniformly at random from a dataset all fit this pattern. Counting can get tricky fast, and the next topic is about it.

The classical reading has two limits.

  • Outcomes are not always equally likely. A loaded die still has six faces, but they do not get 1/61/6 each. Neither do the 50,000 tokens a language model can output next: "the" is far more likely than "aardvark".
  • Outcomes are not always finite in number. A point chosen at random on a segment can land on infinitely many places, and k/nk/n makes no sense.

To deal with such cases we need a reading that does not rely on symmetry.

Long-run frequency

The frequency reading says: repeat the experiment many times under the same conditions, and the probability of AA is the share of trials in which AA happens, in the limit of many trials.

Here are two simulated runs of 10,000 fair coin flips. The table shows the share of heads after the first nn flips.

nn 10 100 1,000 10,000
run 1 0.3 0.51 0.5 0.4955
run 2 0.8 0.54 0.525 0.4948

The share wanders a lot at first and then settles near 0.50.5. How fast? For a fair coin, at a given nn about 95% of runs end up within

0.5±1n.0.5 \pm \frac{1}{\sqrt n}.

At n=100n = 100 that is ±0.1\pm 0.1, and at n=10,000n = 10{,}000 it is ±0.01\pm 0.01. The band shrinks like 1/n1/\sqrt n, not like 1/n1/n, so precision is expensive. The topic The central limit theorem will derive this band. For a coin that is not fair the band is narrower, so 1/n1/\sqrt n is a safe upper bound.

Frequencies are how probabilities meet the world. The error rate of a classifier is exactly this: 50 mistakes on 1,000 test images give 0.050.05, and another test set of the same size could easily give a value up to about 1/1000≈0.031/\sqrt{1000} \approx 0.03 away.

The frequency reading has its own limit. It needs an experiment that can be repeated. "Will it rain tomorrow?" or "Will this startup survive?" happen once, and there is no long series to take a share of.

Degree of belief

The degree-of-belief reading, also called Bayesian, says: a probability measures how strongly a reasoner should believe a statement, given what they know. It applies to one-off events ("rain tomorrow"), to facts we are unsure about ("this coin is biased"), and to model outputs ("this email is spam").

A belief becomes a number through bets. Imagine a ticket that pays 11 if AA happens and nothing otherwise. Your probability P(A)P(A) is the price at which you consider the ticket fair: you are equally willing to buy it or to sell it at that price.

The same idea fixes fair odds. In a bet you put a stake ss; if AA happens you win ww, and if not you lose ss. Over a long series of such bets you win in a share pp of them and lose in a share 1−p1 - p. The bet is fair when you break even on average:

p w−(1−p) s=0.p\,w - (1 - p)\,s = 0.

If you believe p=0.25p = 0.25, you win one bet in four, so the bet is fair when w=3sw = 3s: odds of 3 to 1.

The two readings meet in calibration. A spam filter that outputs 0.90.9 expresses a degree of belief. We call it calibrated when, among all emails that get the score 0.90.9, about 90% really are spam. The belief is then checked by a frequency.

The same rules for every reading

The readings disagree about what probability is. They agree on how probabilities combine. Three rules hold in every reading.

  1. Every probability lies between 00 and 11.
  2. An event that is certain to happen has probability 11.
  3. If AA and BB cannot happen together, the probability that one of them happens is P(A)+P(B)P(A) + P(B).

The third rule extends to any number of events that cannot happen together. Together the rules imply more. For example, AA and "not AA" cannot happen together and one of them is certain, so the probability that AA does not happen is 1−P(A)1 - P(A).

Why do frequencies obey the rules? A share of trials lies between 00 and 11, and if AA and BB never happen together, the trials where one of them happens are just the AA trials plus the BB trials.

Why must beliefs obey them? Because otherwise someone can bet against you and win for sure. Suppose you price a ticket on AA at 0.60.6 and a ticket on "not AA" also at 0.60.6. You consider both fair, so you buy both for 1.21.2. Exactly one of them pays 11, so you lose

0.6+0.6−1=0.20.6 + 0.6 - 1 = 0.2

whatever happens. A set of bets that loses for sure is called a Dutch book. Beliefs that follow the rules are immune to it.

The classical reading obeys the rules too, since it is a share of equally likely outcomes. The topic Kolmogorov's axioms writes these rules down as axioms without choosing a reading, and the whole course is built on them.

Simulation as an intuition pump

The frequency reading gives a tool that works even when we cannot yet compute the answer: simulate the experiment on a computer and count.

A classic example comes from 17th-century gamblers. The Chevalier de Méré bet that at least one six turns up in four rolls of a die. A tempting argument: each roll gives a six with probability 1/61/6, so four rolls give 4/64/6. Let us check it with 100,000 simulated games.

import numpy as np
 
rng = np.random.default_rng(1)
rolls = rng.integers(1, 7, size=(100_000, 4))  # 100,000 games, 4 rolls each
win = (rolls == 6).any(axis=1)                 # at least one six in the game?
print(win.mean())                              # 0.51533

The estimate is 0.5150.515, with a band of ±1/100,000≈±0.003\pm 1/\sqrt{100{,}000} \approx \pm 0.003. That is nowhere near 0.6670.667. The exact answer is 1−(5/6)4≈0.5181 - (5/6)^4 \approx 0.518, and the topics Kolmogorov's axioms and Conditional probability and Bayes' formula will give you the tools to derive it. The bet is good for de Méré, but only barely.

Simulation is an intuition pump. When an argument feels right, ten lines of code can confirm it or break it, and the 1/n1/\sqrt n band tells you how much to trust the result. The topic Monte Carlo methods turns this into a method.

Where intuition fails and what comes next

Intuition fails confidently and in predictable places. A disease affects 1% of people. A test detects it in 90% of sick people and gives a false alarm in 9% of healthy ones. A patient tests positive. How likely is the disease? Doctors asked this question often answered about 0.9.

Count instead, in a group of 1,000 people.

  • 10 are sick, and 9 of them test positive.
  • 990 are healthy, and about 89 of them test positive anyway.

Of the 98 positives only 9 are sick, so the answer is 9/98≈0.099/98 \approx 0.09. The disease is rare, so the false alarms among the many healthy people outnumber the true cases. The topic Conditional probability and Bayes' formula turns this counting into a formula.

Look at what made this work. We listed every kind of outcome (sick or healthy, positive or negative), picked out the ones we cared about, and counted. The die, the coin and de Méré's game had the same skeleton. So far we did it informally. The next topic, Outcomes, events and counting, makes it precise: the set of all outcomes, events as its subsets, operations on events, and the rules of counting that answer questions like "how many people make a shared birthday likely?".

Check your understanding

The same questions as in Pulse. Answers are shared between modes.

Full notes

Answers are saved on the server and tied to this browser until you sign in.