Metrics and statistics for machine learning
A fraud model reports 99.5% accuracy on a test set where 0.5% of transactions are fraud. That sounds excellent until you notice that a model that never says "fraud" also scores 99.5%. A second team replaces it with a detector that catches 90% of the fraud, and its accuracy goes down. Meanwhile, across the hall, a new language model scores 71.2% on a 500-question benchmark against the old model's 70.4%, and someone wants to announce the improvement.
Both groups are about to fool themselves, in the two ways this section is about. The fraud team is judging with the wrong number. The language-model team has no idea how much its number would move if the test set were drawn again. Measuring a model honestly takes both a metric that matches the question and an error bar that says how far to trust it, and the statistics behind the error bar decide whether one model really beats another.
This section builds the metrics first (the confusion matrix, precision and recall, ROC and precision-recall curves, and calibration), then the statistics (confidence intervals, paired comparisons, hypothesis tests, multiple comparisons, and power), and it ends with the ways each is misused in papers and model evaluations. Later chapters use all of it, for retrieval metrics in §7.5, evaluating fine-tuned models in §14.7, reward model accuracy in §16.3, and safety evaluations in §19.4.
The confusion matrix
A binary classifier makes four kinds of decisions, and the confusion matrix counts each. A true positive (TP) is a positive example predicted positive, a false positive (FP) a negative predicted positive, a false negative (FN) a positive predicted negative, and a true negative (TN) a negative predicted negative. With rows for the truth and columns for the prediction, the detector above gives
| predicted fraud | predicted not fraud | |
|---|---|---|
| fraud (485) | TP = 434 | FN = 51 |
| not fraud (99,515) | FP = 997 | TN = 98,518 |
Every common metric is a ratio of these four counts, and the useful ones divide by a row or a column rather than by everything.
- Recall, also called the true positive rate (TPR) or sensitivity, is , the fraction of real positives the model catches. Here .
- Precision, or positive predictive value, is , the fraction of alarms that are real. Here .
- The false positive rate (FPR) is , the fraction of negatives that raise an alarm. Here 0.010. Its complement, , is the specificity.
- Accuracy is , which here is 0.9895, worse than the 0.9951 of never predicting fraud.
Accuracy is dominated by whichever class is common, so on imbalanced data it mostly measures the prevalence. The detector catches nine frauds in ten, yet loses on accuracy because its 997 false alarms outnumber the 485 frauds in the whole set. And notice what precision did. The detector has a false positive rate of only 1%, but seven of every ten of its alarms are false.
Precision depends on the base rate
That last fact is Bayes rule from §0.4, the same arithmetic as the 99%-accurate disease test. Write for the prevalence of positives. Precision is the probability that an example is positive given an alarm, so
In plain words, among all alarms, the true ones come from the positives that are caught () and the false ones from the negatives that slip through (). Recall and FPR are properties of the classifier alone, measured within one true class. Precision mixes in the prevalence. The same detector, unchanged, is excellent at one base rate and nearly useless at another.
At a prevalence of 0.05%, which is realistic for many abuse and safety problems, every true alarm comes with 22 false ones. This is why the safety classifiers of §19.7 need false positive rates far below 1%, and why a precision number means nothing without the base rate of the set it was measured on.
F1, and averaging over classes
When one number must summarize both errors, the usual choice is the F1 score, the harmonic mean of precision and recall ,
The second form follows by substituting the definitions and clearing denominators. In plain words, F1 is high only when both precision and recall are high, because a harmonic mean is pulled toward the smaller value. A model with and gets , not the 0.55 an ordinary average would give. The detector above has . The more general weights recall times as much as precision ( is common when misses are costlier than false alarms). Notice that F1 never looks at TN, which is why it suits problems where the negatives are a vast, uninteresting background.
With classes, compute precision, recall, and F1 for each class by treating "" as positive and everything else as negative, then average. Macro-averaging takes the plain mean over classes, so every class counts equally however rare. Micro-averaging adds up TP, FP, and FN over all classes first and computes one F1 from the totals. For single-label classification every wrong prediction is one false positive (for the predicted class) and one false negative (for the true class), so micro precision, micro recall, and micro F1 all equal plain accuracy. Report macro F1 when rare classes matter, and say which average you used, because they can differ enormously.
Confusion matrix, per-class F1, macro and micro
Implement confusion_matrix(y_true, y_pred, K) returning a (K, K) integer array with rows for the true class and columns for the predicted class, and prf(C) returning (precision, recall, f1, macro_f1, micro_f1), where the first three are arrays of shape (K,). When a ratio has a zero denominator (a class never predicted, say), define it as 0.
Thresholds, and the curves that sweep them
Most classifiers do not output a decision. They output a score (a probability, a logit, a distance), and a decision comes from a threshold , predicting positive when . Every threshold gives a different confusion matrix. Lower it and you catch more positives at the price of more false alarms. To judge a scorer rather than one decision, sweep the threshold through every value and plot what happens.
The ROC curve (receiver operating characteristic, a name from radar engineering) plots TPR against FPR. It starts at , where the threshold is above every score and nothing is flagged, and ends at , where everything is flagged. A perfect scorer goes straight up to , and a random one follows the diagonal. The precision-recall curve plots precision against recall over the same sweep.
The area under the ROC curve, the ROC AUC, has a beautiful meaning. It is the probability that a randomly chosen positive scores higher than a randomly chosen negative,
where and are the scores of a random positive and a random negative, and ties count half. In plain words, AUC measures ranking. It asks how often the model puts a positive above a negative, ignoring any threshold and any calibration. An AUC of 0.5 is chance, and 1 is a perfect ranking.
∂ Why the area under the ROC curve is a ranking probability
Sort all examples by score, highest first, and lower the threshold past them one at a time. Passing a positive moves the ROC curve up by . Passing a negative moves it right by . So the curve is a staircase, and its area is a sum of columns, one per negative. The column for negative has width and height equal to the TPR at the moment we pass it, which is the fraction of positives that scored above it, . Adding up the columns,
the fraction of positive-negative pairs ranked correctly. If a positive and a negative tie, the threshold passes them together and the curve moves diagonally, and the trapezoid under that diagonal step gives exactly half credit to each tied pair.
The pair count does not need comparisons. Rank all scores from 1 (lowest) to , giving tied scores the average of their ranks. The rank of a positive is one plus the number of examples below it, so the sum of the positives' ranks counts every pair of positives once ( in total, including each positive with itself) plus every correctly ordered positive-negative pair (with ties counting half through the averaged ranks). Therefore
computable with one sort, in . This is the Mann-Whitney statistic divided by , so the ROC AUC is a classical rank test in disguise. ∎
For the precision-recall curve the standard summary is average precision (AP), the precision at each threshold weighted by how much recall increased there, over the distinct thresholds from the highest score down. Do not draw straight lines between PR points and integrate under them. Unlike ROC space, precision does not vary linearly between two operating points, and linear interpolation overstates the area (Davis & Goadrich, 2006).
Why precision-recall beats ROC under imbalance
TPR and FPR are each computed within one true class, so neither depends on how many positives there are. The ROC curve, and its AUC, are therefore the same at any prevalence. That sounds like a virtue, and for comparing ranking quality across data sets it is. But when positives are rare, the ROC curve hides exactly what you care about. An FPR of 1% is a point near the left edge of the ROC plot, yet at 0.5% prevalence it means two false alarms for every real one. Precision feels that, and the ROC curve cannot.
The cell draws the same scorer (positives score , negatives ) at three prevalences. The theoretical ROC AUC is at every prevalence, where is the standard normal CDF, since is .
The three ROC curves lie on top of each other, with AUCs between 0.91 and 0.93 (the theoretical 0.921 plus sampling noise from 500 positives). The average precision falls from 0.93 to 0.50 to 0.19, and that collapse is the real story, since at 0.5% prevalence no threshold gets you high precision and decent recall at once. Saito & Rehmsmeier (2015) make this case at length. A random scorer has an expected AP equal to the prevalence, so AP should always be read against that baseline, while a random ROC AUC is always 0.5.
Choosing the threshold
A curve is not a decision. To deploy, you pick one threshold, and the right one depends on what each error costs. If a false positive costs and a false negative , choose the threshold that minimizes on a validation set. Many applications state the constraint directly instead, as recall at a fixed false positive rate, or precision at a fixed recall. Security work, for example, judges membership-inference attacks by their true positive rate at a false positive rate of 0.1% or lower, because an attack that is right on average but cannot confidently identify anyone is no threat (Carlini et al., 2022).
Choose thresholds on validation data, never on the test set. Tuning a threshold to the test set is a quiet form of training on it, and the reported precision and recall will not hold up.
ROC AUC and average precision from scratch
Implement roc_auc(y, s) and average_precision(y, s) for binary labels y (0 or 1, both present) and real scores s, without scikit-learn.
roc_aucmust handle ties (a tied positive-negative pair counts half) and run in , so no comparison matrix.average_precisionmust match scikit-learn's definition, over distinct score thresholds from highest to lowest, where tied scores enter together.
Calibration
A weather forecaster who says "70% chance of rain" is calibrated if it rains on about 70% of the days they say it. A classifier's probabilities can be judged the same way. Formally, a model that outputs a confidence for its prediction is calibrated if
In plain words, among all the predictions made with confidence 0.8, 80% should be right. Calibration is separate from accuracy. A model can rank perfectly and still be overconfident, and a model that always predicts the base rate is perfectly calibrated and useless. It matters whenever a probability is used as a probability, to decide when to abstain, to combine with costs, to route a hard question to a human, or to tell a user how sure the model is.
To check it, sort predictions into bins by confidence (here is the number of bins). For each bin , compare the average confidence with the fraction correct . Plotting accuracy against confidence gives a reliability diagram, which for a calibrated model lies on the diagonal. The expected calibration error summarizes it as the bin-size-weighted gap,
where is the number of predictions in bin (Naeini et al., 2015; Guo et al., 2017). For multi-class models the usual convention uses the top-label confidence, the largest softmax probability, and asks whether the predicted class is correct.
Guo et al. (2017) found that modern deep networks are often overconfident, much more so than older, smaller ones, and that a one-parameter fix works remarkably well. Temperature scaling divides the logits by a single scalar , fitted on a validation set by minimizing the negative log-likelihood. Dividing all logits by the same positive number never changes their order, so the predictions and the accuracy stay exactly the same, and only the confidences move. (This is the same as the sampling temperature of §0.4, used here to repair probabilities rather than to sample.)
The cell builds a 10-class model whose logits are 2.5 times too large, so it is badly overconfident, and fixes it.
Temperature scaling recovers , close to the true 2.5, drops the ECE from 0.24 to about 0.02, and improves the log-likelihood and the Brier score, while the accuracy stays at 0.544 to the last digit. The cell below draws the two reliability diagrams.
Calibration is not discrimination
"Are the confidences any good" hides two separate questions. Calibration asks whether confidences match frequencies. Discrimination asks whether higher confidence goes with being right, so that the confidence can tell the model's right answers from its wrong ones. Discrimination is a ranking question, so it is measured by the AUROC of the confidence used as a score for correctness, the probability that a randomly chosen right answer gets a higher confidence than a randomly chosen wrong one. That is exactly the ROC AUC of the previous section, with "correct" as the positive class. A model can be calibrated without discriminating, and discriminate well while being badly calibrated.
Temperature scaling cuts the ECE more than tenfold and leaves the AUROC almost where it was (it moves slightly, because dividing every logit vector by the same can reorder the top probabilities of two different examples). The constant-confidence model is perfectly calibrated and has an AUROC of exactly 0.5, no better than chance at telling right from wrong. Report both numbers. Calibration says whether a confidence of 0.8 can be read as 80%, discrimination says whether the confidence is worth reading at all, and a model that is to abstain when unsure needs both.
What ECE does not tell you
ECE is useful and easy to misread. Three cautions.
- It can be gamed. A model that outputs its overall accuracy as the confidence for every prediction has an ECE of exactly zero and conveys nothing about which predictions are right. ECE should always be reported next to accuracy or a proper score.
- It is a biased estimate, and it depends on the bins. Within each bin, the accuracy is measured from a finite sample, and its sampling noise never cancels inside the absolute value, so even a perfectly calibrated model gets a positive ECE. The bias grows with the number of bins and shrinks with the number of predictions, roughly like . Too few bins have the opposite problem, averaging real miscalibration away, and for a model whose confidences vary continuously the binned estimate can understate the true calibration error (Kumar, Liang & Ma, 2019). Equal-mass bins, which put the same number of predictions in each, avoid nearly empty bins when confidences pile up near 1, and Nixon et al. (2019) recommend them. Always state the number and kind of bins, and compare models only at the same number of predictions.
- It sees only the top label. A model can be calibrated on its top choice and badly miscalibrated on the rest of the distribution.
A proper scoring rule avoids the gaming problem. It is a score whose expectation is optimized only by reporting the true probability. The Brier score is one. If , its expectation for a report is , minimized exactly at . The log loss (the negative log-likelihood) is another. Both reward calibration and sharpness together, which is why calibration studies report NLL or Brier alongside ECE.
The true calibration error of this model is zero. With 500 predictions and 50 bins the estimate says 0.09 to 0.10, worse than many published "miscalibrated" models, and it falls only as the evaluation grows. Equal-mass bins do not remove the bias, which comes from finite samples, but they keep every bin populated. So a reported ECE is only meaningful next to its number of predictions and bins, and small differences in ECE between models are usually noise.
For language models these questions are live. Kadavath et al. (2022) found that large pretrained models are well calibrated on multiple-choice questions when the question is posed in the right format, and the GPT-4 technical report (OpenAI, 2023) showed calibration on a multiple-choice benchmark getting markedly worse after post-training. Calibration and abstention for language models are the subject of §19.8.
Expected calibration error
Implement ece(conf, correct, n_bins=15) for confidences in and 0-or-1 correctness indicators. Use equal-width bins, with bin holding confidences in , except that a confidence of exactly 1 goes in the last bin. Skip empty bins, and weight each bin's gap by its share of the predictions.
How precise is a measured number
Now the second problem from the opening. A model answers 500 benchmark questions and gets 352 right, . If we drew another 500 questions of the same kind, we would get a somewhat different number. How different?
Each question is a Bernoulli trial with success probability , the model's true accuracy on questions like these. So the number correct is binomial, and by §0.4 the estimate has standard error . By the central limit theorem, is approximately , so with probability about 95% it falls within standard errors of . Turning that around gives the normal (or Wald) interval,
For 352 of 500, that is . The second team's 70.4% and 71.2% are 0.8 points apart, with error bars of four points each. Nothing has been shown yet.
What does "95% confidence interval" mean? It is a statement about the procedure, not about this one interval. If you repeated the whole experiment many times and built an interval each time, 95% of those intervals would contain the true . This one interval either contains it or does not. Saying "there is a 95% probability that is in " is the common misreading, and it is only justified in a Bayesian analysis with a prior.
When the normal interval fails, and the Wilson interval
The Wald interval has two well-known failures. With (no harmful outputs in 50 red-team prompts, say) it gives , claiming certainty from 50 trials. And near 0 or 1 its true coverage falls well short of 95% even for large . Brown, Cai & DasGupta (2001) showed its coverage is erratic and often poor, and recommend the Wilson interval instead. Wilson's idea (1927) is to use the standard error at the hypothesized , not at , and collect every that the data do not reject,
In plain words, the Wilson interval is centered not at but pulled toward , by the equivalent of adding successes and 2 failures, and it never leaves . For 0 successes in 50 it gives . A handy companion is the rule of three. With zero events in trials, the exact one-sided 95% upper bound solves , so , here 0.06. Zero failures in 300 tests still allows a failure rate of 1%.
∂ Solving for the Wilson interval
Square the inequality and multiply by , so the boundary points satisfy . Expand and collect powers of ,
The quadratic formula gives
The discriminant simplifies, since , whose square root is . Dividing numerator and denominator by 2 gives the center and the half-width . Since the quadratic in opens upward and is negative at , the accepted values of are exactly those between the two roots. ∎
How well do the two intervals keep their promise? The coverage of an interval method, the probability that it contains the true , can be computed exactly by summing the binomial probabilities of every outcome whose interval contains .
At with 1,000 trials both are fine. For rare events, which is where safety evaluations live, the Wald interval covers the truth only 87% of the time, while Wilson stays near 95%. The widget lets you watch 100 simulated evaluations at once.
The Wilson score interval
Implement wilson_interval(k, n, level=0.95) returning (lo, hi) for k successes in n trials, using with (use scipy.stats.norm.ppf). It must work for k = 0 and k = n, and stay inside .
The bootstrap, for numbers without a formula
Accuracy has a formula for its standard error. F1, AUC, ECE, a median latency, or the pass rate of a judge do not, or the formula is messy. The bootstrap (Efron, 1979) estimates the sampling distribution of any statistic by treating the test set as a stand-in for the population. Resample items from the test set with replacement, recompute the statistic, repeat a few thousand times, and read off the spread. The percentile interval takes the 2.5th and 97.5th percentiles of the resampled values as a 95% interval.
Even with 400 examples, an F1 of 0.64 is uncertain by about nine points either way. The bootstrap has its own rules. Resample the unit that was sampled independently. If each question was asked five times, or several questions share one passage, resample questions or passages, not individual answers, otherwise the interval comes out far too narrow (Miller, 2024, calls the fix clustered standard errors). It is unreliable for statistics driven by a few extreme values, such as a maximum, and for very small test sets. And it measures only the noise of the test sample, not the variation from retraining with another seed, which needs separate runs.
Comparing two models
Back to the second team, with 70.4% against 71.2%. The key fact is that both models answered the same questions, and that changes the arithmetic completely.
Questions differ in difficulty, so two models' answers are correlated. Both get the easy ones right and both miss the hardest. Let say whether models A and B got question right, and let be the per-question difference, with mean over the questions. Then
In plain words, the covariance term subtracts the shared difficulty. Treating the two accuracies as independent, as if the models had answered different questions, ignores it and overstates the noise. The paired standard error is just the standard deviation of the divided by .
There is an even more direct way to see it. Every is , , or , and the questions both models got right or both got wrong contribute zeros. Only the discordant questions carry information about which model is better. Let count questions A got right and B got wrong, and the reverse. If the models are equally good, each discordant question is equally likely to go either way, so conditional on the discordant questions, . That is McNemar's test (McNemar, 1947), and the exact version computes its p-value from this binomial, with no approximation at all. Dietterich (1998) recommends it for comparing two classifiers on one test set.
The same data give two conclusions depending on the arithmetic. Treated as unpaired, a 3.7-point gain has , short of significance. Paired, the standard error shrinks by a quarter, , McNemar's exact p-value is 0.018, and the paired bootstrap interval excludes zero. Pairing is free precision, and it is the default way to compare models on a shared benchmark. With language models, where answers are sampled and graded by judges, the same idea extends to several samples per question and to clustered questions, which §14.7 works through.
Paired bootstrap and McNemar's test
Two models were graded on the same n items, with 0-or-1 arrays a and b. Implement
paired_bootstrap_ci(a, b, n_boot, rng, level=0.95)returning(diff, lo, hi), wherediffis the mean ofb - aand(lo, hi)is the percentile interval fromn_bootresamples of the items, drawn withrng.integers(0, n, size=(n_boot, n));mcnemar_exact(a, b)returning the two-sided exact p-value, with , and 1.0 when there are no discordant items.
Hypothesis tests and p-values
McNemar's test is one instance of a general recipe. State a null hypothesis , the boring explanation (the models are equally good). Choose a test statistic that tends to be large when is false (the paired , or ). The p-value is the probability, computed assuming is true, of a statistic at least as extreme as the one observed. If it falls below a significance level chosen in advance (often 0.05), reject . Rejecting a true null is a type I error, which happens with probability by construction. Failing to reject a false one is a type II error.
Tests and intervals are two views of the same calculation. A two-sided test at level rejects "the difference is zero" exactly when the confidence interval for the difference excludes zero. The interval says more, because it also shows how big the difference might be, so prefer reporting intervals.
The p-value is the most misread number in science, so it is worth being blunt about what it is not (Wasserstein & Lazar, 2016, give the American Statistical Association's version).
- It is not the probability that the null hypothesis is true. That would be , and the p-value is a probability of data assuming , the same confusion of conditionals that §0.4 warned about.
- It is not the size or importance of an effect. With a million test items, a 0.1-point improvement nobody would notice is highly significant.
- A large p-value is not evidence of no difference. "Not significant" usually means "too few items to tell", which the section on power makes precise.
A permutation test builds the null distribution directly from the data, with no formula. If the models are equally good, then for each question, which model got the and which the is arbitrary, so flipping the sign of each at random produces a draw from the null. Repeat many times and see how often the flipped mean is as extreme as the real one. For paired data this is called the paired randomization test (or sign-flip test).
The three tests agree closely, as they should, since they ask the same question of the same discordant questions.
Nothing in the paired randomization test or the paired bootstrap needs the per-item scores to be 0 or 1. They work unchanged for any metric computed per item and averaged, such as nDCG or reciprocal rank per query in retrieval (§7.5), a judge's score per prompt, or a per-document ROUGE. Smucker, Allan & Carterette (2007) compared significance tests for information retrieval and recommend the randomization test for comparing two systems on the same queries. Here are two retrieval systems scored on the same 200 queries.
The paired tests agree with each other and find the 3.5-point gain clearly, while an unpaired test, swamped by how much queries differ from one another, calls it noise.
Multiple comparisons
Evaluate two identical models on 20 benchmarks, and test each at . The chance that at least one benchmark shows a "significant" difference is . Run 20 seeds, 20 prompts, or 20 hyperparameter settings and report the best, and the same arithmetic applies whether or not anyone counted the attempts. Gelman and Loken call this the garden of forking paths. It is one of the main reasons published improvements fail to replicate.
Three corrections are standard, for tests with p-values .
- Bonferroni rejects only when . By the union bound, the probability of any false rejection is at most . This controls the family-wise error rate, at a high cost in power.
- Holm's method sorts the p-values, compares the smallest with , the next with , and so on, stopping at the first failure. It controls the same error rate and is never less powerful than Bonferroni, so there is no reason to use plain Bonferroni.
- Benjamini-Hochberg (1995) controls something different, the false discovery rate, the expected fraction of rejections that are false. Sort the p-values, find the largest with , and reject the smallest. When many effects are real it finds far more of them than Holm, at the price of allowing a controlled share of false ones.
Testing each benchmark unadjusted finds 85% of the real effects but produces at least one false positive in almost half the runs. Holm nearly eliminates false positives but finds only half the real effects. Benjamini-Hochberg sits between, finding 71% of the real effects while its false discovery rate stays near 3%, under the 5% it promises.
Statistical power and sample size
A test's power is the probability that it detects an effect that is really there, . It is the question to ask before running an evaluation, since an underpowered evaluation can only produce noise or exaggeration.
For a paired comparison, suppose the true mean difference is and the per-item differences have standard deviation . The estimate is approximately , and a two-sided test at level rejects when , where . Standardizing,
The second term, rejecting in the wrong direction, is negligible once power is meaningful. Setting the first term equal to a target power means , so
In plain words, the number of items grows with the square of the noise-to-effect ratio. Halving the effect you want to detect quadruples the evaluation. For and 80% power, , and .
For 0-or-1 grades, is with probability (only B right), with probability (only A right), and 0 otherwise, so . The discordance rate is what matters. Two models near 70% accuracy that disagree on 15% of questions have , while an unpaired comparison of two independent samples has , which is .
A 2-point improvement needs about 2,900 paired questions to detect reliably, and 1 point needs nearly 12,000. Many popular benchmarks have a few hundred to a thousand questions, so many claimed improvements on them were never detectable. Card et al. (2020) reached the same conclusion for NLP more broadly. They found underpowered comparisons common, and estimated, for example, that machine translation test sets of 2,000 sentences have about 75% power to detect a 1-point BLEU difference.
Low power does worse than miss real effects. It exaggerates the ones it finds. If only significant results get reported, and significance requires an observed gain of about two standard errors, then an underpowered study can only report gains that are much larger than the truth. Gelman & Carlin (2014) call these type M (magnitude) and type S (sign) errors.
With a true gain of one point and 1,000 questions, only 13% of evaluations reach significance, and those that do report a gain three times too large on average. This is why surprising results from small evaluations so often shrink when someone reruns them.
How many questions does an evaluation need
Implement
paired_sd(p10, p01), the standard deviation of the per-item difference , wherep10is the probability that only A is right andp01that only B is right;power(delta, sd, n, alpha=0.05), the two-sided power formula above (both terms);n_required(delta, sd, alpha=0.05, target=0.8), the smallest integernfrom the sample-size formula (round up).
In PyTorch
At scale, metrics run on the GPU over millions of predictions, and calibration is fitted on held-out logits. Here is temperature scaling the way Guo et al. implemented it, with L-BFGS on the validation NLL, along with ECE and a rank-based AUC in plain PyTorch.
The ece here uses the identity , so two bincount calls compute every bin at once with no Python loop.
How each is misused
| misuse | why it misleads | do this instead |
|---|---|---|
| accuracy on imbalanced data | dominated by the majority class, a trivial model scores well | precision, recall, F1, or AP for the rare class, with the prevalence |
| ROC AUC for rare positives | prevalence-invariant, so it hides floods of false alarms | precision-recall curve and AP, or recall at a fixed low FPR |
| precision quoted without the base rate | precision changes with prevalence even for the same classifier | report the prevalence, or TPR and FPR |
| threshold or temperature tuned on the test set | the test set becomes training data, so the numbers are optimistic | tune on validation data, report the test set once |
| ECE alone, with unstated bins | gameable by a constant predictor, and bin-dependent | ECE with stated bins plus NLL or Brier, and a reliability diagram |
| a table of numbers without intervals | a gap smaller than the noise looks like progress | Wilson or bootstrap intervals, and paired intervals for differences |
| unpaired intervals for a shared benchmark | ignores shared difficulty, so the noise is overstated | paired standard errors, McNemar, or a paired bootstrap |
| bootstrapping answers instead of questions | correlated samples make the interval far too narrow | resample the independent unit (question, passage, user) |
| "not significant, so no difference" | usually just low power | report the interval and the smallest effect the test could detect |
| best of many seeds, prompts, or benchmarks | multiple comparisons manufacture significance | report all runs or the mean over seeds, and correct with Holm or Benjamini-Hochberg |
| a big gain from a small evaluation | a significance filter at low power exaggerates effects | plan the sample size first, and replicate surprising results |
Two failures in the table are about the data, not the statistics, and no interval can fix them. A test set that leaked into training (contamination) makes every number optimistic, which the evaluation chapters treat as a problem of its own. And comparing your number with a number from a paper that used another prompt, another answer extractor, or another evaluation harness compares two different measurements.
Read more
- Evan Miller (2024). Adding Error Bars to Evals: A Statistical Approach to Language Model Evaluations. Standard errors, clustering, paired differences, and power analysis, written for language model evaluations.
- Guo, Pleiss, Sun & Weinberger (2017). On Calibration of Modern Neural Networks. Why deep networks are overconfident, reliability diagrams, ECE, and temperature scaling.
- Davis & Goadrich (2006). The relationship between Precision-Recall and ROC curves. Dominance in ROC and PR space, and why PR curves must not be linearly interpolated.
- Saito & Rehmsmeier (2015). The Precision-Recall Plot Is More Informative than the ROC Plot When Evaluating Binary Classifiers on Imbalanced Datasets. The imbalance argument, with simulations and real examples.
- Brown, Cai & DasGupta (2001). Interval Estimation for a Binomial Proportion. Why the Wald interval fails, and why Wilson and its relatives should replace it.
- Dietterich (1998). Approximate Statistical Tests for Comparing Supervised Classification Learning Algorithms. McNemar's test and the pitfalls of resampled t-tests for comparing classifiers.
- Card et al. (2020). With Little Power Comes Great Responsibility. How often NLP comparisons are underpowered, with tools for power analysis.
- Benjamini & Hochberg (1995). Controlling the False Discovery Rate: A Practical and Powerful Approach to Multiple Testing. The false discovery rate and the step-up procedure.