--- name: leakage-hunt description: Checks an ML or data result for leakage (test data seen in training, duplicates across splits, features that encode the label, tuning on the test set, future data in the past) by reading the split code and rerunning on data the project never saw. Use when verifying an accuracy, score or quality figure. --- # Leakage hunt A model that has seen the answers scores well without learning anything. Leakage is the most common reason an accuracy figure doesn't survive new data. Part of the Verification Bench (case file: see `verify`). ## Steps 1. **Find where the split happens.** ```sh rg -n "train_test_split|KFold|split\(|\.sample\(|shuffle|val|holdout|test_size" . ``` Note what's split (rows, users, files, dates) and when (before or after preprocessing). 2. **Preprocessing before the split.** Scalers, normalisers, vocabularies, PCA, imputation or feature selection fitted on the full data leak test statistics into training. Fitting must happen on training data only. 3. **Duplicates across splits.** Hash every example and count overlaps: ```python import hashlib h = lambda x: hashlib.sha1(repr(x).encode()).hexdigest() overlap = {h(x) for x in train} & {h(x) for x in test} print(len(overlap), "of", len(test), "test items also in train") ``` Also check near-duplicates (same user, same source file, same text after lowercasing and stripping whitespace). 4. **Groups and time.** If the data has users, patients, sessions or dates, the split must keep each group on one side, and test must come after train for anything forecasting. 5. **Label in the features.** Train a tiny model (a depth-3 tree) on each feature alone. A single feature that nearly predicts the label is either the answer or a leak (an ID, a timestamp, a field filled in after the outcome). 6. **Test set used for tuning.** Search for model selection, early stopping, or thresholds chosen while reading the test score. The reported number must come from data touched once, at the end. 7. **The decisive test:** collect or carve out data the project never saw (a later time window, a new source, items you write yourself), run the frozen model, and compare with the claimed figure. 8. **Ceiling check.** Compare the score with label noise or human agreement on the same task. A score above the ceiling means leakage or a broken metric. ## Entry ```markdown ### leakage-hunt · · PASS | FAIL | INCONCLUSIVE - Split: ; preprocessing fitted on: - Overlap: of test items in train; groups/time respected: yes/no - Single-feature check: - Fresh data: → (claimed: ) ```