Home/Learn/Math for AI/Sampling, Estimation & Confidence Intervals

Sampling, Estimation & Confidence Intervals

Advanced
Probability & Statistics

We almost never see all the data, so we estimate from samples — and confidence intervals tell us how much to trust those estimates, which is how you compare models honestly.

Overview

You rarely have the whole population; you have a sample, and you use it to estimate quantities about the whole (a mean, an accuracy, a click-through rate). Because a different sample would give a slightly different estimate, every estimate carries uncertainty. A confidence interval expresses that uncertainty as a range ("accuracy is 84% ± 3%") rather than a single misleading number. This matters enormously in ML evaluation: reporting that model A scores 84.1% and model B scores 83.9% is meaningless if the confidence intervals overlap heavily — the difference is noise. Related ideas — sampling bias (your sample must represent the population), the standard error (how estimate variability shrinks with more data), and resampling methods like bootstrapping — are what separate rigorous evaluation from cherry-picked results. This is the statistical backbone of trustworthy AI claims.

Estimate + standard error: uncertainty shrinks with n

The standard error of a mean is std/√n — quadruple the data to halve the uncertainty. This is why small test sets give unreliable metrics.

Standard error = std/√n — more data, tighter estimates
import numpy as np
rng = np.random.default_rng(0)

pop_std = 1.0
for n in [25, 100, 400]:
    se = pop_std / np.sqrt(n)          # standard error of the mean
    print(f"n={n:>3}  standard error={se:.3f}")
# n= 25  0.200
# n=100  0.100   -> 4x data -> 2x tighter
# n=400  0.050

Bootstrap a confidence interval for model accuracy

Resample your test results with replacement many times to see how much the metric wobbles — a simple, assumption-light way to put an interval on any score.

Bootstrap: a 95% confidence interval for accuracy
import numpy as np
rng = np.random.default_rng(0)

correct = rng.random(200) < 0.84        # 200 test predictions, ~84% correct
boot = [rng.choice(correct, size=len(correct), replace=True).mean()
        for _ in range(2000)]
lo, hi = np.percentile(boot, [2.5, 97.5])
print(f"accuracy 95% CI: [{lo:.3f}, {hi:.3f}]")   # e.g. [0.79, 0.89]

Key Points to Remember

  • 1We estimate population quantities from finite samples — every estimate has uncertainty
  • 2Standard error of the mean = std/√n; uncertainty shrinks slowly with data
  • 3A confidence interval reports a range, not a single fragile number
  • 4Overlapping CIs mean a metric difference may be noise — essential for honest model comparison

Interview Questions

Sign in to ask Aria
1

What is a confidence interval and why report one for a model metric?

MediumProduct
2

Two models score 84.1% and 83.9%. How do you decide if that difference is real?

HardGoogle
3

How does the standard error scale with sample size, and why does it matter for test sets?

MediumAmazon

Ask Aria about Sampling, Estimation & Confidence Intervals

Your personal AI tutor — ask anything about this concept

Revision Status

Personal Notes

Sign in to save personal notes for this topic.

Discussion

Sign in to join the discussion.

Loading discussion…