Fig. 1 in words
One pool, two ways to split it · same data as code 05
- ① Pool · 1 000 · 200 groups × 5 copies · label: coin
- ② Split by row · random 20% → Train 813 · Test 187 → 1-NN 1.000
- Copies leak · 100% seen (a dotted red link between train and test)
- ③ Split by group · 40 whole groups → Train 800 · Test 200 → 1-NN 0.440
- Sealed · 0% seen (a striped barrier between train and test)
- Looks perfect · it remembered copies
- ④ Gap 0.560
- Honest: ≈ chance · guessing gives 0.5
01 Seal the Test Set Split first
- Split before any cleaning, scaling or feature choice. Never call fit on test data (scikit-learn)
- Version it, lock it, open it once at the end
- Every choice made by looking at it turns it into training data
Recht et al. (2019): new test sets cut accuracy 3–15% and 11–14%, from harder images, not from reuse.
02 Split by Group Leakage
- Copies, one patient, one source: all on one side (GroupKFold)
- Leakage found in 294 papers across 17 fields (Kapoor & Narayanan 2023)
- Duplicates are one of their leakage types. Time order is another
Code 05: the same model scores 1.000 or 0.440 depending only on the split.
03 Hunt the Copies Dedup
- CIFAR test sets: 3.3% (10 classes) and 10% (100 classes) of images had near-copies in training (Barz & Denzler 2020)
- Three QA datasets: 30% of test questions had a paraphrase in training. 60–70% of answers appeared there (Lewis et al. 2021)
Exact hashes miss near-copies. Compare normalised text or features too.
04 Two Readers Agreement
- Ten popular test sets: ≥ 3.3% wrong labels on average, ImageNet validation ≥ 6% (Northcutt et al. 2021)
- Cohen's κ (1960) removes the agreement chance alone gives
- 80% raw, 50% by chance: κ = (0.80 − 0.50) ÷ (1 − 0.50) = 0.60
Two people label each item blind.
05 Try It Yourself
sprint20_building_an_evaluation_dataset.py
import numpy as np
rng = np.random.default_rng(20)
G, K = 200, 5 # groups, copies
g = np.repeat(np.arange(G), K)
c = rng.normal(size=(G, 8))
X = c[g] + 0.05*rng.normal(size=(G*K, 8))
y = rng.integers(0, 2, G)[g] # coin flip
def score(test): # 1-nearest nbr
tr = ~test
d = ((X[test, None]
- X[None, tr])**2).sum(-1)
hit = y[tr][d.argmin(1)] == y[test]
seen = np.isin(g[test], g[tr])
print(test.sum(), f"{hit.mean():.3f}",
f"{seen.mean():.0%}")
score(rng.random(G*K) < 0.2) # rows
pick = rng.choice(G, 40, replace=False)
score(np.isin(g, pick)) # groups
Output, as printed on the image
187 1.000 100%
200 0.440 0%
Run it. sprint20_building_an_evaluation_dataset.py · versions, data and steps
Check: 40 groups × 5 = 200 test rows. 1 000 − 187 = 813 and 1 000 − 200 = 800 for training. Gap 1.000 − 0.440 = 0.560. numpy 2.4.4
06 General Notes Skepticism
- Report the split rule, the seed and the counts
- Write a datasheet: who collected it, how, what is missing (Gebru et al. 2021)
- Keep a small hard slice and report it apart
- A test set used to pick the model is no longer a test set
07 Mini Project Hands-on
- Rerun Code 05 with seeds 1–5. By row I get 1.000 each time. By group: 0.395 to 0.575
- Take 200 items of your own and group them by source before splitting
- Ask a friend to label 50 items with you. Compute κ
- Write a one-page datasheet
R Trusted Sources
- Kapoor & Narayanan (2023). Patterns 4, 100804
- Barz & Denzler (2020). Do We Train on Test Data? J. Imaging 6(6), 41
- Lewis, Stenetorp & Riedel (2021). EACL, 1000–1008
- Recht et al. (2019). ICML, PMLR 97, 5389–5400
- Northcutt, Athalye & Mueller (2021). Pervasive Label Errors in Test Sets Destabilize Machine Learning Benchmarks. NeurIPS
- Cohen (1960). Educ. Psychol. Meas. 20(1), 37–46
- scikit-learn docs: Common pitfalls
- Cross-validation
- Gebru et al. (2021) CACM 64(12)
