agentleFS
mxslrmxslr/mlcraft/skills/data-rigor-and-leakage/SKILL.md

data-rigor-and-leakage

Skill8 starsChanged 4 months agoMITView on GitHub

Use BEFORE training any model, to build correct train/val/test splits and hunt data leakage - the #1 cause of fake-high accuracy. Covers group/patient/subject splits, temporal splits, official-benchmark splits, label correctness, class balance, and preprocessing parity. Triggers on 'split the data', 'train/test split', 'cross validation', 'why is accuracy suspiciously high', 'data leakage', 'per-patient'.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Group leakage (most common): If one entity (patient, person, product, document, study) yields multiple samples, ALL its samples must sit in …

    line 11
  2. Distinctive:

    Official split: If the benchmark defines a train/test split (e.g., encoded in an ID), use it - otherwise numbers aren't comparable to …

    line 13
  3. Distinctive:

    Add explicit assertions that split membership is disjoint at the entity level, e.g.:

    line 20
  4. Distinctive:

    Manifest, not copies: Prefer a manifest table (path, entity, label, split) over shuffling files into folders - it makes the split auditable.

    line 29

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Data Rigor & Leakage Audit

Wrong splits invalidate every downstream number. Do this before training and re-check whenever results look too good.

Leakage checklist

  • Group leakage (most common). If one entity (patient, person, product, document, study) yields multiple samples, ALL its samples must sit in ONE split. Random per-sample splitting scatters them across train/test the model memorizes the entity. Use GroupShuffleSplit / StratifiedGroupKFold keyed by the entity id.
  • Temporal leakage. Time-series / any time-ordered data: train must be strictly earlier than val/test. No shuffling across time. No future-derived features.
  • Official split. If the benchmark defines a train/test split (e.g., encoded in an ID), use it - otherwise numbers aren't comparable to papers.
  • Preprocessing / normalization leakage. Fit scalers, PCA, class weights, augmentation stats, and target encodings on train only, then apply to val/test. Never fit on the full set.
  • Duplicate / near-duplicate leakage. De-duplicate (and augmented copies) across splits.
  • Target leakage in features. Drop features that encode the label or are only known post-outcome.
  • Threshold/selection leakage. Choosing a decision threshold or doing model selection using test labels is leakage. Do it on validation.

Make it enforceable

Add explicit assertions that split membership is disjoint at the entity level, e.g.:

assert not (train_ids & val_ids) and not (train_ids & test_ids) and not (val_ids & test_ids)

Print per-split counts of entities (not just samples) and the class balance.

Also verify

  • Labels are correct and consistent (one authoritative source; handle multi-label-per-entity deliberately).
  • Class balance - decide handling now (class-weighted loss OR resampling, not both by default).
  • Manifest, not copies. Prefer a manifest table (path, entity, label, split) over shuffling files into folders - it makes the split auditable.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.