Chapter 20 · Statistics and ML

Probability Theory and Distributions

Chapter 17 used these distributions without deriving them. This chapter derives every one from its definition — every step of every mean and variance formula, and why that step is legal — then builds the mental map for recognising which distribution a word problem is actually describing.

23 sections 9 distributions derived 10 identification drills 12 interview drills Reading time ~3.5 hours

[!] Why derivation, not a table to memorise

A table of "distribution → mean → variance" is easy to find and easy to forget under pressure, because memorised facts with no structure decay fast and fail silently — you misremember Var = np instead of np(1−p) and have no way to notice. A derived fact is different: if you forget the formula but remember the two-line argument, you can rebuild it in fifteen seconds, and the argument itself tells you when the formula does and doesn't apply.

So every derivation in this chapter is written as a sequence of small steps, and after each step there is a sentence explaining why that step is legal — which identity justifies it, or what property of the distribution it uses. That is the part most treatments skip, and it is the part that actually transfers.

[i] What this assumes, and what it doesn't repeat

It assumes basic algebra, the idea of a limit, and nothing else — section 20.2 builds probability from three axioms up. Chapter 17 covered how to use these distributions in an evaluation or experiment (confidence intervals, hypothesis tests, the bootstrap); this chapter is where each distribution comes from and why its formulas take the shape they do. Read this one first if the two feel out of order — nothing here depends on chapter 17.

Not covered: measure-theoretic probability, moment generating functions, and multivariate distributions beyond what independence already gives you. The goal is everything an engineering interview or a production data problem actually needs, derived properly, not a pure-mathematics course.

20.1 Why derive instead of memorise

Every formula in this chapter can be looked up. The reason to derive them anyway is that the derivation is what tells you when to use them — and that judgement is the actual skill being tested, whether the test is an interview or a production incident.

[+] What a derivation buys you that a table doesn't

  • Error detection. If you misremember a formula but remember the argument, you can rebuild it and notice the misremembering. A memorised fact with no structure gives you nothing to check it against.
  • Knowing the assumptions. Every distribution's formula depends on specific conditions — independence, a constant rate, a fixed number of trials. The derivation is where those conditions get used explicitly, which is exactly where they get violated in real data (20.19).
  • Transfer. The same three tricks — linearity of expectation, the factorial-moment trick, and recognising a limit — derive nearly every formula in this chapter. Learn the tricks once and every distribution becomes easier, including ones not covered here.

[retail] This is chapter 17, one level down

Chapter 17 computed a search platform's peak traffic as "5× the average" and treated query counts as roughly normal. Both of those are distributional claims. This chapter is where you learn why request counts in a fixed window are Poisson, why a sum of many small independent effects tends toward normal regardless of the underlying shape, and why the approximation quietly breaks in specific cases (20.15). Nothing changes about how you used those facts in chapter 17 — this is where they come from.

20.2 Sample space, events, the axioms

Everything in probability is built from three rules. Nearly every identity you will ever use is a short, mechanical consequence of one of them.

[def] The vocabulary

The sample space Ω is the set of every possible outcome of an experiment: for one API call, {success, failure}; for a service's request count in an hour, {0, 1, 2, …}. An event is any subset of Ω — "at least one failure" is the event {failure} within the two-outcome space, or "more than 300 requests" is a subset of the non-negative integers.

[→] The three axioms, and what each one is for

  1. Non-negativity: P(A) ≥ 0 for every event A A probability is never negative. This is a definition, not something derived — it rules out nonsense results, and any calculation that produces a negative "probability" contains an error somewhere upstream.
  2. Normalisation: P(Ω) = 1 Something in the sample space happens with certainty. This is what turns probability into a number between 0 and 1 rather than an arbitrary positive quantity — it fixes the scale.
  3. Countable additivity: for disjoint events A₁, A₂, … — P(A₁ ∪ A₂ ∪ …) = P(A₁) + P(A₂) + … If two events cannot both happen, the probability that either happens is the sum. This is the axiom that makes a PMF sum to 1 (20.4) and is the engine behind almost every "add up the cases" calculation in this chapter.

[+] Two identities that fall straight out, and why they're free

P(Ac) = 1 − P(A) — since A and its complement are disjoint and together make up Ω, axiom 3 gives P(A) + P(Ac) = P(Ω) = 1 by axiom 2. This is why "P(at least one) = 1 − P(none)" is always legal: it is axioms 2 and 3 applied once, not a special trick. And P(A ∪ B) = P(A) + P(B) − P(A ∩ B) corrects axiom 3 for overlapping events — you'd double-count the overlap by adding P(A) and P(B) directly, so you subtract it back out once.

20.3 Conditional probability and independence

[def] Conditional probability, defined

P(A | B) = P(A ∩ B) / P(B), read "the probability of A given B." This is a definition, not a derived fact — it formalises "restrict attention to the world where B happened, and ask how much of that world is also A." Rearranging gives the form used constantly in derivations: P(A ∩ B) = P(A | B)·P(B), the multiplication rule.

[→] Independence, and why it's a qualification rather than a definition of "unrelated"

Events A and B are independent if knowing one occurred tells you nothing about the other: P(A | B) = P(A). Substitute this into the multiplication rule above:

deriving the product ruletext
P(A ∩ B) = P(A | B) · P(B)      <- multiplication rule, always true
            = P(A) · P(B)          <- substitute P(A|B) = P(A), the definition of independence

P(A ∩ B) = P(A)·P(B) is therefore not a separate fact to memorise — it is what independence means, run through the definition of conditional probability. This is the single most-used step in this chapter: every Binomial, Geometric and Negative Binomial derivation multiplies probabilities across trials, and doing so is only legal because the trials are assumed independent. Change that assumption and every formula in Part B stops applying.

[!] Independent is not the same as mutually exclusive — the opposite, usually

Mutually exclusive events (disjoint: A ∩ B = ∅) cannot both happen, so knowing one occurred tells you the other definitely did not — which is about as far from independent as two events can be. Confusing the two is one of the most common errors in applied probability: two disjoint events with positive probability are never independent, because P(A|B) = 0 ≠ P(A) whenever P(A) > 0.

20.4 Random variables, PMF, PDF, CDF

[def] Random variable

A random variable X is a function from the sample space to the real numbers — it takes an outcome ("success") and assigns it a number (1). This is what lets you do arithmetic on outcomes: you cannot average "success" and "failure", but you can average the numbers 1 and 0 that X assigns to them.

Three functions that describe a random variable completely
FunctionApplies toDefined as
PMF — probability mass function Discrete X p(k) = P(X = k). Must satisfy ∑ p(k) = 1, directly from axiom 2 and 3: the events {X=k} for every k are disjoint and cover Ω.
PDF — probability density function Continuous X f(x) such that P(a ≤ X ≤ b) = ∫ab f(x)dx. f(x) itself is not a probability — P(X=x) is exactly 0 for any single point (20.12).
CDF — cumulative distribution function Both F(x) = P(X ≤ x). Always non-decreasing, F(−∞)=0, F(∞)=1. For discrete X, F is a staircase; for continuous X, F is smooth and F′(x) = f(x).

[+] Why the PDF being allowed above 1 confuses people, and shouldn't

A PDF value like f(x) = 3 is completely legal, because f is a density, not a probability — it only becomes a probability after being integrated over an interval. A Uniform(0, 0.2) distribution has f(x) = 5 everywhere on its support, and that is correct: ∫00.2 5 dx = 1, exactly satisfying normalisation. The height of a density curve carries no meaning on its own; only area under it does.

20.5 Expectation and variance, derived

These two numbers summarise a distribution's centre and spread, and both are defined by a formula whose legality depends on one property proven in this section: linearity.

[def] Expectation

E[X] = ∑ k·p(k) for discrete X, or ∫ x·f(x)dx for continuous X — the probability-weighted average of every value X can take. It is the long-run average of X across infinitely many independent repeats, which follows from the law of large numbers (not derived here, but the reason "expectation" is a meaningful word rather than an arbitrary formula).

[→] Linearity of expectation, and why it needs no independence at all

E[X + Y] = E[X] + E[Y], for any X and Y — correlated, dependent, anything. This single fact is the most-used tool in this entire chapter, because it is what lets you compute E[X] for a complicated X by writing it as a sum of simple pieces.

proof, discrete casetext
E[X+Y] = ∑∑ (x+y)·P(X=x, Y=y)               <- definition of expectation, applied to X+Y
       = ∑∑ x·P(X=x,Y=y) + ∑∑ y·P(X=x,Y=y)   <- distribute the sum; legal because
                                                    sums are finite/absolutely convergent
       = ∑x · [∑y P(X=x,Y=y)] + ∑y · [∑x P(X=x,Y=y)]  <- factor out x and y, regroup
       = ∑x · P(X=x) + ∑y · P(Y=y)      <- the bracketed sum is exactly the
                                                    marginal PMF of X (or Y) -- summing
                                                    out the other variable
       = E[X] + E[Y]                              <- definition of expectation, again

The step worth noticing is the third line: summing P(X=x, Y=y) over every value of y recovers P(X=x) by definition of a marginal distribution — it doesn't matter whether X and Y are independent, because you're just regrouping a sum, not multiplying anything. That's why linearity holds unconditionally, and it's why the Binomial's mean (20.7) is np in three lines despite the trials being correlated through the fixed total count.

[def] Variance

Var(X) = E[(X − E[X])2] — the average squared distance from the mean. This definition is rarely used directly in a derivation because it requires knowing E[X] first and then squaring a difference; the computational form below is used almost everywhere instead.

[→] Deriving Var(X) = E[X²] − E[X]²

the identity every variance derivation in this chapter usestext
Var(X) = E[(X - E[X])²]                        <- definition
       = E[X² - 2X·E[X] + E[X]²]              <- expand the square; E[X] is a
                                                  constant number, not a random variable
       = E[X²] - 2E[X]·E[X] + E[X]²         <- linearity: E[aX] = a·E[X] for a
                                                  constant a, and E[constant] = that constant
       = E[X²] - 2E[X]² + E[X]²               <- combine 2E[X]·E[X] = 2E[X]²
       = E[X²] - E[X]²                        <- combine the last two terms

Two steps are doing real work here. Treating E[X] as a plain number (not a random quantity) is what makes "E[aX] = a·E[X]" apply to it in step three — that scalar rule is itself a one-line consequence of linearity, since a constant is just a degenerate random variable. This is why nearly every derivation below computes E[X²] as its hard step and then simply subtracts E[X]²: the identity converts "find the spread" into "find one more moment," which is usually an easier sum or integral than working with the definition directly.

[+] The scaling rules, and why they look asymmetric

E[aX+b] = aE[X]+b follows directly from linearity. But Var(aX+b) = a²Var(X) — the shift b vanishes entirely, and the scale a is squared. Both make sense from the definition: shifting every value of X by a constant b shifts the mean by exactly b too, so the distance from the mean (X − E[X]) is completely unchanged, hence unaffected by b. Scaling X by a scales that distance by a, and variance squares it, so the factor becomes a². This is why standard deviation (√Var(X)) rather than variance is the number quoted alongside a mean — it scales the same way the data does.

20.6 Bernoulli: the atom

Every distribution in Part B is built out of Bernoulli trials. Getting its two-line derivation right by hand is worth doing once, because the same expansion pattern reappears in every derivation that follows.

[def] Bernoulli(p)

Models a single trial with two outcomes: success (X=1) with probability p, failure (X=0) with probability 1−p. One API call succeeding or failing, one coin flip, one user converting. Every other discrete distribution in this chapter counts or times a sequence of these.

[→] Deriving E[X] and Var(X)

Bernoulli mean and variance from the definitiontext
E[X]  = 0·(1-p) + 1·p = p                    <- definition of expectation: sum over
                                                the two possible values of X

E[X²] = 0²·(1-p) + 1²·p = p                  <- same sum, but X² takes the same
                                                two values (0 and 1) as X does

Var(X) = E[X²] - E[X]² = p - p² = p(1-p)      <- the computational identity from 19.5

The reason E[X²] = E[X] here specifically is that 0²=0 and 1²=1 — X is one of the very few random variables where squaring doesn't change the value, so this shortcut is a property of the {0,1} support, not a general trick. E[X] = p, Var(X) = p(1−p). Variance is maximised at p = 0.5 (a fair coin is the most unpredictable single trial) and is exactly 0 at p = 0 or p = 1, where the outcome is certain and there's nothing left to vary.

20.7 Binomial: summing Bernoullis

[def] Binomial(n, p)

Counts the number of successes in n independent Bernoulli(p) trials. The number of failed requests out of 20, the number of converting users out of 1,000 visitors. The PMF, which counts how many ways k successes can be arranged among n trials and weights each arrangement by its probability, is P(X=k) = C(n,k)·pk·(1−p)n−k.

[→] The mean, the fast way: linearity beats the PMF

You could compute E[X] by summing k·P(X=k) over the whole PMF — it works, but it's a genuinely awkward sum. Linearity of expectation (20.5) makes it three lines instead.

write X as a sum of indicatorstext
Let Xi = 1 if trial i succeeds, 0 otherwise    <- Xi is Bernoulli(p), one per trial
Then X = X1 + Xi + ... + Xn             <- total successes is the sum of indicators

E[X] = E[X1] + E[Xi] + ... + E[Xn]       <- linearity (19.5) -- holds even though the
                                                Xi are dependent through the fixed n
     = p + p + ... + p   (n terms)          <- each Xi is Bernoulli(p), so E[Xi] = p (19.6)
     = np

The subtlety worth sitting with: the Xi are not independent in the sense that knowing nine of the twenty trial outcomes changes nothing about your belief in the tenth (they genuinely are independent, since each trial is separate) — but even if they weren't, linearity wouldn't care, because it never used independence in its proof (20.5). This is exactly why the trick generalises: any count of successes across n trials has mean n·p(per trial success chance), whether or not the trials are independent, as long as each trial has the same success probability.

[→] The variance: this step needs independence, and here's exactly where

Variance does not add as cleanly as expectation in general. For two random variables, Var(X+Y) = Var(X) + Var(Y) + 2Cov(X,Y), and the covariance term vanishes only when X and Y are independent. This is the first derivation in the chapter where independence is doing indispensable work rather than just being assumed for convenience.

variance of a sum of independent indicatorstext
Var(X) = Var(X1 + Xi + ... + Xn)
       = Var(X1) + Var(Xi) + ... + Var(Xn)    <- Cov(Xi,Xj) = 0 for i≠j because
                                                the trials are INDEPENDENT -- this is
                                                the step that fails for correlated trials
       = p(1-p) + p(1-p) + ... + p(1-p)  (n terms)   <- each Xi is Bernoulli(p), Var = p(1-p) (19.6)
       = np(1-p)

E[X] = np, Var(X) = np(1−p). The contrast with the mean derivation is the entire point of showing both: expectation adds for free regardless of dependence, but variance only adds this cleanly when the trials are independent. If your twenty API calls share a resource and fail together under load, this formula for the variance is wrong even though the formula for the mean is still fine — a distinction that only becomes visible once you've seen where each proof actually uses (or doesn't use) independence.

[retail] Worked: 20 calls to a flaky payment provider, 3% failure rate

Binomial(20, 0.03)text
E[X] = np           = 20 × 0.03            = 0.60 expected failures
Var(X) = np(1-p)    = 20 × 0.03 × 0.97   = 0.582
SD                  = √0.582               = 0.763

P(exactly 2 fail)   = C(20,2)·0.03²·0.97¹&sup8;   = 0.0988
P(at least 1 fails) = 1 - P(0 fail) = 1 - 0.97²&sup0;      = 0.4562   ← complement rule, 19.2

Note how "at least one" reflexively became "1 − none" — that's the complement identity from 20.2, and it is almost always the easier direction to compute for a Binomial, since P(X=0) is a single term rather than a sum over eleven values.

20.8 Geometric: waiting for one success

Binomial counts successes in a fixed number of trials. Geometric flips the question: run trials until the first success, and ask how many trials that took. Fixed trial count becomes a fixed target; the number of trials becomes what's random.

[def] Geometric(p)

The number of independent Bernoulli(p) trials up to and including the first success. Support is {1, 2, 3, …} — you need at least one trial. To get X = k, the first k−1 trials must fail and the k-th must succeed, and independence lets you multiply those probabilities directly (20.3): P(X=k) = (1−p)k−1·p.

[→] Confirming the PMF sums to 1, using the geometric series

Before trusting a mean or variance formula, it's worth checking the PMF is legitimate — axiom 2 (20.2) requires it to sum to 1. This uses the standard infinite geometric series result k=0 rk = 1/(1−r) for |r| < 1, which is where the distribution's name comes from.

the PMF is a valid probability distributiontext
k=1 (1-p)k-1·p  = p · ∑k=1 (1-p)k-1    <- factor out the constant p
                            = p · ∑j=0 (1-p)j      <- substitute j = k-1, so the sum
                                                        restarts at j=0
                            = p · [1 / (1-(1-p))]           <- geometric series formula, r = 1-p
                            = p · (1/p) = 1                 <- simplify: 1-(1-p) = p

That substitution j = k−1 is the recurring move in every derivation below: it turns a sum starting at an inconvenient index into the standard geometric series starting at 0, where the textbook formula applies directly.

[→] Deriving E[X] = 1/p, by differentiating the series

This is the classic trick for geometric-series sums involving an extra factor of k: differentiate the basic series with respect to r, because differentiation brings a factor of k down out of the exponent.

the differentiation tricktext
Start from:     ∑k=0 rk = 1/(1-r)              <- the known geometric series

Differentiate   ∑k=0 k·rk-1 = 1/(1-r)²      <- d/dr of both sides; term-by-term
both sides                                              differentiation is legal here because
w.r.t. r:                                               the series converges nicely for |r|<1

Now compute E[X]:
E[X] = ∑k=1 k·(1-p)k-1·p           <- definition of expectation
     = p · ∑k=1 k·(1-p)k-1          <- factor out p
     = p · [1/(1-(1-p))²]                    <- this sum is EXACTLY the differentiated
                                                series above, with r = 1-p
     = p · (1/p²) = 1/p                      <- simplify: 1-(1-p) = p

E[X] = 1/p. This should feel right before you even finish the algebra: if success happens 3% of the time, you expect to wait 1/0.03 ≈ 33 trials for one — rarer successes mean longer waits, and the relationship is a clean reciprocal.

[→] Deriving Var(X) = (1−p)/p²

Differentiating once gave ∑k·rk−1. Differentiating again brings down a factor of k(k−1), which is exactly the factorial-moment shape used throughout this chapter for handling E[X²] cleanly.

second derivative gives E[X(X-1)]text
Differentiate    ∑k=0 k(k-1)·rk-2 = 2/(1-r)³    <- differentiate the first derivative's
again:                                                 result again w.r.t. r

E[X(X-1)] = ∑k=1 k(k-1)·(1-p)k-1·p
          = p·(1-p) · ∑k=1 k(k-1)·(1-p)k-2   <- pull out one factor of (1-p) so the
                                                        remaining sum matches the 2nd-derivative form
          = p·(1-p) · [2/(1-(1-p))³]         <- substitute r = 1-p into the 2nd-derivative series
          = p·(1-p) · (2/p³) = 2(1-p)/p²

Now assemble the variance:
E[X²] = E[X(X-1)] + E[X]              <- algebra: X² = X(X-1) + X, so this is just
                                        linearity applied to that identity
         = 2(1-p)/p² + 1/p
         = [2(1-p) + p] / p²           <- common denominator
         = (2-p) / p²                  <- simplify 2(1-p)+p = 2-2p+p = 2-p

Var(X) = E[X²] - E[X]²                <- the identity from 19.5
       = (2-p)/p² - 1/p²
       = (1-p)/p²

The identity X² = X(X−1) + X is worth remembering on its own: it is what converts "the hard moment" E[X²] into "the factorial moment" E[X(X−1)], which is almost always easier to compute for a distribution defined by products of probabilities, because the (X−1) cancels an awkward term in the sum. The same identity reappears in the Poisson derivation (20.10).

[!] Memorylessness: the property that makes Geometric special

P(X > k+m | X > k) = P(X > m) — if you've already had k failures, the distribution of additional trials needed is identical to starting over, regardless of k. Proof: P(X>k) = (1−p)k (all first k trials fail), so P(X>k+m)/P(X>k) = (1−p)k+m/(1−p)k = (1−p)m = P(X>m). This is the discrete counterpart to the Exponential's memorylessness (20.13), and it is only true for Geometric among discrete waiting-time distributions — Negative Binomial (20.9) does not have it, because remembering r−1 prior successes changes what's left to wait for.

[retail] Worked: trials until the first conversion, p = 0.03

Geometric(0.03)text
E[X]   = 1/p           = 1/0.03            = 33.3 trials expected
Var(X) = (1-p)/p²      = 0.97/0.0009        = 1077.8
SD     = √1077.8                          = 32.8

P(X=10)  = (0.97)⁹·0.03      = 0.0228   ← converts on exactly the 10th trial
P(X>50)  = (0.97)⁵⁰         = 0.218    ← still hasn't converted after 50 trials

Notice SD (32.8) is nearly as large as the mean (33.3) — Geometric distributions are highly right-skewed, which is worth flagging back to 17.2: reporting "average trials to conversion" as a clean summary hides that a substantial fraction of users convert almost immediately while a long tail never does within any reasonable window.

20.9 Negative binomial: waiting for r

Geometric asks how long until the first success. Negative Binomial asks the same question for the r-th success — and the fastest way to its mean and variance is to recognise it as r independent copies of a Geometric, stacked end to end.

[def] NegativeBinomial(r, p)

The number of independent Bernoulli(p) trials needed to accumulate exactly r successes (this section's convention: X counts total trials, not just the failures — check which convention a library or a problem statement uses before trusting a number, since both are common). Support is {r, r+1, r+2, …}. To land the r-th success exactly on trial k, the first k−1 trials must contain exactly r−1 successes in any order, and trial k itself must succeed: P(X=k) = C(k−1, r−1)·pr·(1−p)k−r.

[→] The mean and variance, without touching the PMF at all

Waiting for r successes is the same as waiting for the 1st success, then — once that resets — waiting for the next one, r times over. Each individual wait is Geometric(p), and the total trial count is their sum.

Negative Binomial as a sum of r Geometricstext
Let W1 = trials for the 1st success
    W2 = ADDITIONAL trials for the 2nd success, after the 1st
    ...
    Wr = additional trials for the r-th success, after the (r-1)-th

Each Wi is Geometric(p), and by the memorylessness of Geometric (19.8), each
new waiting period restarts fresh regardless of how the previous one ended --
so the Wi are INDEPENDENT and IDENTICALLY DISTRIBUTED.

X = W1 + W2 + ... + Wr

E[X] = E[W1] + E[W2] + ... + E[Wr]     <- linearity (19.5); doesn't even need the Wi
                                        to be independent, just identically distributed
     = (1/p) + (1/p) + ... + (1/p)  (r terms)   <- each Wi is Geometric(p), E[Wi]=1/p (19.8)
     = r/p

Var(X) = Var(W1) + Var(W2) + ... + Var(Wr)   <- variance of a sum of INDEPENDENT terms
                                            adds (19.7) -- this step needs the
                                            independence that memorylessness gave us
       = r · (1-p)/p²                          <- each Wi has Var = (1-p)/p² (19.8)

E[X] = r/p, Var(X) = r(1−p)/p². Set r=1 and both formulas collapse exactly to the Geometric's 1/p and (1−p)/p² — which is a useful sanity check on any formula you derive this way: it should reduce to the simpler distribution it generalises when you plug in the boundary case.

[+] The trick behind the trick: decompose into a sum of things you already solved

This derivation didn't touch the PMF once. That's deliberate, and it's the single most valuable habit in this chapter: before summing a nasty PMF directly, ask whether the random variable can be written as a sum of simpler, already-solved pieces. Binomial as a sum of Bernoullis (20.7) and Negative Binomial as a sum of Geometrics are the same move twice. It works whenever "the whole thing happening" can be split into independent (or at least identically distributed) stages, and it turns a derivation that would need the factorial-moment machinery into three lines of linearity.

[retail] Worked: trials until the 5th conversion, p = 0.03

NegativeBinomial(5, 0.03)text
E[X]   = r/p            = 5/0.03             = 166.7 trials expected
Var(X) = r(1-p)/p2       = 5 × 0.97/0.0009      = 5388.9
SD                       = √5388.9                = 73.4

P(exactly the 100th trial is the 5th success)
      = C(99,4) · 0.035 · 0.9795    = 0.00507

Compare to five independent runs of the earlier Geometric example (20.8), where one success takes 33.3 trials on average: five of them end to end give exactly 5 × 33.3 = 166.7, matching r/p precisely — because that's exactly what the derivation proved.

20.10 Poisson: the binomial's limit

Poisson counts events in a fixed window — requests per second, defects per batch, typos per page — when there's no natural "number of trials" to point to. It arises as what a Binomial becomes when n grows huge and p shrinks to match, which is exactly the derivation that explains where its strange e−λ comes from.

[def] Poisson(λ)

Counts events occurring at an average rate of λ per interval, when events happen independently and the chance of two events at the exact same instant is negligible. P(X=k) = e−λλk/k!, support {0, 1, 2, …}.

[→] Deriving the PMF as a limit of Binomial(n, λ/n)

Imagine chopping one second into n tiny slices, each slice an independent Bernoulli trial with a tiny success chance p = λ/n — small enough that at most one event can plausibly land in any one slice. As n → ∞ the slices become infinitesimally fine and this becomes an exact model of events landing at random instants. The number of "successes" is Binomial(n, λ/n), and its mean stays fixed at n·(λ/n) = λ no matter how fine the slicing gets — which is exactly the property you want for "a rate of λ per second."

taking the limit, one factor at a timetext
P(X=k) = lim  C(n,k) · (λ/n)k · (1-λ/n)n-k
       n→∞

Split C(n,k) = n!/(k!(n-k)!) and regroup into three separate limits:

  n! / [(n-k)! · nk]  →  1              <- this ratio is n(n-1)...(n-k+1)/n^k,
                                             a product of k terms each → 1 as n→∞
                                             (e.g. (n-1)/n → 1, (n-2)/n → 1, ...)

  (1 - λ/n)n          →  e       <- the standard calculus limit that DEFINES e:
                                             lim (1+x/n)^n = e^x, with x = -λ

  (1 - λ/n)-k         →  1              <- the exponent -k is FIXED while n→∞,
                                             so this factor just goes to 1^(-k) = 1

Multiply the surviving pieces together with the untouched λk/k!:

P(X=k) = 1 · λk/k! · e · 1 = eλk/k!

The e−λ term is not a special constant chosen to make the formula work — it's the ordinary calculus limit lim(1+x/n)n = ex showing up because "many independent trials, each individually unlikely" is precisely the setup that definition describes. Anywhere you see e−λ in a probability formula, a hidden "n → ∞, p → 0" limit is almost always the reason.

[→] Mean and variance: take the limit of np and np(1−p) directly

Rather than re-deriving from the Poisson PMF, take the Binomial's already-proven mean and variance (20.7) and push p = λ/n through the same limit.

inheriting the moments from the Binomial limittext
E[X] = lim n·p = lim n·(λ/n) = λ                    <- the n's cancel exactly, for every n

Var(X) = lim n·p·(1-p) = lim n·(λ/n)·(1-λ/n)
       = lim λ·(1-λ/n) = λ·(1-0) = λ      <- as n→∞, λ/n → 0, so the
                                                second factor just goes to 1

E[X] = λ, Var(X) = λ. Mean equals variance — a fact unique enough among named distributions that it functions as a diagnostic in its own right (20.17): if a real dataset's sample variance is far from its sample mean, that alone is evidence the data isn't really Poisson, independent of any other check.

[!] What the derivation reveals about when Poisson applies

The limit needed three things to be true, and each maps onto a real-world assumption worth checking before reaching for Poisson: many opportunities (n large — many tiny sub-intervals a request could arrive in), each individually unlikely (p small — no single instant is a likely arrival time), and independence (one request arriving doesn't change the odds of another). The classic violation is bursty traffic — a retry storm after an outage, or a marketing email landing in every inbox at once — where arrivals cluster and are no longer independent. Poisson will understate the probability of extreme counts in exactly that situation, because it assumes away the clustering that caused them.

[retail] Worked: request bursts at 3 per second on average

Poisson(3)text
P(X=0) = e-3·30/0!   = 0.0498   ← a quiet second, despite the average being 3
P(X≤1) = P(X=0)+P(X=1)          = 0.1991   ← roughly a 1-in-5 chance of 0 or 1 requests

At a much higher rate — 347 requests per second, a real platform's peak — P(X≥400) ≈ 0.29%, and the standard deviation is √347 ≈ 18.6. That 19.6 is the number chapter 17's capacity planning quietly depends on: "5× the average" as a safety margin is a blunt rule of thumb, while λ ± 3√λ (347 ± 56) is the same idea done with the actual distribution's spread.

20.11 Hypergeometric: sampling without replacement

Binomial assumes every trial has the same success probability p, which is only true if you're sampling with replacement — or from a population so large that removing one item doesn't meaningfully change the odds for the next. Hypergeometric is what happens when that assumption is dropped.

[def] Hypergeometric(N, K, n)

A finite population of N items, K of them "successes" (defective units, fraud cases), from which n are drawn without replacement. X is the number of successes among the n drawn. Every draw changes the composition of what's left, which is exactly the dependence Binomial assumes away. P(X=k) = C(K,k)·C(N−K,n−k) / C(N,n) — ways to choose k successes and n−k failures, divided by all ways to choose n items.

[→] The mean, by the same indicator trick as Binomial

Write X as a sum of n indicators exactly as in 20.7 — Xi = 1 if the i-th draw is a success. Linearity doesn't care that the draws are dependent (20.5), so the mean comes out just as easily as it did for Binomial.

E[X] via linearity, ignoring the dependence entirelytext
By symmetry, EVERY individual draw -- 1st, 2nd, ..., n-th -- has the same marginal
probability of being a success: K/N. (This is a genuinely non-obvious fact: the 5th
card drawn from a shuffled deck is exactly as likely to be an ace as the 1st card is,
even though which cards remain by then depends on everything drawn before it.)

E[X] = E[X1] + E[X2] + ... + E[Xn]    <- linearity (19.5), regardless of dependence
     = (K/N) + (K/N) + ... + (K/N)  (n terms)
     = n·K/N

E[X] = nK/N — identical in shape to the Binomial mean with p = K/N, which makes sense: on average, sampling without replacement still draws successes in proportion to how common they are in the population.

[+] The variance carries a correction factor, and it tells you something real

Var(X) = n·(K/N)·(1−K/N)·[(N−n)/(N−1)] — the Binomial variance np(1−p) with p=K/N, multiplied by the finite population correction (N−n)/(N−1). This factor is always ≤ 1, and it is what the dependence between draws actually costs you: sampling without replacement is more informative than sampling with it, because each draw rules out one possibility for the rest, which is precisely why the variance shrinks. As N grows large relative to n, (N−n)/(N−1) → 1 and Hypergeometric converges to Binomial(n, K/N) — removing one card from a million-card deck barely changes the odds for the next draw.

[retail] Worked: auditing 5 orders from a batch of 50, 10 flagged

Hypergeometric(N=50, K=10, n=5) vs Binomial(5, 0.2)text
Hypergeometric:  E[X] = 5·10/50 = 1.00     Var(X) = 1·0.8·(45/49) = 0.735
Binomial(5,0.2): E[X] = 5·0.2  = 1.00     Var(X) = 5·0.2·0.8       = 0.800

P(X=2), hypergeometric = 0.2098
P(X=2), binomial       = 0.2048   ← close, but measurably different at this small N

finite population correction: (50-5)/(50-1) = 0.918

The means match exactly (both formulas reduce to n·p when p=K/N), but the variances don't — the hypergeometric is consistently a little tighter, by exactly the correction factor of 0.918. Treating a without-replacement audit sample as Binomial isn't wildly wrong here, but it overstates the uncertainty in exactly the direction that makes flagging thresholds too conservative, and the gap grows as n approaches N.

20.12 Uniform: the baseline

Every discrete distribution so far has been built from Bernoulli trials. The three continuous distributions in this part need a different toolkit — integrals in place of sums — and Uniform is the simplest place to see the substitution work.

[def] Uniform(a, b)

Equal density everywhere on an interval [a,b], zero outside it: f(x) = 1/(b−a) for a ≤ x ≤ b. The constant 1/(b−a) is forced by normalisation — ∫ab f(x)dx must equal 1, and the only way a constant height over a width of (b−a) integrates to 1 is if the height is exactly 1/(b−a).

[→] E[X] and Var(X), by direct integration

The continuous analogue of ∑k·p(k) is ∫x·f(x)dx — same idea, sum replaced by integral because x now varies continuously rather than jumping between discrete values.

the two integralstext
E[X] = ∫ab x · 1/(b-a) dx
     = 1/(b-a) · [x²/2]ab            <- antiderivative of x is x²/2
     = 1/(b-a) · (b²-a²)/2
     = (b-a)(b+a) / [2(b-a)]              <- factor the difference of squares b²-a²
     = (a+b)/2                            <- the (b-a) terms cancel

E[X²] = ∫ab x² · 1/(b-a) dx
       = 1/(b-a) · [x³/3]ab
       = (b³-a³) / [3(b-a)]
       = (a²+ab+b²)/3            <- factor b³-a³ = (b-a)(b²+ab+a²), cancel (b-a)

Var(X) = E[X²] - E[X]²                <- the identity from 19.5, unchanged for continuous X
       = (a²+ab+b²)/3 - (a+b)²/4
       = (b-a)²/12                    <- combine over a common denominator of 12; the
                                       algebra is mechanical but the cancellation
                                       is real -- try it with a=0,b=1 to check: 1/12

E[X] = (a+b)/2 is just the interval's midpoint, exactly as intuition demands for a flat density. Var(X) = (b−a)²/12 is worth keeping as a reference point: it's the variance formula every other continuous distribution in this chapter gets compared against, since Uniform is "spread with no preference at all" — the baseline case.

20.13 Exponential: continuous waiting

Geometric is the number of discrete trials until an event. Exponential is its continuous twin: the time until an event that can happen at any instant, at a constant rate. It falls directly out of the Poisson process that produced the Poisson distribution in 19.10.

[def] Exponential(λ)

Models the waiting time until the next event of a process where events occur at rate λ per unit time — time between requests, time to failure. f(x) = λe−λx for x ≥ 0.

[→] Deriving the PDF from "zero events so far," the Poisson connection

The cleanest route to the Exponential is through its CDF, using the Poisson distribution already derived in 20.10 rather than starting from the PDF as given.

the survival function, then differentiatetext
Let X = waiting time for the first event of a rate-λ Poisson process.
"X > t" means EXACTLY: zero events occurred in the interval [0, t].

The number of events in an interval of length t is Poisson(λt) -- the rate
λ scaled up by however long you wait (this scaling is a property of a
Poisson process, taken as given here).

P(X > t) = P(zero Poisson(λt) events)
         = e-λt(λt)0/0!        <- Poisson PMF at k=0, from 19.10
         = e-λt

So the CDF is F(t) = P(X ≤ t) = 1 - e-λt

f(t) = F'(t) = λe-λt          <- differentiate the CDF to recover the PDF;
                                       this is the defining relationship from 19.4

This route matters more than it looks: it shows Exponential isn't an independent assumption bolted onto Poisson — it's a restatement of the same process, just asking "how long until the first event" instead of "how many events in a fixed window." Whatever assumptions justified Poisson (20.10's independence and no-clustering conditions) automatically justify Exponential too, and whatever breaks one breaks the other.

[→] E[X] = 1/λ, by integration by parts

the standard integration-by-parts pattern for x·e^(-x) integralstext
E[X] = ∫0 x · λe-λx dx

Integrate by parts: ∫u dv = uv - ∫v du
  Let u = x            dv = λe-λx dx
      du = dx           v = -e-λx          <- antiderivative of λe^(-λx) is -e^(-λx)

E[X] = [-x·e-λx]0  +  ∫0 e-λx dx
     = (0 - 0)                          + [-1/λ · e-λx]0
     = 0 + (0 - (-1/λ))
     = 1/λ

The boundary term [-x·e−λx] at ∞ needs a moment's justification: exponential decay beats polynomial growth, so x·e−λx → 0 as x → ∞ even though x itself is growing without bound. This same fact makes every moment of the Exponential finite, unlike some heavier-tailed continuous distributions where it doesn't hold.

[+] Var(X) = 1/λ², and the pattern that gets you there faster

A second integration by parts on ∫x²·λe−λxdx gives E[X²] = 2/λ², so Var(X) = 2/λ² − (1/λ)² = 1/λ². The pattern generalises: ∫0xnλe−λxdx = n!/λn, one factorial for every power of x, from repeating integration by parts n times. Standard deviation equals the mean exactly (both 1/λ) — a signature as distinctive as Poisson's mean-equals-variance, and one more free consistency check: if a "time between events" dataset has a standard deviation wildly different from its mean, it probably isn't Exponential.

[!] Memorylessness, and the intuition trap it creates

P(X > s+t | X > s) = P(X > t), proved identically to the Geometric case (20.8): P(X>s) = e−λs, so the ratio P(X>s+t)/P(X>s) = e−λt = P(X>t). If a server has been up for three hours with a constant failure rate, its remaining lifetime distribution is identical to a freshly started server's — the three hours of survival provide zero information. This is precisely why "the server hasn't crashed in a while, it's due for one" is a fallacy under a true constant-rate model: memorylessness says the opposite. It's also why the assumption fails hard for anything that wears out — hardware degradation needs a Weibull or similar, not an Exponential.

[retail] Worked: response time, mean 80ms

Exponential(λ = 1/80)text
E[X] = 1/λ = 80ms                    (given directly as the mean)
P(X > 200ms) = e-200/80               = 0.0821    ← 8.2% of requests exceed 200ms
median = ln(2)/λ = 80·ln(2)             = 55.5ms    ← NOT 80ms -- see below

The median (55.5ms) sitting well below the mean (80ms) is the Exponential reproducing chapter 17's core lesson about skewed latency data (17.2) from first principles: the distribution has a long right tail of slow requests pulling the mean up above the typical case, and this is a mathematical certainty for any Exponential, not an artefact of one particular dataset.

20.14 Normal: where it comes from

The Normal is not derived from a simple counting argument the way the discrete distributions were — its justification is a theorem about what happens when many independent effects add together, and that theorem is why it shows up everywhere without anyone assuming it deliberately.

[def] Normal(μ, σ²)

f(x) = 1/(σ√(2π)) · e−(x−μ)²/(2σ²). E[X] = μ and Var(X) = σ² directly by construction — unlike every other distribution in this chapter, the parameters are the mean and variance, not intermediate quantities you derive them from. What deserves derivation instead is why this particular bell shape appears so often.

[→] The Central Limit Theorem, stated precisely

Take any distribution with finite mean μ and finite variance σ² — it can be wildly skewed, discrete, bounded, anything. Draw n independent samples from it and average them. The CLT says:

the theorem itselftext
As n → ∞,   (X̄ - μ) / (σ/√n)   converges in distribution to Normal(0, 1)

Equivalently:  X̄  is approximately Normal(μ, σ²/n)  for large n

The remarkable part is what's absent from the statement: no assumption about the shape of the original distribution. A sum or average of many small independent contributions looks approximately Normal almost regardless of where those contributions came from — which is why measurement errors, aggregated user behaviour, and sums of many small effects all tend toward a bell curve even when no individual effect is remotely bell-shaped. This is also precisely the fact chapter 17 relied on for confidence intervals on a sample mean (17.7), used there without re-deriving it.

[!] What the CLT does not say — the misreading that causes real damage

The CLT is a statement about the distribution of a sample mean, not about the underlying data. Individual request latencies do not become Normal just because you have a lot of them — they stay however skewed they actually are (17.4). It is the average of many latencies that becomes approximately Normal, which is a completely different quantity. Applying a 68-95-99.7 rule (below) directly to raw latency data is exactly the mistake this distinction is meant to prevent, and it's one of the most common statistical errors in production monitoring.

[+] Standardisation: turning any Normal into the one table you memorised

If X ~ Normal(μ, σ²), then Z = (X−μ)/σ is exactly Normal(0,1) — this follows directly from the scaling rules in 20.5: shifting by −μ centres the mean at 0 without touching the variance, and dividing by σ scales the variance by (1/σ)² = 1/σ², taking σ² down to exactly 1. This is why a single standard normal table (or a single scipy call) answers a probability question for every Normal distribution: convert to a z-score first, and the specific μ and σ drop out. Latency of Normal(500ms, 100ms² variance): P(X<650) converts to P(Z<1.5) = 0.9332, and that 1.5 is all the calculation actually needs.

[retail] The 68-95-99.7 rule, and where those numbers come from

±1, ±2, ±3 standard deviationstext
P(μ-1σ < X < μ+1σ) = 0.6827   ← "68%"
P(μ-2σ < X < μ+2σ) = 0.9545   ← "95%"
P(μ-3σ < X < μ+3σ) = 0.9973   ← "99.7%"

These aren't approximations chosen for convenience — they're exact integrals of the standard normal density over those ranges, and they are 17.3's warning made numeric: this rule is only valid for a genuinely (or approximately) Normal variable. Applied to log-normal latency data (17.4), or to a raw skewed metric that hasn't been averaged, these percentages are simply wrong — there is no version of this rule that rescues a non-Normal distribution.

20.15 Approximating one distribution with another

Three of this chapter's distributions are limits or approximations of others. Knowing which approximation applies, and its rule of thumb for validity, is itself an identification skill worth having on top of the individual derivations.

The approximations derived or used in this chapter
ApproximationValidity conditionWhy it works
Binomial → Poisson n large, p small, np = λ moderate. Rule of thumb: n ≥ 20 and p ≤ 0.05. Proved exactly as a limit in 20.10 — not a heuristic, a genuine n→∞ convergence.
Binomial → Normal np ≥ 10 and n(1−p) ≥ 10 — both tails need room to look symmetric. A special case of the CLT: a Binomial is itself a sum of n independent Bernoullis (20.7), so their average trends Normal as n grows.
Hypergeometric → Binomial n/N small (sample is a small fraction of the population), conventionally n/N ≤ 0.05. Shown directly in 20.11: the finite population correction (N−n)/(N−1) → 1 as N grows large relative to n.

[→] The continuity correction, and why skipping it is a real error

Binomial is discrete; Normal is continuous. Approximating P(X=k) for the discrete variable by plugging k directly into the continuous Normal CDF quietly asks the wrong question — a single point has probability exactly 0 under any continuous distribution (20.4). The fix is to treat the discrete value k as if it occupies the continuous interval [k−0.5, k+0.5].

with and without the correctiontext
Binomial(20, 0.5): exact P(X ≤ 10) = 0.5881

Without correction:  P(Z < (10-10)/√5)         = P(Z<0)     = 0.5000   ← visibly wrong
With correction:      P(Z < (10.5-10)/√5)       = P(Z<0.224)  = 0.5885   ← matches closely

The uncorrected version is off by nearly 9 percentage points here, entirely from forgetting that "at most 10" for a discrete variable means "up to but not including 11.5" on the continuous number line the Normal lives on. Always add or subtract 0.5 at the boundary you're evaluating, in the direction that includes the boundary value itself.

[retail] When the rule of thumb actually matters

Binomial(n, 0.03): exact vs Normal-with-correctiontext
n     np     n(1-p)   exact P(X≤np)   normal approx   fit
100    3.0    97.0        0.6472           0.6153       poor  -- np < 10
1000  30.0   970.0        0.5484           0.5369       fine  -- both ≥ 10

At n=100 the np=3 condition fails the rule of thumb, and the approximation error (3.2 points) shows it directly. This is the same shape of mistake as reaching for Poisson when events cluster (20.10) or reaching for CLT-based confidence intervals on too small a sample (17.9): every approximation in probability comes with a stated validity condition, and the condition is not decoration — it's the boundary of where the convenient formula is still telling the truth.

20.16 The five diagnostic questions

Every distribution in this chapter answers a specific combination of five questions. Answering them in order, before reaching for a formula, is the actual skill this chapter has been building toward — the derivations proved the formulas; this section is what tells you which formula a new problem is even asking for.

[→] Ask these in order, on every problem

  1. 1. Discrete count, or continuous measurement? Is the answer an integer (number of failures, number of clicks) or a real number on a continuum (time, distance, amount)? This alone splits the whole chapter into Part B and Part C.
  2. 2. Is there a fixed number of trials, n? "Out of 20 calls" is a fixed n. "Keep going until something happens" has no fixed n — the trial count is itself the random quantity. This is the single biggest fork in the discrete side: fixed n points to Binomial or Hypergeometric; no fixed n points to Geometric, Negative Binomial, or Poisson.
  3. 3. Are trials independent, with replacement (or from an effectively infinite population)? Drawing cards without putting them back, or auditing without replacement, breaks the constant-p assumption every Bernoulli-based distribution needs. This is the question that separates Hypergeometric from everything else.
  4. 4. Counting successes, or waiting for one to happen? "How many defects in this batch" counts occurrences. "How long until a defect" waits for one. The same underlying process produces a counting distribution and a waiting-time distribution as two sides of the same coin — Poisson counts events in a window, Exponential times the gap until the next one (20.13).
  5. 5. Waiting for exactly one occurrence, or for the r-th? "The first success" is Geometric or Exponential. "The fifth success" is Negative Binomial — the direct generalisation proved in 20.9 by summing r Geometrics.

[+] The two questions people skip, and the two distributions they confuse as a result

Question 3 is the one most often skipped, and skipping it is exactly how Hypergeometric problems get answered with a Binomial formula — close enough to look right at large N, measurably wrong at small N (20.11). Question 5 is the second most-skipped, and skipping it is how "first success" problems (Geometric, mean 1/p) get confused with "r-th success" problems (Negative Binomial, mean r/p) — an easy mistake since both describe "waiting" and both involve the same p.

20.17 The identification table

Applying the five questions in sequence sorts every distribution in this chapter into a unique cell. This table is the compressed version — use it to check a decision you already reasoned through with 20.16, not as a substitute for reasoning through it.

Nine distributions sorted by discrete/continuous, fixed-n, replacement, and counting-vs-waiting
Distribution Discrete/continuous Fixed n? With replacement? Counts or waits? Signal phrase
Bernoulli Discrete n=1 Counts (0 or 1) "a single trial"
Binomial Discrete Yes, fixed n Yes / infinite pop. Counts successes "out of n", "in a sample of"
Hypergeometric Discrete Yes, fixed n No replacement Counts successes "without replacement", "from a batch of"
Geometric Discrete No, unbounded Yes Waits (for the 1st) "trials until the first"
Negative Binomial Discrete No, unbounded Yes Waits (for the r-th) "trials until the r-th"
Poisson Discrete No fixed n; a rate instead Counts events in a window "events per", "rate of", "on average N per"
Uniform Continuous Neither — flat density "equally likely anywhere between"
Exponential Continuous Waits (for the 1st event) "time until", "time between", constant hazard
Normal Continuous Neither — a sum/average of many effects "approximately", "measurement error", or invoked via the CLT

[!] The table identifies a family; the parameters still take reasoning

Landing on "this is Poisson" doesn't yet tell you λ. Landing on "this is Binomial" doesn't yet tell you whether n is the number of users, the number of requests, or the number of days — that requires re-reading the problem for what's actually being counted. The table narrows nine possibilities to one; it doesn't extract the numbers for you.

20.18 Distributions in disguise

Some of the most useful facts about these distributions are relationships between them — a problem that looks unfamiliar is often a familiar distribution wearing a different description.

Relationships worth recognising on sight
If you see…It's really…
A sum of n independent Bernoulli(p) variables Binomial(n, p) — proved directly in 19.7.
A sum of r independent Geometric(p) variables Negative Binomial(r, p) — proved directly in 19.9.
A sum of n independent Exponential(λ) variables Gamma(n, λ) — the continuous analogue of the Geometric-to-Negative-Binomial step, same shape of argument, not derived in this chapter.
The minimum of independent Exponential(λ1), Exponential(λ2), … Exponential(λ12+…) — whichever of several independent constant-rate processes fires first is itself constant-rate, at the summed rate. Useful for "time until the first of several independent failure modes."
Binomial with n huge and p tiny Approximately Poisson(np) — the exact limit derived in 19.10.
Binomial with np and n(1−p) both ≥ 10 Approximately Normal(np, np(1−p)) — a special case of the CLT, since Binomial is itself a sum of n Bernoullis (20.15).
Hypergeometric with n/N small Approximately Binomial(n, K/N) — removing items from a huge population barely changes the odds for what's left (20.15).
A sample mean or sample proportion of anything, for large n Approximately Normal, by the CLT (20.14) — regardless of what the underlying individual values look like.

[+] Why "sum of independent copies" is worth checking first, always

Four of the eight rows above are some version of "a sum of independent copies of a simpler distribution." That's not a coincidence — it's the same technique from 20.9's box on decomposition, applied at the level of recognising whole distributions rather than deriving formulas. Before assuming a problem needs an unfamiliar distribution, ask whether the quantity described is actually a sum, a minimum, or a limit of something already in this chapter.

20.19 Traps and trick questions

Phrasing that misleads, and the question from 20.16 that resolves it
The trapWhy it's misleadingResolve with
"20 customers, 3% return rate" — sounds like Binomial If the 20 are drawn from a small finite pool of recent orders rather than treated as independent samples from a large population, it may actually be Hypergeometric. Question 3: is there really replacement, or an effectively infinite population?
"Average of 5 requests per second" — assumed Poisson automatically Poisson requires independence between arrivals. Retried requests after a timeout, or correlated user behaviour, break that assumption even though the average rate is genuinely 5/second. The three conditions under 20.10's warning box: many opportunities, each unlikely, independent.
"How many trials until the first success" vs "how many failures before the first success" These differ by exactly 1 in the mean (1/p vs (1−p)/p) and it's easy to answer the wrong one, particularly since some libraries (including scipy's nbinom) parametrise by failures, not total trials. Re-read for whether the success itself is included in the count (20.8's convention note).
"Time between events" — assumed Normal because it's continuous Continuous does not imply Normal. Waiting times are essentially always right-skewed and frequently Exponential, never symmetric around the mean the way Normal is. Question 4: counting, or waiting? Waiting times need Exponential-family reasoning, not automatic Normality.
"Mean and variance are equal in this dataset" — assumed proof of Poisson Mean equalling variance is necessary for Poisson (20.10) but not sufficient — it's a quick screen, not a proof. Independence and the no-clustering condition still need separate justification. 20.10's warning box: check independence and clustering directly, don't rely on one summary statistic.
"Large sample, so use the Normal approximation" — without checking np and n(1−p) Large n alone isn't the condition. n=10,000 with p=0.0001 still has np=1, and the Normal approximation to that Binomial is poor regardless of how large n is. 20.15's rule of thumb: both np ≥ 10 and n(1−p) ≥ 10, not n alone.

[!] The meta-trap: pattern-matching on keywords instead of running 20.16

Every row above is a case where a surface keyword ("out of n", "rate of", "time until") pointed at the wrong distribution because a condition underneath it was silently violated. The five questions in 20.16 exist specifically to catch this — they force you to check independence, replacement, and fixed-vs-unbounded n explicitly rather than pattern-matching on phrasing, which is exactly what these traps are designed to exploit.

20.20 Ten worked identifications

Each of these runs the five questions from 20.16 explicitly before touching a formula. Reading the identification step is more valuable than checking the number — the number is easy once the distribution is right.

[1] "Of 15 marketing emails sent, each independently has an 8% chance of being flagged as spam. Find P(exactly 2 flagged)."

Identify: discrete (Q1) · fixed n=15 (Q2) · independent, effectively infinite pool of possible emails (Q3) · counting flagged emails, not waiting (Q4) → Binomial(15, 0.08).

P(X=2) = C(15,2)·0.08²·0.92¹³ = 0.2273

[2] "A batch of 40 units contains 6 defective. Inspect 4 units without returning them. Find P(zero defective in the sample)."

Identify: discrete · fixed n=4 · explicitly without replacement from a finite population of 40 (Q3 fails the independence/replacement check) → Hypergeometric(N=40, K=6, n=4), not Binomial.

P(X=0) = C(6,0)·C(34,4) / C(40,4) = 0.5075

[3] "A salesperson closes 12% of cold calls, independently. Find P(the first close happens on exactly the 6th call)."

Identify: discrete · no fixed n, calling continues until success (Q2) · independent trials (Q3) · waiting for exactly the first success (Q5) → Geometric(0.12).

P(X=6) = (0.88)⁵·0.12 = 0.0633

[4] "A support queue receives a mean of 2.5 tickets per hour. Find P(5 or more tickets in the next hour)."

Identify: discrete · no fixed n, a rate instead (Q2) · counting occurrences in a fixed window, not waiting (Q4) → Poisson(2.5).

P(X≥5) = 1 − P(X≤4) = 0.1088

[5] "A recruiter makes independent calls with a 25% success rate and needs 3 successful hires. Find the expected number of calls."

Identify: discrete · no fixed n (Q2) · independent (Q3) · waiting, but for the 3rd success specifically, not the first (Q5) → Negative Binomial(r=3, p=0.25), total-trials convention.

E[X] = r/p = 3/0.25 = 12 calls expected

[6] "Requests to a service arrive with a mean gap of 4 minutes between them. Find P(the next request arrives within 2 minutes)."

Identify: continuous (Q1) · time until the next event, not a count (Q4) · constant average gap implies constant rate → Exponential(λ = 1/4).

P(X<2) = 1 − e−2/4 = 0.3935

[7] "500 independent transactions, each with a 4% fraud rate. Find P(at most 25 fraudulent), using an approximation."

Identify: discrete, fixed n=500, independent → exactly Binomial(500, 0.04) by the same reasoning as example 1 — but the question asks for an approximation, and np = 20, n(1−p) = 480, both comfortably ≥ 10 (20.15) → Normal(20, 20.2) with the continuity correction is appropriate here.

Exact: 0.8924 Normal+cc: P(Z<(25.5−20)/√20.2) = 0.8953

[8] "A cache lookup takes anywhere from 10ms to 50ms with no value more likely than another. Find P(a lookup exceeds 40ms)."

Identify: continuous · explicitly stated as equally likely across a range, no waiting or counting involved (Q4 doesn't apply — this is a flat density, not a process) → Uniform(10, 50).

P(X>40) = (50−40)/(50−10) = 0.25

[9] "One user either converts or doesn't, with probability p. Find Var(X)."

Identify: discrete · n=1 explicitly, a single trial (Q2) → Bernoulli(p), the n=1 special case of Binomial — not worth invoking the full Binomial machinery for.

Var(X) = p(1−p)

[10] "Server A fails independently with a Poisson(2) rate per hour and server B with a Poisson(3) rate per hour. Find P(exactly 4 combined failures in an hour)."

Identify: the disguise from 20.18 — a sum of two independent Poisson variables is itself Poisson, with rates adding (this follows the same "sum of independent copies" logic as 20.9's Negative Binomial, though the summed-rate result itself isn't derived in this chapter) → Poisson(2+3) = Poisson(5), not two separate distributions combined some other way.

P(X=4) = e−554/4! = 0.1755

20.21 The formula sheet

Everything derived in Parts B and C, collected in one place. Use it as a check after reasoning through 20.16 and the derivation itself — a formula recalled without the argument behind it is exactly the failure mode 20.1 opened with.

Every distribution derived in this chapter
Distribution PMF / PDF E[X] Var(X) Derived in
Bernoulli(p) P(1)=p, P(0)=1−p p p(1−p) 20.6
Binomial(n,p) C(n,k)pk(1−p)n−k np np(1−p) 20.7
Geometric(p) (1−p)k−1p 1/p (1−p)/p² 20.8
Neg. Binomial(r,p)† C(k−1,r−1)pr(1−p)k−r r/p r(1−p)/p² 20.9
Poisson(λ) e−λλk/k! λ λ 20.10
Hypergeometric(N,K,n) C(K,k)C(N−K,n−k)/C(N,n) nK/N n·(K/N)(1−K/N)·(N−n)/(N−1) 20.11
Uniform(a,b) 1/(b−a) (a+b)/2 (b−a)²/12 20.12
Exponential(λ) λe−λx 1/λ 1/λ² 20.13
Normal(μ,σ²) by construction μ σ² 20.14

† Negative Binomial mean/variance shown for the total-trials-until-r-successes convention used throughout this chapter (20.9). Libraries that instead count failures before the r-th success give E[X] = r(1−p)/p — check the convention before quoting a number from a tool.

20.22 Key takeaways

  1. Derive, don't just memorise. A remembered argument lets you rebuild a forgotten formula and tells you when it stops applying; a memorised formula gives you neither.
  2. Three axioms generate almost everything: non-negativity, normalisation, and countable additivity. The complement rule and inclusion-exclusion are one-line consequences, not separate facts.
  3. Independence means P(A∩B)=P(A)P(B), which follows from substituting the definition of independence into the multiplication rule — and every product of probabilities across trials in this chapter depends on it.
  4. Linearity of expectation needs no independence at all. E[X+Y]=E[X]+E[Y] always — which is why Binomial's mean (np) is three lines even though the trials are correlated through the fixed total.
  5. Variance only adds for independent terms. That's the one place Binomial's derivation genuinely needs independence, and it's exactly where correlated trials break the formula.
  6. Var(X) = E[X²]−E[X]² converts every hard derivation into "find one more moment." Nearly every variance in this chapter uses this identity as its final step.
  7. Decompose into sums of simpler, already-solved pieces before touching a PMF. Binomial as a sum of Bernoullis and Negative Binomial as a sum of Geometrics both skip the hard sum entirely.
  8. Geometric and Exponential are memoryless — past waiting provides zero information about future waiting. It's the only discrete/continuous pair in this chapter with that property, and it's precisely what makes "it's due for a failure" a fallacy under a true constant-rate model.
  9. Poisson is what Binomial becomes as n→∞, p→0, np=λ fixed — and e−λ is the ordinary calculus limit (1+x/n)n→ex, not a special constant.
  10. Mean equals variance for Poisson; mean equals standard deviation for Exponential. Both are free diagnostic checks against real data before trusting either model.
  11. Hypergeometric's variance carries a finite population correction, (N−n)/(N−1), always ≤1 — sampling without replacement is more informative, and that's what the shrinkage measures.
  12. The Central Limit Theorem is about the sample mean, not the underlying data. Individual latencies stay skewed forever; it's their average that becomes approximately Normal.
  13. Standardising with Z=(X−μ)/σ works because of the scaling rules in 20.5 — shift kills the mean's offset, divide-by-σ forces the variance to exactly 1.
  14. The 68-95-99.7 rule is exact for Normal and simply wrong for anything else, including raw skewed metrics that haven't been averaged.
  15. Continuity correction (±0.5) matters when using a Normal to approximate a discrete distribution — skipping it produced an 8.8-point error in the worked example.
  16. Every approximation has a stated validity condition, and it is not decoration: np≥10 and n(1−p)≥10 for Normal, n large and p small for Poisson, n/N small for Binomial-from-Hypergeometric.
  17. Run the five diagnostic questions before reaching for a formula: discrete or continuous, fixed n or not, with or without replacement, counting or waiting, first occurrence or the r-th.
  18. Question 3 (replacement) and question 5 (which occurrence) are the two most commonly skipped — and skipping them is exactly how Hypergeometric gets mistaken for Binomial, and Geometric for Negative Binomial.
  19. A keyword is not an identification. "Rate of," "out of n," and "time until" all have failure modes where the surface phrasing points to the wrong distribution because an underlying condition was silently violated.

[i] Vocabulary check

You should be able to explain: sample space, event, the three probability axioms, conditional probability, independence, random variable, PMF, PDF, CDF, expectation, linearity of expectation, variance, the computational variance identity, factorial moment, Bernoulli, Binomial, Geometric, Negative Binomial, Poisson, Hypergeometric, Uniform, Exponential, Normal, memorylessness, the Central Limit Theorem, standardisation and the z-score, the 68-95-99.7 rule, continuity correction, and the finite population correction.

20.23 Interview drills

Probability questions in an interview are testing whether you can identify the right distribution under pressure and defend a derivation, not whether you have a table memorised. The strongest answers show the identification reasoning explicitly.

1. Derive the mean and variance of a Bernoulli random variable.

X takes value 1 with probability p and 0 with probability 1−p. By definition, E[X] = 0·(1−p) + 1·p = p. For the variance I use the computational identity Var(X) = E[X²]−E[X]² rather than the definition directly, because it's usually easier.

Since X only takes values 0 and 1, X² equals X exactly — 0²=0 and 1²=1 — so E[X²] = E[X] = p. That gives Var(X) = p − p² = p(1−p). It's maximised at p=0.5, which makes sense: a fair coin is the most unpredictable single trial, and certainty at p=0 or p=1 gives zero variance.

2. Why does E[X+Y]=E[X]+E[Y] hold even when X and Y are dependent?

Because the proof never uses independence. Writing out E[X+Y] as a sum over the joint distribution, you can split (x+y)·P(X=x,Y=y) into separate sums and regroup them. Summing P(X=x,Y=y) over every value of y just recovers the marginal P(X=x) by definition — that's true whether or not X and Y are related.

This is why it's the tool of choice for Binomial's mean: I write X as a sum of n Bernoulli indicators, one per trial, and the mean is np in three lines even though the indicators are technically dependent through the fixed total count n. Variance doesn't have this property — Var(X+Y) needs a covariance term that only vanishes under independence, which is exactly where Binomial's variance derivation does need the trials to be independent.

3. A batch of 100 items has 8 defective. You inspect 5 without replacement. What distribution, and why not Binomial?

Hypergeometric(N=100, K=8, n=5). Binomial requires each trial to have the same success probability, which only holds if you sample with replacement from an effectively infinite population. Here, every item you inspect changes the composition of what's left — after drawing one defective item, only 7 remain among 99, so the probability genuinely shifts trial to trial.

The means actually coincide — both give n·K/N — but the variances don't: Hypergeometric's variance is the Binomial variance times a finite population correction, (N−n)/(N−1), which is always at most 1. Sampling without replacement gives more information, so the variance shrinks. As N grows large relative to n that correction goes to 1 and Hypergeometric converges to Binomial, which is why treating a small sample from a huge population as Binomial is usually fine, and treating a small sample from a small population that way isn't.

4. Derive the Poisson PMF as a limit of the Binomial.

Split one interval into n tiny slices, each an independent Bernoulli trial with success probability p=λ/n, small enough that at most one event lands per slice. As n→∞, the count of events is Binomial(n, λ/n), and its mean stays fixed at n·(λ/n)=λ regardless of how fine the slicing gets, which is exactly the property you want for a constant rate.

Taking the limit of the Binomial PMF splits into three pieces: n!/[(n−k)!nk] goes to 1 because it's a product of k terms each individually approaching 1; (1−λ/n)n goes to e−λ by the standard calculus limit that defines e; and (1−λ/n)−k goes to 1 because k is fixed while n grows. Multiplying the surviving pieces with the untouched λk/k! gives e−λλk/k! exactly. The e−λ isn't a special constant — it falls out of that one calculus limit.

5. What's the difference between Geometric and Negative Binomial, and how do you avoid confusing them?

Geometric is trials until the first success; Negative Binomial is trials until the r-th success. Geometric is actually the r=1 special case — plugging r=1 into Negative Binomial's mean r/p and variance r(1−p)/p² collapses exactly to Geometric's 1/p and (1−p)/p², which is a useful sanity check on the general formula.

The cleanest way to derive Negative Binomial's moments is to recognise it as a sum of r independent Geometric waiting times — the wait for the first success, then, once that resets, the wait for the next, r times over. Memorylessness is what guarantees each of those waits restarts fresh and is independent of the others, so linearity gives the mean immediately and independence lets the variances add. The practical trap is that some libraries, including scipy's nbinom, parametrise by number of failures rather than total trials, which shifts the mean by exactly r — worth checking before trusting a library's output.

6. Explain memorylessness and give a case where assuming it is wrong.

A distribution is memoryless if P(X>s+t | X>s) = P(X>t) — knowing you've already waited s gives you no information about how much longer you'll wait. Exponential and Geometric are the only two distributions in the standard toolkit with this property, and it follows directly from their survival functions being pure exponentials in the waiting variable: the ratio of survival probabilities collapses the s term entirely.

It's wrong for anything that wears out. Hardware degradation is the classic counterexample — a component that's survived five years is often more likely to fail soon than a brand-new one, which is the opposite of memoryless and needs something like a Weibull distribution with an increasing hazard rate instead. The practical tell is the phrase "it's due for a failure," which is only meaningful under a non-memoryless model; under a true constant-rate Exponential process, it's a flat-out fallacy.

7. State the Central Limit Theorem precisely, and describe a common misapplication.

For any distribution with finite mean μ and variance σ², the standardised sample mean (X̄−μ)/(σ/√n) converges to a standard Normal as n grows, regardless of the shape of the original distribution. Equivalently, the sample mean itself is approximately Normal(μ, σ²/n) for large n.

The misapplication I see constantly is applying Normal-based rules directly to raw, unaveraged data. Individual request latencies stay skewed no matter how many you collect — the CLT says nothing about them. It's the average of many latencies that becomes approximately Normal. Using the 68-95-99.7 rule on raw latency values, instead of on a sample mean or a sum, is exactly this mistake, and it produces confidently wrong percentages because the underlying assumption was never met.

8. When can you approximate a Binomial with a Normal, and what goes wrong if you skip the continuity correction?

When both np and n(1−p) are at least about 10 — both tails need enough room to look roughly symmetric. It's a special case of the CLT, since a Binomial is itself a sum of n independent Bernoullis, and the same theorem that makes any sample mean approximately Normal applies to that sum.

Skipping the continuity correction treats a discrete point as having zero width on a continuous scale, which understates one-sided cumulative probabilities. In a Binomial(20, 0.5) example, the exact P(X≤10) is 0.588; converting the boundary directly gives P(Z<0) = 0.500, a nine-point error, while treating the discrete value 10 as occupying the continuous interval up to 11.5 gives P(Z<0.224) = 0.589, matching almost exactly. The fix is always to shift the boundary by 0.5 in the direction that includes it.

9. A dataset of event counts has sample mean 4.1 and sample variance 4.05. Is it Poisson?

Mean and variance being close is consistent with Poisson — it's a real derived property, since Poisson's mean and variance are both exactly λ — but it's necessary, not sufficient. I wouldn't call this proof on its own.

I'd still check the actual assumptions behind the Binomial-limit derivation: independence between events, and no clustering. If these are server requests, I'd check for retry storms or correlated user behaviour, which would violate independence while still potentially leaving mean and variance close by coincidence. Conversely, if the sample variance were far above the mean — overdispersion — that alone would be enough to rule Poisson out and point toward something like a Negative Binomial instead, which can accommodate the extra spread.

10. Given a word problem, walk through how you'd identify the correct distribution.

I run five questions in order rather than pattern-matching on keywords. First, discrete or continuous — is the answer a count or a measurement. Second, is there a fixed number of trials n, or does the process run until something happens. Third, are trials independent with replacement, or from an effectively infinite population — this is the one people skip most, and skipping it is how Hypergeometric problems get mistaken for Binomial.

Fourth, is the problem counting occurrences or waiting for one to occur — Poisson counts, Exponential waits, and they describe the same underlying process from two different angles. Fifth, if it's waiting, is it for the first occurrence or the r-th — Geometric versus Negative Binomial, the other commonly skipped distinction. I only reach for a formula after these five are answered, because a surface phrase like "out of n" or "rate of" can point to the wrong distribution if an underlying condition is silently violated.

11. Derive the variance of the Uniform(a,b) distribution.

f(x) = 1/(b−a) on [a,b]. E[X] = ∫x·f(x)dx = 1/(b−a)·[x²/2] from a to b, which simplifies using the difference of squares b²−a² = (b−a)(b+a), so the (b−a) cancels and leaves (a+b)/2 — the interval's midpoint, exactly as intuition demands for a flat density.

For E[X²], the same integral with x² gives (a²+ab+b²)/3 using the sum-of-cubes factorisation. Subtracting E[X]² and combining over a common denominator of 12 gives (b−a)²/12 — I usually sanity-check this with a=0, b=1, where it should reduce to 1/12, a number worth just remembering. I treat this as the baseline variance formula in probability: it's "spread with no preference at all," and every other continuous distribution's variance gets implicitly compared against it.

12. Two independent servers fail with Poisson(2) and Poisson(3) rates per hour. What's the distribution of combined failures, and how do you know?

Poisson(5). Sums of independent Poisson variables are themselves Poisson, with the rates adding — it's the same "sum of independent copies" pattern I'd use for Binomial as a sum of Bernoullis or Negative Binomial as a sum of Geometrics, applied at the level of recognising the combined distribution rather than deriving a new formula from scratch.

I'd sanity-check this against the process interpretation: two independent constant-rate processes running simultaneously are indistinguishable, from the outside, from one process running at the combined rate — there's no way to tell "two rate-2-and-3 processes" from "one rate-5 process" just by counting total events. So P(exactly 4 combined failures) = e−554/4!, not some separate calculation combining the two original distributions term by term.

Where this leaves you

Chapter 17 used confidence intervals, p-values, and the bootstrap as tools. This chapter opened every one of those tools up: why a sample mean is approximately Normal regardless of the underlying data, why a Poisson process has the variance it has, and why a formula that looks unfamiliar is often a familiar distribution wearing different words.

That's also the last new mathematical machinery in the course. What remains is judgement — recognising which of these tools a real problem needs, which chapter 17's statistics and this chapter's derivations were both building toward.