Discrete distributions
Random variables, the pmf and the CDF; the Bernoulli, categorical, binomial, geometric and Poisson distributions, each from its own story, with the Poisson limit of the binomial.
Numbers on outcomes
The topic Conditional probability and Bayes' formula worked with events: yes/no statements such as "the person is sick" or "the test is positive". We can now update their probabilities on new evidence. But the questions kept turning into numbers. How many of three test runs come back positive? How many suspicious words does a letter contain? What do two dice add up to? How many rolls until the first six?
A random variable attaches a number to every outcome. Formally it is a function
Roll two dice. The sample space has 36 equally likely outcomes , and the sum is a random variable. It sends to , and so do four other outcomes. Statements about are events, that is, sets of outcomes:
Nothing new is needed to compute such probabilities. Collect the outcomes where the variable takes the value, and use the rules from the earlier topics. Upper case is the variable; lower case is a value it can take.
The pmf and the CDF
For a discrete variable, one with finitely or countably many values, the whole story is in one table. The probability mass function (pmf) gives the probability of each value:
For the sum of two dice, counting outcomes as in the previous block gives
| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 5 | 4 | 3 | 2 | 1 |
A pmf is non-negative and sums to 1 over all values. Any probability about is a sum of pmf values. For example, .
The pmf describes the distribution, not the variable itself. A die and a six-sector spinner are different objects with the same distribution. Every probability statement about one holds for the other. That is why named distributions are worth learning: one table serves many problems.
The cumulative distribution function (CDF) accumulates the pmf:
For a discrete variable it is a staircase. It is flat between the values, jumps by at each value , starts at 0 far to the left and reaches 1 far to the right. It is defined for every real , not only for the values. Since is the disjoint union of and , the probability of a half-open interval is a difference:
Bernoulli and categorical
The simplest variable answers one yes/no question. , the Bernoulli distribution, takes the value 1 with probability and 0 with probability . Both cases fit in one formula:
Every event gives one. The indicator equals 1 when happens and 0 otherwise, so . Events from the earlier topics are Bernoulli variables in disguise. The result of one run of the medical test from the previous topic, 1 for positive, is , where is from the law of total probability.
This is also what a binary classifier outputs. A spam filter does not return "spam" or "not spam". It returns a number , and that number is read as the parameter of a Bernoulli distribution over the label.
With possible values instead of two, we get the categorical distribution : value has probability , with
The softmax layer of a 10-class image classifier outputs ten numbers : a categorical distribution over classes. A language model does the same over its whole vocabulary of tens of thousands of tokens. Generating text means drawing the next token from that categorical distribution, again and again. Training such models with cross-entropy fits these parameters by maximum likelihood; the topic Maximum likelihood shows why.
Counting successes
Repeat a Bernoulli trial times, independently and with the same , and count the successes. The count is a sum of indicators, , and it takes values .
Its pmf takes two steps. One particular sequence with successes and failures has probability . This is the multiplication rule for independent events. There are such sequences, one for each choice of where the successes go, as in the topic Outcomes, events and counting. So , the binomial distribution, has
Ten fair coins land on exactly 5 heads with probability . Even the most likely count turns up only about a quarter of the time.
A classifier's test set is the same story. If the true error rate is and the test examples are independent, the number of errors is . With and , the chance of seeing exactly 10 errors is only about . The measured error rate almost never equals the true one exactly. How far it can stray is the subject of the limit theorems later in the course.
Both conditions matter: independent trials and the same . Run the medical test three times on one person. For a sick person the runs are independent with , so the number of positives is . For a random person it is not binomial: the runs are only conditionally independent, and a first positive makes a second one more likely.
Draw 5 cards from a deck without putting them back, and the draws are dependent. The number of aces then follows the hypergeometric distribution, and exactly two aces has probability , while the binomial formula with would say . When the population is much larger than the sample, the difference fades. That is why a poll of 1,000 people out of millions can use binomial formulas.
Waiting for the first success
Now keep repeating the same trial and ask how long the wait is. Let be the number of trials up to and including the first success. Its values are , with no upper limit. means failures followed by a success, so , the geometric distribution, has
Some books count the failures before the first success instead. Their variable is ours minus one. In this course always counts trials.
The tail is even simpler. means exactly that the first trials all failed:
The wait for a six exceeds 10 rolls with probability .
Now suppose rolls have already passed without a six. By the definition of conditional probability, and because lies inside ,
The geometric distribution is memoryless: the remaining wait has the same distribution as a fresh one. After 10 rolls without a six, the chance of 10 more without one is still . The feeling that a six is "due" is the gambler's fallacy. The die does not remember.
Rare events and the Poisson limit
Some counts come from many opportunities, each with a tiny chance. A site has a million visitors a day, and each one hits a rare bug with probability . A long document contains a rare word a few times. The count is binomial, but is huge, is tiny, and often neither is known. What we do know is , the typical number of events. The topic Expectation and variance will show that is exactly the average count.
So fix , set and let grow. Split the binomial pmf into four factors:
As with fixed, the first factor tends to 1, the third tends to , and the fourth tends to 1. What remains is the Poisson distribution :
It is a genuine pmf. The series equals , so the probabilities sum to 1. It has a single parameter, and it never asks for or separately.
The approximation is good quickly. With , the binomial probability of zero events is for , for and for , against the Poisson value .
The classic data set is Bortkiewicz's (1898): deaths from horse kicks in the Prussian cavalry, 200 corps-years with 122 deaths, so . Years with 0, 1, 2, 3 and 4 deaths were observed 109, 65, 22, 3 and 1 times, and predicts 108.7, 66.3, 20.2, 4.1 and 0.6. Many soldiers, each with a tiny and roughly independent risk: exactly the story above.
Which story gives which distribution
Each family comes from a story, and the story tells you which one to use.
| Story | Distribution | Values |
|---|---|---|
| One yes/no trial | ||
| One of categories | ||
| Successes in independent trials | ||
| Trials up to the first success | ||
| Rare events among many opportunities |
When the story breaks, so does the formula. Clicks from the same user or near-duplicate test examples are not independent trials, and the real spread is wider than the binomial says. Bursty counts, such as requests from a bot or repeats of a word that has just appeared, vary more than a Poisson with the same . Models such as the negative binomial or mixtures handle such counts.
All five families take countable values: one table of probabilities covers everything. A waiting time in seconds, a person's height or a model's predicted probability lives on a continuum. There the table fails. The topic Kolmogorov's axioms showed that every single point of has probability zero under the uniform distribution, so a pmf would be zero everywhere. The topic Continuous distributions replaces the pmf with a density and keeps the CDF. It also meets the exponential distribution, the continuous cousin of the geometric and memoryless too.
Check your understanding
The same questions as in Pulse. Answers are shared between modes.
Answers are saved on the server and tied to this browser until you sign in.