RU
Home · Statistics for ML · Updated

Sampling, the CLT and Standard Error

Why sample means fall into a bell curve: the central limit theorem, the standard error σ/√n and the 68–95–99.7 rule — with a simulator where samples pile up before your eyes.

Intuition

You measured a model's latency on 50 requests: 118 ms on average. A colleague measured it on another 50 — and got 123 ms. Who is right? Both and neither: you are looking at different samples from the same population — all the requests the model will ever receive. We never see the whole population: not all users, not all test examples, not all pizza deliveries. We see a piece and judge the whole by it.

Hence the main shift in thinking: the sample mean x̄ is itself a random variable. Take another sample — you get another number. The question of statistics is not “what is the mean equal to”, but “how much does it jump from sample to sample”. If it jumps by ±1 ms, the difference between 118 and 123 is real. If by ±10, it's noise.

How it works

Imagine we repeated the measurement a thousand times and built a histogram of a thousand means. This is the sampling distribution of the mean. Two things are known about it, and together they make up the central limit theorem (CLT):

The width of this bell is called the standard error (SE):

SE = σ / √n

where σ is the standard deviation (SD) of individual observations and n is the sample size. The square root is the most important detail of the formula: to halve the error you need four times more data; to cut it tenfold, a hundred times more. Precision grows with data, but slowly.

And since the distribution is normal, the 68–95–99.7 rule applies: in 68% of samples the mean will fall within ±1 SE of μ, in 95% within ±2 SE (more precisely 1.96), in 99.7% within ±3 SE. This is exactly where confidence intervals and the p-value grow from: both constructions are simply ways of reading this bell.

Back to latency: if σ ≈ 30 ms, then with n = 50 we have SE ≈ 4.2 ms. The difference of 118 versus 123 is just over one standard error; this happens all the time with one and the same model. To reliably catch a 5 ms difference, you need samples of hundreds of requests.

💡 Key idea Any sample mean — test accuracy, latency, conversion — is one realization of a random variable with spread σ/√n. Until you've estimated that spread, you don't know whether you're comparing models or noise.

When the CLT lets you down

The magic “n ≥ 30” from textbooks is a heuristic, not a law. How many observations you need depends on the shape of the data: for symmetric distributions the bell appears already at n = 5–10, for strongly skewed ones (latency with rare multi-second timeouts, incomes, text lengths) — at hundreds. Play with n in the interactive on the skewed distribution: at n = 3 the histogram of means is still noticeably skewed to the right, at n = 30 no trace of the skew remains.

Three situations where the formula SE = σ/√n is seriously wrong:

Where this hides in ML

⚠️ Pitfall The standard deviation and the standard error are different things. SD describes the spread of individual observations and does not decrease as n grows; SE describes the precision of the estimate of the mean and falls as 1/√n. Writing “accuracy 0.87 ± 0.02” is meaningless until you say what comes after the ±: SD across folds, SE of the mean or a confidence interval.
🎤 In the interview
  • “State the CLT” — the mean of a sample of n independent observations with finite variance is approximately normally distributed, centered at μ with spread σ/√n, whatever the shape of the original distribution.
  • “How is the standard error different from the standard deviation?” — SD is about the data, SE is about the estimate; SE = SD/√n and shrinks as the sample grows.
  • “Model A scored 0.91, model B 0.92 on a test of 500 examples. Which is better?” — estimate SE ≈ √(0.9·0.1/500) ≈ 1.3 pp: a 1 pp difference is within the noise; you need a paired test or more data.
  • “How many times larger must the sample be to halve the spread of the estimate?” — four times, because of the square root in the formula.