Where this came from. Probability began in 1654 as a gambling dispute — how to split an interrupted game’s pot fairly — settled in letters between Pascal and Fermat that invented expected value along the way. It took a century for Bayes to reverse evidence back to causes, another for Gauss to give measurement error a distribution, and until 1933 for Kolmogorov to give the whole subject axioms. Respectable mathematics did not “do” uncertainty; every formula in this module was a scandal first. The story is in How the mathematics was forged; the machinery starts here.
Machine learning is a probability discipline wearing an optimization costume. A model’s output is a conditional distribution; a loss is a negative log-likelihood in disguise (that reveal comes in lesson 3); every evaluation metric is an expectation estimated from samples. This module builds the probability a practitioner actually leans on daily — not measure theory, but fluency: the operators, the standard distributions, and above all conditioning, which is what the word “prediction” formally means.
Random variables, and the two operators that matter
A random variable assigns a number to each outcome of a random process; it is described by its distribution — a pmf for discrete values, a pdf for continuous ones (heights of a density, not probabilities themselves: only areas are probabilities — the classic beginner trap, since densities happily exceed 1). Two functionals summarize a distribution, and they behave like operators with algebra worth memorizing:
The rules — provable in two lines each, used ten thousand times each:
- Linearity of expectation: — unconditionally, independence not required. The single most-used fact in this curriculum’s proofs (the unbiasedness of minibatch gradients was exactly this).
- Variance algebra: , and only under independence (in general add — forgetting the covariance term is how the forest lesson’s floor surprises people).
- The consequence that runs statistics: an average of i.i.d. draws has and — the standard-error law, formally born here and starring in the next lesson.
The zoo, and how to choose from it
Distributions are modeling assumptions with names. Choosing one is asserting a data-generating story, and each standard story earns its slot:
| Distribution | The story it tells | Mean / Variance | Where this curriculum uses it |
|---|---|---|---|
| Bernoulli() | one yes/no event | / | classification labels; cross-entropy’s origin |
| Binomial() | count of yes in tries | / | vote-sim & judge widgets (RL track) |
| Poisson() | counts of rare events in a window | / | arrivals, defects, word counts |
| Gaussian() | sum of many small effects | / | noise models; least squares (lesson 3) |
| Exponential() | waiting time, memoryless | / | durations, survival, queues |
Play deliberately: on the Binomial, push p toward 0.05 and watch symmetry break (the Gaussian resemblance at p = 0.5 is the next lesson’s CLT foreshadowed — and its failure at extreme p with small n is why rare-event problems need care); on the Poisson, confirm mean = variance as λ moves (a testable fingerprint — count data with variance ≫ mean is “overdispersed” and the Poisson story is wrong); on the Exponential, notice the mode is at zero no matter the parameter — if your waiting-time data has a hump away from zero, memorylessness is already refuted. Reading a distribution’s SHAPE as a claim about the world is the skill; the sliders are for calibrating it.
Joint, marginal, conditional: the grammar of “given”
Real problems involve several variables, and three constructions relate them. The joint says everything; the marginal integrates the rest away; the conditional re-normalizes a slice:
Conditioning is the central operation of machine learning — the whole discipline of supervised learning is the art of estimating : the logistic model was , a language model is , and “prediction” means computing a conditional. Two structural facts complete the grammar. Independence ( — knowing one tells nothing about the other) is the assumption behind every “i.i.d.” in this curriculum, and its conditional cousin — — is subtler and stronger machinery: Naive Bayes assumes features independent given the class; Markov chains assume the future independent of the past given the present (the Markov property that carried the entire RL track). And the chain rule factorizes any joint into conditionals — the identity that makes autoregressive language models possible at all.
The inversion of conditioning — from — is Bayes’ theorem, which gets lesson 4 to itself. Here, just the shape of the trap it resolves: and differ by the base rate, and confusing them (the prosecutor’s fallacy) is possibly the most consequential statistical error civilians make.
Expectation as the universal interface
A closing reframe that pays rent across the curriculum: nearly every quantity ML optimizes or reports is an expectation —
— and none of them can be computed exactly, because the underlying distribution is the world. Everything is estimated by sample averages, which is why the next lesson — on what sample averages do and how fast — is arguably the load-bearing wall of the entire practice: it prices every training batch, every test set, and every Monte Carlo rollout you will ever run.
import numpy as np
rng = np.random.default_rng(0)
# linearity needs no independence; variance addition does
x = rng.normal(2.0, 1.0, 200_000)
y = 0.8 * x + rng.normal(0, 0.5, 200_000) # correlated with x
print(np.mean(x + y), np.mean(x) + np.mean(y)) # equal (linearity)
print(np.var(x + y), np.var(x) + np.var(y)) # NOT equal (covariance ≠ 0)
print(np.var(x + y), np.var(x) + np.var(y) + 2 * np.cov(x, y)[0, 1]) # fixed
Exercises
Work these before the next lesson
- Prove and linearity of expectation for the discrete case. Then derive Bernoulli’s variance and explain why it peaks at in one intuitive sentence.
Solution
Worked solutions are part of Premium — unlock all of them for £5/month →
- 5 more exercises — each with a worked solution — are part of Premium. Unlock everything for £5/month →
References
- J. Blitzstein & J. Hwang, Introduction to Probability, 2nd ed. — the best story-first treatment; free lectures (Stat 110) accompany it.
- L. Wasserman, All of Statistics, ch. 1–3 — the compressed graduate version of this module.
- D. MacKay, Information Theory, Inference, and Learning Algorithms, ch. 2 — probability as the language of inference, free online.