Statistics and Evaluation
Estimate the quantity, quantify uncertainty, protect the comparison.
On this page
A model score is an estimate produced by data and an evaluation procedure. Before asking whether it improved, ask which population and metric it represents. Then distinguish sampling noise from bias and decide whether the observed effect is useful.
The same discipline connects streaming summaries, confidence intervals, A/B testing and cross-validation. They answer different questions; none can repair a mismatch between the collected data and the intended deployment.
Define what the estimate represents
Specify the unit: token, example, document, request or user. Specify the reduction: per-token average, per-user average, macro average or another weighting. Ten requests from one user are not automatically ten independent users.
Separate the target population, random sampling/assignment process and observed sample. More observations can reduce random error without removing systematic bias. A carefully computed statistic on leaked or selected data still answers the wrong question.
Update a mean without keeping every observation
Derive it from . Starting with n=0 and a placeholder Q=0, observing 10 gives 10; observing 20 gives 15. For [10,20,30,40], the successive means are [10,15,20,25].
n, mean = 0, 0.0
for x in stream:
n += 1
mean += (x - mean) / n
yield meanThis conceptual streaming fragment stores O(1) state and uses O(1) work per observation. It avoids maintaining a large raw sum. Differences can still overflow for extreme values, and rounding/count precision still matter; it is not a universal numerical guarantee.
With constant gain , is an exponentially weighted moving average (EWMA). It adapts to drift, but it is no longer the equal-weight mean of all observations. Early initialization can bias it.
Welford's update extends the same innovation to variance. Keep the count, mean and sum of squared deviations M2. Update the mean before updating M2:
This avoids subtracting two large nearly equal raw second moments. It still uses floating-point arithmetic; extreme differences and rounding can cause errors.
Running summaries support signal filtering, streaming metrics and action-value estimation. An action's count must be its own count; one global sample count would weight that estimate incorrectly.
Variation in data versus uncertainty in a mean
The sampling distribution is the distribution of X̄ over repeated samples of size n, not the histogram of individual X values. Uniform(0,1) has mean .5; Exponential(scale=1) has mean 1. Repeated means remain centered on those values.
Correlation changes variance: . Positive cross-covariances can make too optimistic. More tokens from the same prompt are not automatically independent evidence.
A normal approximation needs conditions
Original observations need not be normal. But there is no universal “n≥30 is enough” rule. Strong skew, heavy tails, dependence or rare events can make an approximation poor at a particular sample size. Infinite-variance distributions need a different analysis.
For a normal population, its sample mean is exactly normal. For other populations, write the normal approximation as approximate and check whether its tail accuracy matches the intended interval or test.
A small simulation stores sample means, not only their average: means = rng.exponential(scale=1, size=(repeats,n)).mean(axis=1). Averaging those means again can check centering, but it hides the shape and spread that demonstrate the CLT.
More observations, less variation in their mean
Independent Bernoulli observations have P(X=1)=.2. Each bar contains exact probability for a .05-wide mean bin on [0,1]; the final bin includes 1. Dashed burgundy marks the unchanged population mean .2.
The distribution is still discrete. Its standard error is .100, while the mean remains .2.
Exact binomial calculation, not a sampled histogram or a measured benchmark. Vertical scale is probability per bin; horizontal scale and bin width stay fixed. Playback varies n, not training time.
Interpret an interval as a procedure
A frequentist 95% confidence level describes long-run coverage by this procedure under its assumptions. Once observed, an interval either contains the fixed parameter or does not. It is not automatically a 95% posterior probability.
An interval for the mean is not an interval containing 95% of individual future observations. Those observations also include population variation. Missing bias, clustering or model selection can undermine advertised coverage.
False alarms, misses and power
| Reality | Fail to reject H₀ | Reject H₀ |
|---|---|---|
| H₀ true | Correct nonrejection: 1−α | Type I error: α |
| Specified alternative true | Type II error: β | Power: 1−β |
The nominal α controls false rejection under the null for the specified procedure. It is not the probability that H₀ is true after a significant result. Some procedures control a maximum false-rejection rate rather than an exact equality.
Power is conditional on a particular effect, noise level, sample size and test. A planning target of 80% means at that specified alternative, not 80% for every possible improvement.
At fixed design, larger effects or samples usually improve power; lower noise helps. A stricter threshold generally reduces power unless the design changes. Failure to reject does not establish no effect. To argue equivalence, define a meaningful equivalence margin and an appropriate procedure.
A/B differences: pooled test, unpooled interval
For binary outcomes, let n꜀ and nₜ be independent randomized-unit counts, with observed success rates . The effect estimate is .
Hypothetical counts: 1,000/10,000 control successes and 1,100/10,000 treatment successes. Difference is 1 percentage point, or 10% relative to the .10 baseline. These units must not be confused.
| Quantity | Value |
|---|---|
| Pooled rate | 0.105 |
| Pooled-test z | 2.307 |
| Unpooled standard error | 0.004335 |
| Approximate 95% interval for difference | 0.150 to 1.850 percentage points |
The example is synthetic and assumes independent units, adequate counts and a fixed analysis. Repeated outcomes per user require unit-aware estimation; random assignment alone does not make every event independent.
The normal interval can fail at the boundary. With zero successes among ten units in each arm, both estimated variances are zero. The Wald interval becomes [0,0], and the pooled-test statistic is undefined. Neither result establishes equal population rates.
Even away from exact boundaries, a Wald interval can cover the true difference less often than its nominal confidence level. Choose an interval or test appropriate to the count regime; do not repair a failed approximation by clipping its endpoints. NIST compares Wald and adjusted intervals ↗.
Plan detectable effects before observing results
For 80% power, . This is a planning approximation, not a universal sample-size certificate. Specify baseline rate, minimum detectable effect, assignment unit, attrition, clustering and guardrail metrics.
Set a stopping rule before looking at results. Repeatedly applying a fixed-horizon threshold until it becomes significant can inflate false positives. A valid sequential design needs its own error control; merely calling repeated checks “sequential” is insufficient.
For 20 independent true-null tests at .05, the chance of at least one false rejection is . Bonferroni controls the familywise rate without requiring independence, but the family of decisions must be defined.
Statistical evidence is not a launch policy
| Result | Interpretation |
|---|---|
| Clear useful positive effect | Consider rollout with guardrails, serving cost and reliability |
| Clear regression | Prefer control unless another explicit tradeoff dominates |
| Precise but tiny gain | May not justify latency, memory or maintenance cost |
| Wide interval crossing meaningful effects | Inconclusive; follow the planned stop/redesign decision |
A tiny statistically detectable gain with 10× serving memory can be a bad trade. A nonsignificant result is not permission to extend the experiment arbitrarily. Practical thresholds and guardrails should precede analysis where possible.
Keep user assignment stable and randomized independently of outcomes. Check sample-ratio mismatch, failed instrumentation and attrition. In marketplaces or shared-resource systems, one unit's treatment can affect another unit's control outcome; interference changes the experiment being estimated.
Cross-validation changes which data is held out
For each of k folds, fit a fresh model on the other k−1 folds and evaluate on that fold. Standard k-fold assigns every sample to validation exactly once across the procedure. This does not mean the fitted models or their scores are independent.
Generate indices, optionally shuffle with a recorded seed, partition, then form each held-out/training pair. Indices can support many dataset types without duplicating the underlying examples. The compact generator below preserves the index procedure without copying data.
This Python reference yields index pairs. Leave seed=None to preserve input order; use an integer seed for reproducible shuffling. The generator passes 1,305 independent index-allocation and reproducibility checks; it does not fit a model.
def kfold(n, k, seed=None):
from random import Random
if not 2 <= k <= n:
raise ValueError("require 2 <= k <= n")
order = list(range(n))
if seed is not None:
Random(seed).shuffle(order)
sizes = [n // k + (j < n % k) for j in range(k)]
start = 0
for size in sizes:
stop = start + size
yield order[:start] + order[stop:], order[start:stop]
start = stopFor n=10,k=5 with no shuffle, held-out pairs are [0,1], [2,3], [4,5], [6,7] and [8,9]; each training set is its complement. Check disjointness, complete union and one held-out assignment per sample.
Three fitted models, not one repeatedly tested model
Ten sample indices, no shuffle, k=3. Blue labeled V cells are validation for this fit; burgundy labeled T cells are training. Each row is a separate fit initialized independently.
Fit 1: validate [0,1,2,3]; train [4,5,6,7,8,9]. Fold sizes are [4,3,3].
Exact index allocation only; no performance score is fabricated. Overlapping training sets do not make fold scores independent replicates.
The split must match the deployment question
Cross-validation is useful when split sensitivity matters and repeated fitting is affordable. A large dataset or expensive training can justify a fixed holdout. More folds do not guarantee a better estimate for every deployment setting.
Choose splits around the dependence that matters: grouped data keeps a unit's related examples together; temporal evaluation trains on earlier data and evaluates later data. Ordinary shuffled folds can leak future or identity information. Stratification preserves label balance but does not remove dependence.
Fit normalization, imputation and feature selection on each training split only, then transform its holdout. Hyperparameter selection also uses evaluation data. Use a separate final test set or nested selection/evaluation rather than reporting the winning tuning score as untouched evidence.
Fold-average scores, out-of-fold aggregate metrics and dataset-size-weighted means can differ, especially for nonlinear metrics. Record which summary is reported. Fold dispersion is not automatically a confidence interval because training sets overlap.
Report an experiment that can be interpreted
State the population and unit, split/assignment policy, preprocessing, objective/metric reduction, count, effect size and uncertainty. Distinguish a fitted model's training examples from model-selection and final-evaluation examples.
Also record seed, repeated looks, tested metrics, exclusions, missing outcomes, compute and serving costs. A reproducible score with a flawed comparison is still flawed. A significant improvement with an undefined target population is still difficult to use.
Probability and Distributions → explains the random objects behind these estimates. Losses and Objectives → separates the optimized criterion from the downstream evaluation goal.
Sources and retained references
NIST mean confidence limits ↗ · Cross-validation assumptions and workflow ↗