You have one dataset and one number computed from it. Resampling lets you ask how much that number would wobble, and how well a model would do on data it hasn't seen, without any new data and without a formula.
Lesson 5 gave you a formula for the uncertainty of an average: standard error = standard deviation / √N. Lesson 9 told you to check a gap between two prompts with "a real significance test (a two-proportion z-test or a bootstrap resample)", and left the bootstrap at that. The formula covers the mean and little else. What is the standard error of a median latency? Of a p95? Of the gap between two prompts graded on the same items? Of a model's accuracy on data it never trained on? No tidy formula answers these, but one idea answers all of them: reuse the data you have, over and over, and watch how the answer moves. That idea has two main forms. The bootstrap measures the uncertainty of a statistic. Cross-validation estimates how well a model generalizes. This lesson covers both.
Lesson 5 imagined repeating your eval many times, each time drawing a fresh sample from the population, and looking at how the statistic varies. You can't do that: you have one sample. The bootstrap's move is to treat your sample as a stand-in for the population and draw fresh samples from it.
"With replacement" is the part that matters. After an item is drawn, it goes back in the pool, so the same item can appear twice or three times in one bootstrap sample while other items don't appear at all. Drawing without replacement would just hand you your original data back in a different order, and every resample would give the identical statistic.
A team logs the latency of 9 requests to a summarization endpoint, in milliseconds. In the order logged (call the positions 0 to 8):
The mean (277) sits well above the median (232) because of the two slow requests, 410 and 530. That is why a team reports the median here. The question is how far off 232 could be. Draw 9 positions at random with replacement, twice. (These positions came from a seeded random generator, so you can reproduce them; the Python block below does the whole thing at scale.)
Two resamples gave medians of 221 and 245. Notice that position 1 (245 ms) turned up three times in resample 2 and position 2 (198 ms) never did. Each resample is a plausible alternate version of the afternoon you logged. Two is too few to read an interval from.
Sort the 10,000 bootstrap medians and read off the 2.5th and 97.5th percentiles: 205 ms to 410 ms. That is a percentile bootstrap interval for the median latency. The bootstrap medians average 234.8 ms with a spread (standard deviation, the bootstrap's estimate of the standard error) of about 32.9 ms.
The interval is wide, lopsided (27 ms below the sample median, 178 above), and honest: with 9 requests, two of them slow, the median could plausibly sit anywhere from the low 200s to 410. Every bootstrap median is one of the original values, since the median of a sample is always one of its members. Only 9 distinct medians were possible in this experiment, which is a small-data warning in itself.
The logic: your sample is the best picture of the population you have. Sampling from the sample mimics sampling from the population, and the wobble of a statistic across bootstrap samples mimics its wobble across real ones.
A concrete property falls out of "with replacement". Any single bootstrap sample of n items contains only some of the originals. How many?
Why the limit is 1/e: take logs. n·ln(1 - 1/n) ≈ n·(-1/n) = -1, because ln(1 - x) ≈ -x for small x. Exponentiate and you get e-1. So a bootstrap sample contains about 63.2% of the distinct original items, and the other 36.8% are left out. Check it by simulation:
Across 1,000 bootstrap samples of 1,000 items, the average share of distinct items was 0.6323, matching 1 − 1/e = 0.6321. The left-out items are called out-of-bag. Random forests use them as a free validation set for each tree. For you, the 63.2% is a reminder that a bootstrap sample has fewer distinct items than the original, which is part of why the bootstrap is shakier on small data.
Lesson 9 compared two prompts by their pass rates. The common eval setup is stronger than that: both prompts are run on the same 40 items. Some items are just hard and both prompts fail them; some are easy and both pass. That shared difficulty is noise you can cancel out, if you keep each item's pair of results together.
| B passes | B fails | Total | |
|---|---|---|---|
| A passes | 28 | 1 | 29 |
| A fails | 7 | 4 | 11 |
| Total | 35 | 5 | 40 |
The paired bootstrap resamples the items, 40 at a time with replacement, and recomputes the gap from the same resampled items for both prompts. Resampling the list of d values does exactly that. The unpaired version, for contrast, resamples each prompt's results independently, as if the two had been tested on different items:
The paired interval, +2.5 to +27.5 points, stays above zero: prompt B is probably better on this kind of item. The unpaired interval, −2.5 to +32.5 points, includes zero and would make you shrug. Same data, same point estimate (+15 points), different verdict. Pairing is worth the effort because 28 of the 40 items were passed by both prompts. Only the 8 items where the prompts disagreed (7 for B, 1 for A) tell you anything, and the paired bootstrap focuses on those.
The bootstrap asks "how uncertain is this number?" Cross-validation asks a different question: "how well will a model trained like this do on new data?" Lesson 8 split data into train and validation. A single split wastes data and depends on luck: with 100 labeled examples, one split's validation score reflects whichever 20 examples landed there. K-fold cross-validation uses every example for validation exactly once.
Every example is scored exactly once while unseen. The dashed test set sits outside the loop entirely.
A team has 100 labeled support tickets and wants to know how accurate a ticket-routing classifier built with a given recipe will be. They cut the data into 5 folds of 20, train five times, and score each model on the fold it didn't see:
Report it as 0.82 with a fold-to-fold standard deviation of 0.057. The spread matters as much as the mean: fold 3 scored 0.75 and fold 4 scored 0.90, a 15-point range inside the same dataset. The standard error line is only a rough guide. The training sets overlap heavily (any two share 75% of the data), so the folds are not independent and the true uncertainty is larger than 0.0255. Treat it as a floor.
Leave-one-out cross-validation (LOO) is the extreme: k = n, so each fold is a single example. With 100 examples that is 100 training runs instead of 5, each on 99 examples. LOO uses nearly all the data for each run, so it is the least pessimistic, but it costs n fits whose models are almost identical, and it is unaffordable for anything expensive to train, such as an LLM fine-tune. Common practice is k = 5 or 10.
Each fold's model trains on only (k−1)/k of the data (80% for k = 5), so it is slightly weaker than a model trained on everything, and CV tends to be a little pessimistic: that is bias, and it shrinks as k grows (LOO trains on n−1 of n). The other side is variance: the estimate depends on which random folds you drew, and a larger k makes the training sets overlap more, so the k models and scores move together and averaging them removes less noise. LOO is low-bias but often noisy and always expensive; k = 5 or 10 is the usual compromise. This is the bias-variance tradeoff from Lesson 8, now applied to the measurement of the model instead of the model itself.
Say 1,000 tickets include 50 urgent ones (5%), cut into 5 folds of 200. Each fold should hold 10 urgent tickets. Purely random folds won't: the count in a fold varies with a standard deviation of √(200 × 0.05 × 0.95 × 800/999) ≈ 2.8, so a fold with 5 or 15 urgent tickets is routine, and a rare class with 10 positives in total can leave a fold with none, making recall undefined there. Stratified k-fold deals the positives and negatives into folds separately, so every fold keeps the 5% ratio. Use it for any classification task with a rare class (the same imbalance trap as Lesson 9's 95% "do nothing" moderator).
Random folds assume order doesn't matter. If you are predicting next month's traffic, or classifying support tickets whose wording drifts as the product changes, a random fold lets the model train on March and be scored on February, using the future to predict the past. Use a forward-chaining split instead: always train on earlier data, validate on later data: train on months 1-3 and validate on month 4, then train on months 1-4 and validate on month 5, and so on.
Likewise, keep grouped rows (several turns from one user, several chunks from one document) inside a single fold, or near-copies of training examples will flatter the validation score.
Leakage is any way information from the validation data reaches the model during training. The classic version is subtle: compute a preprocessing step on the whole dataset, then cross-validate.
In the wrong version, the means, vocabulary, or "best 50 features" were chosen with a look at the validation examples, so the validation fold is no longer unseen. Feature selection is the worst offender: choose the features most correlated with the label using all the data and you can get impressive CV accuracy on pure noise. The rule is that everything that learns from data (scalers, imputers, feature selectors, tokenizer vocabularies, even deduplication thresholds) belongs inside the loop. Lesson 17 (study design and confounding) shows the wider family: a number that looks like evidence because the data collection or the analysis let information in that shouldn't be there.
Rule of thumb: a CV score that looks too good for the problem is a reason to check for leakage before celebrating.
Cross-validation is for choosing: prompt template, learning rate, number of retrieved chunks, which of three models. Every time you pick the best of many options by its CV score, a little of the score is luck you selected for, so the winning number is optimistic. That is why the final check needs data that played no part in any choice.
If the test score disappoints and you go back to tweak, the test set has become one more tuning set, and you've lost your only honest measurement. It matters for LLM work too: a prompt tuned for weeks against a fixed 200-item eval set is overfit to it (the held-out warning in Lesson 9's checklist).
Put an interval on every eval number you act on. Latency percentiles, pass rates and judge scores have no clean formula, and all are one bootstrap away from a range. Resample by item when two systems share items. Protect the score from yourself: the worst evaluation failures are leakage, peeking and a reused test set, not arithmetic. Split first, fit everything inside the fold, and keep one test set sealed until the end.
1. How is one bootstrap sample of a dataset of n items built?
2. About what fraction of the distinct original items appears in a large bootstrap sample?
3. Prompts A and B were both run on the same 40 eval items. Why is the paired bootstrap usually better than resampling each prompt's results separately?
4. A team standardizes all features using the mean and standard deviation of the full dataset, then runs 5-fold cross-validation. What is wrong?
5. You tuned a prompt against a 200-item test set for three weeks, then report its score on that same set as the final number. What is the problem?