Sub topic 12
How many cases are enough
This chapter assumes you can read Python and JSONL, know what a proportion and a sample size are, and already have a dev/test split and a per-case pass/fail grader. The question here is how much a score can be trusted at your current dataset size.
Why a score is only an estimate
Your dataset is a sample of all the inputs your app will see. An accuracy of 0.85 on 40 cases is an estimate of the true rate, not the rate itself. A different 40 cases would give a different number.
For a pass/fail metric, the standard error is roughly sqrt(p * (1 - p) / n). It shrinks with the square root of n. Going from 100 to 400 cases halves the uncertainty. It does not make it four times smaller.
| Cases (n) | Score | Approx. 95% interval (±) |
|---|---|---|
| 25 | 0.80 | 0.16 |
| 100 | 0.80 | 0.08 |
| 400 | 0.80 | 0.04 |
| 1600 | 0.80 | 0.02 |
Measure the uncertainty with a bootstrap
You don't need to memorize the formula. Resample your per-case scores (1 for pass, 0 for fail) with replacement, and look at how much the mean moves.
import random
def bootstrap_ci(scores, n_boot=1000, alpha=0.05, seed=0):
rng = random.Random(seed)
n = len(scores)
means = sorted(sum(rng.choices(scores, k=n)) / n for _ in range(n_boot))
lo = means[int(n_boot * alpha / 2)]
hi = means[int(n_boot * (1 - alpha / 2)) - 1]
return lo, hi
scores = [1] * 34 + [0] * 6 # 34 of 40 cases pass
print(sum(scores) / len(scores), bootstrap_ci(scores))With 40 cases and 34 passes, the score is 0.85. The interval is roughly 0.72 to 0.95. That is wide enough to hide a real change.
Decide from the size of the change you need to detect
Choose the dataset size by the smallest difference you must be able to see. If you want to detect a 5-point drop in accuracy, the intervals of the two runs must be narrower than that. At a score near 0.8, this takes several hundred cases. If you only care about 20-point differences, such as between a bad prompt and a good one, 50 to 100 cases can be enough.
Slices need their own counts
A total of 300 cases can still leave a slice with 8 cases. A per-slice score on 8 cases has an interval of about ±0.3. Treat small-slice numbers as hints, not measurements. Report the count n beside every slice score.
Common errors
- Reporting a score without an interval or a case count.
- Declaring a prompt change an improvement when the two intervals overlap heavily.
- Comparing two runs as if they were independent. If both runs use the same cases, compare the per-case differences. This paired comparison is tighter than comparing two separate intervals.
- Adding many easy cases to grow
n. This narrows the interval but tells you little about hard inputs. - Re-running a non-deterministic app on the same cases and treating the spread as the dataset's uncertainty. Run-to-run noise and sampling noise are different sources.
Exercise
Your app scores 0.90 on 50 cases, and a new prompt scores 0.94 on the same cases. Can you conclude the new prompt is better? What would you do next?
Show answer
Not yet. At n = 50 the interval is about ±0.08, so a 4-point gap is within the noise. Compute the paired per-case differences and bootstrap them, or add more cases (especially in weak slices) until the interval is narrower than the change you care about.