The law of large numbers
Why averages settle down: the weak law via Chebyshev's inequality, the strong law, convergence in probability and almost surely, empirical risk as a sample mean, and the cases where averages fail to converge.
Where the average sits
The topic Inequalities and concentration bounded how far an average can stray from its mean. For the sample mean, Chebyshev's inequality gave
and Hoeffding's inequality gave a far smaller bound for bounded variables. Each bound is about one fixed . What is still missing is the limit: what happens to the average itself as the data keep coming. That is the law of large numbers.
The setup for the whole topic: are i.i.d. with mean and, where needed, variance . The sample mean is
Two facts from earlier topics say where it sits and how widely it spreads. By linearity, . Variances of independent variables add (Joint distributions and independence), and the factor comes out of a variance squared, so
The centre stays put while the variance shrinks like , and the standard deviation like .
The running example is a classifier that errs on each test example independently with probability . Let if example is misclassified and otherwise. Then is the error rate measured on a test set of size , with and .
The weak law
The weak law of large numbers. If are i.i.d. with mean , then for every
With a finite variance the proof takes one line. The sample mean has mean and variance , so Chebyshev's inequality bounds the left side by . Hold fixed and let grow: the bound goes to zero, and the probability is squeezed to zero with it.
This kind of limit has a name. A sequence converges in probability to a number if, for every ,
written . The weak law says .
Read the order of the quantifiers carefully. First you choose a tolerance , as small as you like. Then the chance that the average misses by or more can be made as small as you like by taking large enough. A tighter tolerance simply costs more data.
Frequency becomes a theorem
Now take any event with and repeat the experiment independently. Let if happened on trial and otherwise. This indicator has mean and variance , and its sample mean is the frequency of in trials. The weak law says that the frequency converges to in probability.
In the topic What probability is, the frequency reading was an observation: toss a coin many times and the share of heads drifts towards . Here it is a theorem. Nothing about frequencies went into Kolmogorov's axioms, yet frequencies come out of them. The share of heads, a classifier's error rate on a test set and the conversion rate in an A/B test are all frequencies of this kind.
A finite variance was needed only for the short proof. Khinchin (1929) proved the weak law for i.i.d. terms with a finite mean, , and nothing more. His proof cuts off large values, applies Chebyshev to the truncated part and shows that the cut-off part is negligible. We will not need the details.
The mean, however, cannot be dropped. Without it there is no number for the average to converge to, and the block on failures below shows what happens then.
The strong law
The weak law speaks about each separately: at a miss by is unlikely, and at it is even less likely. But your running average is one path, for a single outcome . Could that path keep making rare excursions forever, each one unlikely, yet never stopping?
The strong law of large numbers (Kolmogorov) says no. If are i.i.d. with a finite mean , then
Inside stands an event: the set of outcomes whose whole sequence of averages converges to in the ordinary sense of a limit. A sequence converges almost surely to if , written . "Almost" because exceptional outcomes exist, such as a coin showing heads forever, but together they have probability zero, like the single points of in the topic Kolmogorov's axioms.
Almost sure convergence implies convergence in probability. The converse fails. Take independent events with , and let be the indicator of . Since , in probability. Yet the expected number of events among the first is , which grows without bound; by it is already about . With probability one the events never stop, so again and again and the path does not converge.
Why this matters in ML: one long run of stochastic gradient descent, or one long Markov chain, is a single path, and the strong law is the statement about that path. For i.i.d. averages both laws hold under the same finite-mean condition, so they differ in what they claim, not in when they apply.
Empirical risk is a sample mean
Here is the law at work in learning. A model is scored by a loss , and data come from some distribution. The risk is the expected loss from Expectation and variance:
We cannot compute it, because the distribution is unknown. Given i.i.d. examples, we compute the empirical risk instead:
For a fixed , the losses are i.i.d. with mean , so is just a sample mean and . This is why a test error estimates the true error, and why minimizing empirical risk is a sensible proxy for minimizing risk. With the 0–1 loss, is the error rate from the first block.
Two words in that argument carry weight.
- Fixed. A model trained on the same data depends on the examples, and its training error is optimistic. The topic Inequalities and concentration handled a finite set of candidates with a union bound; in practice we keep a separate test set.
- Identically distributed. If production data drift away from the test data, the average still converges, but to the risk on the old distribution.
The same trick estimates any expectation: average over samples to get . This is a Monte Carlo estimate. For two independent variables, , so four times the share of points that land in the quarter disc converges to ; in one run 2000 points gave . A minibatch gradient is the same idea: the average of per-example gradients estimates the full gradient. The topic Monte Carlo methods develops this.
When averages fail
The law has conditions, and each of them can break.
No mean. The standard Cauchy distribution has density and CDF
Its tails fall only like , so . Worse, the average of independent standard Cauchy variables is again standard Cauchy. Averaging does not help at all: in one simulation the averages of , and draws were , and . A Cauchy variable is not exotic; the ratio of two independent standard normals has this distribution.
A mean but no variance. The Pareto distribution with tail index has density for , mean and infinite variance. Khinchin's law still holds, but Chebyshev is gone and convergence is slow and jumpy: the same sample sizes gave , and . Every so often one enormous value arrives and drags the average away. Incomes, file sizes and occasional gradient spikes have such heavy tails.
Dependence. In the extreme case are one and the same draw, and forever. Milder cases are everywhere: neighbouring states of a Markov chain, near-duplicate examples in a dataset, the same user counted many times in an A/B test. The average may still converge, but it behaves like an average of fewer independent terms. That smaller number is the effective sample size.
How big is the error
The law of large numbers names the destination, not the speed. It says , and says nothing about how close the average is at .
Two quantitative tools are already on the table. The standard deviation gives the typical distance. It shrinks slowly: to cut the error by a factor you need times the data. The same governs test sets, A/B tests and Monte Carlo.
Chebyshev's bound holds for every , but it is loose. For 100 coin tosses and it gives against the exact (see Inequalities and concentration). For 1000 die rolls and the same it gives , and simulation gives about . Hoeffding is tighter, but it is still only a bound.
The gap means the fluctuations have a definite shape that Chebyshev ignores. Take , scale it up by and draw a histogram. For coins, dice, error rates and exponential waiting times alike, the same bell appears. That is the next topic, The central limit theorem: the standardized average approaches , whatever the distribution of the terms, as long as the variance is finite.
Check your understanding
The same questions as in Pulse. Answers are shared between modes.
Answers are saved on the server and tied to this browser until you sign in.