Flip a fair coin a hundred times. The count of heads is usually close to but rarely exactly , and the fraction of heads is usually close to . Flip it ten thousand times and the fraction is much closer to , even though the count of heads is now usually further from than before. Two questions follow. Why do averages settle at all? And when they wobble around the settled value, what shape does the wobble have?
The first question is the law of large numbers. The second is the central limit theorem. Earlier lessons promised both: P1.D1 said relative frequencies settle and that the law would be proved here, P1.D3 said the Gaussian appears wherever many small independent effects add up, and P1.D4 computed how big the wobble is. This lesson delivers all three.
The average of draws is itself random
Draw independently from the same distribution. As P1.D5 put it, they are i.i.d. (independent and identically distributed). Call the mean of the distribution and its standard deviation . The sample mean is the ordinary average of the draws,
The bar means “average of”, and the subscript says how many draws went into it. The sum is used too, with .
Draw the numbers again and you get a different average, so is a random variable, and P1.D4 gave its two key numbers. By linearity of expectation, . Because the draws are independent, variances add, so and . Hence
The second number is called the standard error of the mean. A fair die has and . The average of rolls is centred on with standard deviation .
The mean and spread alone do not say how likely the average is to land far away, or what its histogram looks like. The next section answers the first with a bound that needs no knowledge of the shape, and the rest of the lesson answers the second.
How far can a random variable stray? Markov and Chebyshev
We want a guarantee that works for any distribution. Start with the simplest. Markov’s inequality says that for a variable that is never negative, and any ,
The proof takes two lines. Compare with the variable that equals when and otherwise. The first is never smaller, so , and dividing by gives the claim. For example, if waiting times are never negative and average minutes, then at most of the waits can be minutes or longer. (For an exponential waiting time with mean the true share is , much smaller. Markov’s bound is safe, not sharp.)
Now apply Markov to the variable , which is never negative, with . The event is the event , and by the definition of variance. So
This is Chebyshev’s inequality, named after the 19th-century Russian mathematician Pafnuty Chebyshev. It needs only a finite variance: the distribution can have any shape. It says that at most of the probability lies standard deviations or more from the mean, and at most lies or more. Written for a distance instead of :
How loose is it? For a Gaussian the true probabilities of being at least and standard deviations away are and , far below and . The price of covering every shape is a weak bound for any one shape. It cannot be improved for all distributions at once: a variable that is with probability each and with probability has variance exactly and puts exactly at distance . But for a coin, a die or a bell curve it is pessimistic, and the central limit theorem below gives much sharper answers.
The weak law of large numbers
Apply Chebyshev’s inequality to the sample mean, with the mean and the standard deviation from above:
The right side goes to as grows, for any fixed tolerance . That is the weak law of large numbers: for i.i.d. draws with finite variance, the chance that the average is farther than from tends to . In symbols, “in probability”. The proof above is the entire proof under these conditions.
Revisiting P1.D1. There, a fair coin’s frequency of heads was within of with probability for flips, within with probability for flips, and within with probability for flips. A flip has , so Chebyshev gives for the chance of being or more away. For and the bound is , so “within ” has probability at least (the exact value is ). For and the bound is (the exact chance of being farther than is ). For and the bound equals and says nothing, while the truth is a chance of being farther than . The law is true in all three cases. Chebyshev is a proof tool, not a calculator.
How many rolls? How many rolls of a fair die make the average within of with probability at least ? With , Chebyshev guarantees it once , that is . The Gaussian estimate from later in this lesson says . The exact value at is , a little below (the exact value wobbles around near here, because the sum is a whole number: gives , counting an average exactly away as within). The Gaussian estimate is very close, and Chebyshev’s guarantee is about five times too cautious.
What the law does and does not say
- It is about the long run. For a short run it promises nothing. Ten flips have exactly heads only of the time (P1.D1).
- It does not pay back a surplus. It dilutes it. After fair flips with heads, the next flips are expected to bring heads, so the expected frequency at flips is . The surplus of is still there. It just matters less. The belief that tails is “due” after a run of heads is the gambler’s fallacy (P1.D1): each flip is independent of the past (P1.D5).
- The count wanders further while the frequency settles. The number of heads in flips has standard deviation , and the frequency has (P1.D4). P1.D4’s “typical gap of about ” for flips is the standard deviation. The table also shows the average gap, ignoring sign, which is about of the standard deviation (for a Gaussian it is of it).
| Flips | sd of the count | average gap of the count | sd of the frequency |
|---|---|---|---|
| about | |||
| about | |||
| about |
The popular “law of averages” mixes these up. Averages settle. Totals do not: they keep drifting by about .
- It needs a mean. The proof used a finite variance, and the standard laws need a finite mean. For the Cauchy distribution (P1.D4) the mean does not exist, and a short calculation shows that the average of independent standard Cauchy draws has exactly the same distribution as a single draw, whatever is. Averaging does not help at all: half of all averages lie between and for and for . You will see this in the second widget.
- It needs the draws to bring in new information. If every were a copy of the same , the average would be itself and would never settle. Independence (or at least weak dependence) is the part of “i.i.d.” that does this work.
Go deeper The strong law of large numbers, and how little the law needs
The weak law says that for each fixed , the probability of a gap larger than shrinks. The strong law says something about the whole sequence of averages at once: for i.i.d. draws with a finite mean , with probability the sequence converges to . This is a stronger statement, called almost-sure convergence. It is a theorem of Andrey Kolmogorov, and its proof is harder than the one above. “With probability ” does not mean “for every possible sequence”: a sequence of all heads is possible, it just has probability .
Both laws hold with only a finite mean, without the finite variance used in the proof above. A heavy-tailed population such as a Pareto distribution with finite mean but infinite variance still has averages that settle, but they settle slowly and their shape is not Gaussian. The first law of this kind was proved by Jacob Bernoulli for repeated yes-or-no trials (his book was published in 1713, after his death).
The Galton board: steps that add up to a bell
The law says the average settles. It does not say what the wobble around the settled value looks like. A Galton board, devised by Francis Galton in the 19th century, shows it. Balls fall through rows of pegs. At each peg a ball goes left or right, here with probability of going right, independently of the pegs above. After rows its bin is the number of right moves, . That is a sum of independent Bernoulli steps, so the bin has the binomial distribution of P1.D3: mean , standard deviation .
What to try:
- Twelve rows, . Drop balls. The bars follow the dots closely, and the dots follow the curve. The middle bin has exact probability . The Gaussian density at is , and the Gaussian area over the bin (from to , the continuity correction of P1.D3) is .
- Drop only a few balls. Ten balls give a ragged histogram. The law of large numbers is at work: bars settle onto the dots as the balls pile up, and the “largest bar vs dot gap” in the readouts shrinks.
- More rows. At rows the bell is smoother. The curve follows the dots even more closely.
- Change to with rows. The pile leans against the left wall. Here is small, the binomial is lopsided, and the Gaussian is a poor fit, because it ignores the wall. The common rule of thumb of P1.D3, that and should both be at least about , is a warning about exactly this.
The numbers from P1.D3. For flips of a fair coin, exactly. The Gaussian with the continuity correction gives , and without it . With rows the same idea gives exactly and with the correction, but only if you integrate from to instead of to . Counts are whole numbers, so each count owns the interval from to .
The statement that the standardized binomial approaches the Gaussian is the oldest case of the central limit theorem. Abraham de Moivre found it for in a pamphlet dated 1733 (printed in English in the 1738 edition of his book The Doctrine of Chances), and Laplace extended it in the early 19th century. It is called the de Moivre–Laplace theorem.
The central limit theorem
A binomial is a sum of Bernoulli steps. The same picture appears for sums of almost any kind of step. The central limit theorem (CLT) says so. To compare sums for different on one scale, standardize: subtract the mean and divide by the standard deviation, both known from above,
By the rules of P1.D4, has mean and standard deviation for every . The theorem adds the shape.
“In distribution” means that the CDF of (P1.D2) approaches the CDF at every point. It does not claim that any single equals a Gaussian, only that probabilities of intervals approach Gaussian ones. For large this licenses the working approximations
The first gives the Galton board as the case , , . The second is the form used most in machine learning: an average is roughly Gaussian, centred on , with standard deviation . The standard deviation of the average was already known. The new content is the shape.
An example with dice. The average of dice has mean and standard deviation . How likely is an average of at least , that is, a sum of at least ? With the continuity correction (the sum is a whole number) the Gaussian gives . The exact value, by adding up the probabilities of all sums, is . Without the correction the answer is , about too small.
Watch it happen
What to try:
- Uniform, then . One draw is flat. The mean of two is a triangle, and the mean of five is already close to a bell. Averaging smooths the shape.
- Exponential. At the histogram is the skewed population, and the Gaussian is a clear mismatch. At it still leans right. At the lean is slight. At it is close. The readout “predicted skewness ” falls as .
- Fair coin. The means can only be the values , so the histogram is a row of bars, and it follows the Galton board.
- Two humps. One draw has two bumps. The mean of two draws has three bumps (both low, one of each, both high). At and it is still lumpy, with several small peaks, because the means sit on a lattice of spacing . By about it is one smooth bump.
- Rare event (heads probability ). It is skewed like the exponential, but worse, because is small. At we have and the bars still lean right.
- Cauchy. No matter what is, the histogram of means stays as wide as one draw, and the middle half stays near to . Many means fall outside the axis. The average of Cauchy draws never becomes a bell.
- Fixed axis. Switch to “fixed range” and step through for the uniform population. The bell does not move: it narrows like , which is the law of large numbers. The zoomed axis shows the shape, which is the CLT. Both are the same fact seen two ways: the mean and spread of are and (the law), and in addition the shape is Gaussian (the theorem).
A 95% interval for an average
For a Gaussian, . So for large , about of sample means land within of . The readout “share within ” checks this. Turned around, it gives the usual recipe as an interval likely to contain . In practice is not known and is estimated from the data, which makes the interval slightly wider for small . How to read such an interval correctly is the subject of P1.D13.
What the CLT does not say
- The data do not become Gaussian. A single draw keeps its own distribution, however many you collect. It is the average (or sum) that becomes bell-shaped. A pile of skewed incomes is still skewed.
- is a rule of thumb, not a theorem. The speed depends on the population. A symmetric, light-tailed population such as the uniform is close to Gaussian after a handful of draws, and a strongly skewed one needs far more (see the Go-deeper box below).
- The bell is a good fit in the middle and a worse one far out. The theorem says the CDFs approach each other, but the relative error in a far tail stays large for a long time.
- Strong dependence can break it. If every is a copy of the same variable, the sum is and the standardized sum has the shape of . Positive correlation between neighbours makes the naive too small.
- Heavy tails break it. Without a finite variance (the Cauchy distribution is the standard example) the theorem does not apply. For tails that fall like with the limit, after a different scaling, is not Gaussian.
Go deeper How fast the bell arrives: skewness and the exponential
Take the exponential population with (the one in the widget). The average of draws can be computed exactly, so we can compare the chance that the average lands more than standard errors above , or below, with the Gaussian value for each side.
| skewness | above | below | |
|---|---|---|---|
At the upper tail is too big and the lower tail too small, and the two errors nearly cancel in the sum, against . A two-sided interval looks fine while each side is off. Farther out it is worse: the chance of being more than standard errors above at is , about times the Gaussian value .
The general statement is the Berry–Esseen theorem: with a finite third moment, the largest gap between the CDF of and is at most a constant times , where . The error shrinks like , and a skewed population has a large . For the exponential the largest CDF gap (found by computing it) is at , at , at , at and at . For the uniform population it is at , at , at and at .
Go deeper When the central limit theorem fails: dependence and infinite variance
The CLT has hypotheses, and in machine learning they are sometimes violated.
Dependent draws. A sum of copies of one variable has variance , not , and the standardized sum is just the original variable. Weakly dependent draws, such as values of a time series that forget the distant past, can still obey a version of the CLT, but when neighbouring draws are positively correlated the variance of the average is larger than , so the naive standard error is too small. The i.i.d. assumption of P1.D5 matters here: for example, consecutive frames of one video are not independent examples.
Infinite variance. Suppose the tail probability falls like for large . For the mean exists but the variance does not. The averages still settle (the law holds), but their fluctuations shrink more slowly than , and their limit shape is not Gaussian (it belongs to the family of “stable” distributions). For not even the mean exists. The Cauchy distribution, with tail probability falling like , is the case , and its averages do not settle at all.
Independent but not identical. The i.i.d. assumption can be relaxed. For independent pieces with different distributions a bell shape still appears when no single piece dominates the total variance (the Lindeberg and Lyapunov conditions). This is the precise version of the “many small effects, none dominating” description of P1.D3.
Go deeper A short history
Jacob Bernoulli proved the first law of large numbers for repeated yes-or-no trials in a book published in 1713. Abraham de Moivre showed in 1733 that fair-coin counts follow a bell curve for large (the work reached a wide audience in the 1738 edition of The Doctrine of Chances), and Pierre-Simon Laplace extended it to other sums in the early 1800s. The name “central limit theorem” is credited to George Pólya, in the early 20th century. The modern conditions for it to hold came in work from the late 19th and early 20th centuries. The word “central” is usually read as meaning that the theorem is central to probability. Francis Galton’s board was a way to show the effect to an audience.
Putting it to work: an error bar for every average
The CLT turns “this is an average of things” into “it has a standard error and a bell shape”. Four uses follow, all previews of lessons to come.
Mini-batch gradients (P1.F4). A mini-batch gradient is the average of per-example gradients. If the examples are drawn independently and each gradient has spread , the average has spread . Batch sizes give of the single-example noise. To halve the noise you need four times the batch, so large batches have diminishing returns.
Test-set accuracy (P3.A9). Each test example is correct () or wrong (), so accuracy is an average of Bernoulli draws with spread , and its standard error is . Suppose a model’s true accuracy is and you test on fresh examples. The standard error is , so the measured accuracy is likely (about ) to lie within of , between and . The value lies inside that range, so a measured fits a true well, and examples cannot reliably tell from . To pin one accuracy near to needs examples. To make a one-point gap between two models, measured on separate test sets, as large as standard errors takes about examples each, because the two variances add: . Even then, when the true gap equals standard errors you would detect it only about half the time. (Comparing two models on the same test set can need fewer examples, a point for P1.D13.) All of this assumes the test examples are independent draws from the data you care about.
Monte Carlo (P1.D9). To estimate , average over random samples. The law says the estimate converges, and the standard error says how fast: ten times more precision costs a hundred times more samples.
Why Gaussian noise, and why weight scales. A measurement error made of many small independent effects is roughly Gaussian (P3.A2). A neuron’s pre-activation is a sum of terms, and with independent zero-mean weights its variance grows in proportion to (for inputs of a fixed size), so initial weights are scaled by about to keep it steady (P4.12).
Intuition
An average is a vote of many draws. A lucky draw is often cancelled by an unlucky one, so the average is steadier than a single draw, and the more draws, the steadier, in proportion to rather than because the cancellation is partial. That is the law of large numbers.
Adding independent things is a repeated smoothing of the picture of the distribution (the distribution of a sum is a blend of shifted copies of the others). Each blend rounds off corners: a two-valued coin becomes a binomial staircase, a flat uniform becomes a triangle, then a hump. Whatever the starting shape, if no single piece dominates and the variance is finite, the repeated blending drifts to one shape, the bell. That is the central limit theorem. The Galton board is the picture of this blending with the simplest possible piece.
Math
The sample mean, and its mean and spread:
Markov, for , and Chebyshev:
The weak law:
The central limit theorem:
The binomial case, with :
Code
Simulate batches of rolls with NumPy and compare the spread of the averages with .
import numpy as np
rng = np.random.default_rng(0)
means = rng.integers(1, 7, size=(5000, 100)).mean(axis=1) # 5000 batches of 100 rolls
print(means.mean(), means.std(), np.sqrt(35 / 12) / 10) # near 3.5, near 0.171, 0.171Try it: laws and limits in code
The first cell rolls a die in batches of and compares the spread of the averages with , the share of averages within of , and the Chebyshev bound on the share that are not. It then repeats the idea with Cauchy draws. The second cell is exact (no random numbers): for a fair coin, it compares the true chance that the frequency is more than from with the Chebyshev bound and the Gaussian estimate, then checks the exponential table from the Go-deeper box. Predict first: will Chebyshev’s bound be above or below the exact value every time?
Runs real Python in your browser. First run downloads about 9 MB (once; your browser keeps it).
The cell prints a spread of the averages that tracks (about , , and ), a share within that rises toward , and a Chebyshev bound that is capped at (no information) for and equals for . For the Cauchy draws the middle half stays near to for every , up to random variation. Challenge: change the tolerance to and find the smallest in the list for which the Chebyshev bound is below .
Runs real Python in your browser. First run downloads about 6 MB (once; your browser keeps it).
The first table shows the exact chance of being farther than (, and ), the Gaussian estimate (, and , much nearer than Chebyshev, though a little off for because it ignores the continuity correction) and the Chebyshev bound (, and ). The second table reproduces the exponential tails: the upper tail shrinks from toward and the lower tail grows from toward it. Challenge: add the pair to the coin list and check that the Chebyshev bound is then capped at .
Common mistakes
Check your understanding
A variable has mean and standard deviation , and nothing else is known about its shape. What does Chebyshev’s inequality say about ?
The distance is standard deviations, so the bound is . The value is the chance for a Gaussian, which needs the bell shape that is not given here. Exact equality with holds only for special distributions, since the inequality gives a bound. The inequality gives an upper limit, not a lower one, so a claim that the probability is at least does not follow.
You average independent draws from a population with standard deviation . What is the standard deviation of the average?
The standard deviation of an average of independent draws is . The value divides by instead of , which is the wrong power. The value is the spread of one draw, with no averaging. The value is , which has no basis here.
A fair coin gives heads in its first flips. It is flipped more times. What is the expected frequency of heads over all flips?
The next flips are expected to give heads, so the expected total is out of , a frequency of . The value would need the extra heads to be paid back, which a coin with no memory does not do. The value has no basis in the numbers. The value would need the later flips to give heads as well.
Which statement about the central limit theorem is correct?
The theorem is about the standardized sum or average, with a finite variance and independent, identically distributed draws. A single draw keeps its own distribution. The Cauchy distribution has a bell-shaped density but infinite variance, so the theorem does not apply. The number is a rule of thumb that depends on the population, not part of the theorem.
A model gets of test examples right. Treating the examples as independent, what is the standard error of its measured accuracy?
Accuracy is an average of results, so its standard error is . The value is the variance, before taking the square root. The value is the share of wrong answers, not a standard error. The value is about two standard errors, the half-width of a rough 95% interval.
Exercises
- A waiting time is never negative and averages minutes. Use Markov’s inequality to bound the chance that it is at least minutes.
Show answer
. - A variable has standard deviation . What does Chebyshev’s inequality say about the chance that it lies strictly within of its mean?
Show answer
The chance of being or more away is at most , so the chance of lying strictly within is at least . - A fair coin is flipped times. Find the standard deviation of the count of heads and of the frequency, Chebyshev’s bound on , and the Gaussian estimate of the same probability.
Show answer
The count has and the frequency has . The distance is standard deviations. Chebyshev gives , and the Gaussian gives . - How many rolls of a fair die make the average lie within of with probability at least , by Chebyshev and by the Gaussian estimate?
Show answer
Chebyshev: gives . Gaussian: . Halving the tolerance multiplies both by , compared with the case in the text ( and ). - A model scores on independent test examples. Give the standard error of the accuracy and an approximate interval.
Show answer
, and , so about to . - Use the Gaussian approximation with the continuity correction to estimate the chance of at least heads in fair flips. The exact value is .
Show answer
The mean is and the standard deviation is . “At least ” starts at , so . Without the correction, . - Why can the law of large numbers not be used to argue that a coin which has shown heads in a row is “due” for tails?
Show answer
The flips are independent, so the next flip is heads with probability whatever came before. The law says the frequency approaches because later flips dilute the surplus, not because they compensate for it. - Suppose , all the same draw , with variance . What are and its variance? Which part of the law’s proof fails?
Show answer
and its variance is , which does not shrink with . The proof used , which needs the draws to be independent (or at least uncorrelated). - One example’s gradient has noise . Which batch size reduces the noise of the mini-batch average to a tenth of that, assuming independent examples?
Show answer
gives . - An estimator has mean and variance . By Chebyshev, how large must be so that it is within of with probability at least ?
Show answer
gives . - What skewness is predicted for the average of exponential draws, given that one exponential draw has skewness ?
Show answer
The skewness of an average of i.i.d. draws is the skewness of one draw divided by , so . (This is the formula used by the widget’s “predicted skewness” readout.) - What is the middle half of the average of standard Cauchy draws?
Show answer
The same as for one draw, since the average is again standard Cauchy: from to .
Next: P1.D9 turns the law and the CLT into a tool: estimating quantities by averaging random samples (Monte Carlo), such as by throwing darts at a square. P1.D10 uses the i.i.d. product to fit parameters by maximum likelihood, and P1.D13 turns into confidence intervals and fair comparisons of models. P1.F4 uses the noise of mini-batches.