Everything measured in machine learning is a sample average standing in for an expectation. That substitution is licensed by exactly two theorems, and between them they answer the two questions that matter: does the average converge? (the law of large numbers: yes) and how wrong is it right now? (the central limit theorem: Gaussianly, shrinking as ). This lesson proves the first, demonstrates the second until you believe it in your bones, and then collects the tax bill from every corner of the curriculum.
The law of large numbers, via Chebyshev
For i.i.d. draws with mean and variance , last lesson gave the average’s moments: , . Chebyshev’s inequality — for any random variable, , provable in three lines — then turns shrinking variance into shrinking miss-probability:
That is the (weak) law of large numbers: sample means converge to the true mean. It is why empirical risk approaches true risk, why Monte Carlo works at all, and why a casino’s income is deterministic while every gambler’s night is random — the house plays , the gambler plays 1. Sharper tools exist for bounded variables — Hoeffding’s inequality gives exponentially small miss probability, , and is the standard engine behind generalization bounds — but Chebyshev’s virtue is that it needs nothing but a finite variance, and its already displays the module’s favourite ratio.
The central limit theorem: the shape of the error
LLN says the error vanishes; the CLT says something far stranger — the error has a universal shape. If are i.i.d. with mean and finite variance , then the standardized mean
Average enough of anything (with finite variance) and the fluctuations become Gaussian. This is why the bell curve is everywhere: not because nature loves it, but because nature loves sums — measurement errors, biological traits, aggregated returns are all totals of many small contributions. It is also why Gauss’s error model for least squares (next lesson’s reveal) was such a defensible bet. Watch universality happen, because reading about it does not compare:
At n = 2, the exponential’s skew is written all over the histogram — the green normal curve fits badly and the skewness readout says so. Slide n upward and watch the histogram pour itself into the bell: by n ≈ 30 the fit is respectable, by n = 100 it is uncanny. Now the instructive failures: the bimodal base loses its two humps astonishingly fast (averaging destroys multimodality), but Bernoulli(0.15) resists — at small n the histogram is a comb of discrete spikes, and normality needs much larger n (the np ≥ 10-ish folklore you discovered in last lesson’s exercise, now explained: convergence speed depends on skewness — Berry–Esseen makes that precise). “n = 30 makes everything normal” is a rule of thumb, not a theorem, and this widget shows you exactly when it lies.
The 1/√n tax, itemized
The CLT’s practical content is the standard error: the typical error of an average is , so every additional digit of accuracy costs 100× the data. This one scaling law has been quietly running the entire curriculum — collect the receipts:
- Test-set metrics (Evaluation lesson): accuracy on samples carries SE — the error bar that made 0.5% “improvements” on small benchmarks meaningless, now with its theorem attached. The 95% interval is just the CLT’s Gaussian quantiles.
- Minibatch gradients (SGD lesson): a batch of samples estimates the true gradient with noise — the reason batch size bought noise reduction at a sublinear exchange rate, and the reason the noise ball had the radius it had.
- Monte Carlo everything (RL track): a policy’s value estimated from rollouts, a win-rate from judged pairs, self-consistency’s vote from samples — all estimators, all priced by this lesson.
- A/B tests and cohort comparisons: detecting an effect of size needs per arm — the sample-size arithmetic every product experiment lives and dies by.
The flip side is a warning label: the CLT needs finite variance and weak dependence. Heavy-tailed quantities (wealth, viral counts, catastrophic losses) can have effectively infinite variance — their averages converge slowly or to stable non-Gaussian laws, and reasoning silently lies. Correlated samples (time series, users within a cohort, the forest lesson’s ) shrink the effective . When an error bar looks too good, one of these two assumptions is usually the reason.
import numpy as np
rng = np.random.default_rng(1)
# The 1/√n law, measured: SE of the mean of exponential(1) draws
for n in [10, 100, 1000, 10000]:
means = rng.exponential(1.0, size=(20_000, n)).mean(axis=1)
print(n, means.std(), 1 / np.sqrt(n)) # empirical SE ≈ σ/√n (σ = 1)
Exercises
Work these before the next lesson
- Prove Chebyshev from Markov’s inequality ( for nonnegative ), and Markov itself from the definition of expectation. Then assemble the weak LLN.
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, ch. 10 — LLN and CLT with the stories kept on.
- W. Hoeffding, “Probability inequalities for sums of bounded random variables”, JASA 1963.
- A. C. Berry (1941) / C.-G. Esseen (1942) — the CLT convergence-rate theorem behind the widget’s observations.
- N. N. Taleb, Statistical Consequences of Fat Tails, 2020 — the failure modes, argued at length.