SafeZone AI Learn
Learn/ Mathematical Foundations/ Probability & Statistical Inference · lesson 2 of 9

The law of large numbers and the CLT

Why averages settle, why their errors are bell-shaped no matter what you average, and the 1/√n law that prices every batch, benchmark and Monte Carlo estimate you will ever run — watched happening, live.

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 1/n1/\sqrt{n}). This lesson proves the first, demonstrates the second until you believe it in your bones, and then collects the 1/n1/\sqrt n tax bill from every corner of the curriculum.

The law of large numbers, via Chebyshev

For i.i.d. draws with mean μ\mu and variance σ2\sigma^2, last lesson gave the average’s moments: E[Xˉn]=μ\mathbb{E}[\bar X_n] = \mu, Var[Xˉn]=σ2/n\operatorname{Var}[\bar X_n] = \sigma^2/n. Chebyshev’s inequality — for any random variable, Pr(YEYε)Var[Y]/ε2\Pr(\lvert Y - \mathbb{E}Y\rvert \ge \varepsilon) \le \operatorname{Var}[Y]/\varepsilon^2, provable in three lines — then turns shrinking variance into shrinking miss-probability:

Pr(Xˉnμε)    σ2nε2  n  0.\Pr\big( \lvert \bar X_n - \mu \rvert \ge \varepsilon \big) \;\le\; \frac{\sigma^2}{n \varepsilon^2} \;\xrightarrow{\,n \to \infty\,}\; 0 .

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 nn, the gambler plays 1. Sharper tools exist for bounded variables — Hoeffding’s inequality gives exponentially small miss probability, 2exp(2nε2)2\exp(-2n\varepsilon^2), and is the standard engine behind generalization bounds — but Chebyshev’s virtue is that it needs nothing but a finite variance, and its σ2/n\sigma^2/n 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 XiX_i are i.i.d. with mean μ\mu and finite variance σ2\sigma^2, then the standardized mean

Zn=Xˉnμσ/n    d    N(0,1)— regardless of the distribution of X.Z_n = \frac{\bar X_n - \mu}{\sigma / \sqrt{n}} \;\xrightarrow{\;d\;}\; \mathcal{N}(0, 1) \qquad\text{— regardless of the distribution of } X.

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 σ/n\sigma/\sqrt{n}, 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 mm samples carries SE p(1p)/m\sqrt{p(1-p)/m} — the error bar that made 0.5% “improvements” on small benchmarks meaningless, now with its theorem attached. The 95% interval ±1.96SE\pm 1.96\,\mathrm{SE} is just the CLT’s Gaussian quantiles.
  • Minibatch gradients (SGD lesson): a batch of bb samples estimates the true gradient with noise 1/b\propto 1/\sqrt{b} — 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 nn rollouts, a win-rate from nn judged pairs, self-consistency’s vote from kk samples — all σ/n\sigma/\sqrt{n} estimators, all priced by this lesson.
  • A/B tests and cohort comparisons: detecting an effect of size δ\delta needs nσ2/δ2n \sim \sigma^2/\delta^2 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 σ/n\sigma/\sqrt n reasoning silently lies. Correlated samples (time series, users within a cohort, the forest lesson’s ρ\rho) shrink the effective nn. 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

  1. Prove Chebyshev from Markov’s inequality (Pr(Ya)E[Y]/a\Pr(Y \ge a) \le \mathbb{E}[Y]/a for nonnegative YY), and Markov itself from the definition of expectation. Then assemble the weak LLN.
    Solution

    Worked solutions are part of Premiumunlock all of them for £5/month →

  2. 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.