Skip to main content

Data Splits and Leakage

Data leakage occurs when training, feature construction, selection, or evaluation uses information that would not legitimately be available for the target use, making results optimistic. High training accuracy alone is not leakage, and not every strong proxy is illegal information.

Define the Information Boundary

unit prediction object
prediction_time when the output must be made
horizon how far ahead the target lies
available_info information genuinely available and allowed then
label_time when the label occurs, matures, and may be revised
split_key entities, groups, and times that must not cross sets

Legitimacy is relative to the deployment information set I(t)\mathcal{I}(t). A field existing in a database does not mean it existed at prediction time or is permitted for use.

Leakage Types

TypeExampleDistortionControl
target/post-outcomedischarge billing predicts admission-time riskfeature follows outcomeaudit event times and lineage
temporalrandom time-series split or future revisionstraining sees the future regimeforward split and data vintages
entity/groupone patient/device appears on both sidesidentity or history is memorizedgroup, sometimes group+time split
duplicatecrops or template copies cross setstest is not a new casegroup near-duplicates before splitting
preprocessingscaler, imputer, PCA, selection fit globallytest distribution changes transformsfit inside every training fold
model selectiontest repeatedly changes model/thresholdtest becomes validationlock test or obtain a new holdout
benchmark contaminationtraining contains questions and answersmeasures reproductionprovenance, deduplication, source/time isolation

A deployment-available proxy may still be a shortcut, bias, or brittle correlate without being leakage. Use subgroup, intervention, and shift tests rather than relabeling every problem.

Split to Simulate Use

Deployment questionPreferred splitDoes not answer
new independent same-regime casesstratified randomtemporal change or identity memory
new patients/users/devicesgroupfuture policy change
future periodtemporal forwardnew institution
new institution/regionexternal/group holdoutevery external environment
spatially dependent casesblocked spatialarbitrary unseen-region extrapolation

Stratification preserves label proportions; it does not prevent group, time, or duplicate overlap.

Pipeline Invariant

For training indices ItrI_{tr} and validation indices IvaI_{va}, every learned transform TηT_\eta should satisfy

η^=fit(T,DItr),Xva=Tη^(XIva).\hat\eta=\operatorname{fit}(T,D_{I_{tr}}), \qquad X'_{va}=T_{\hat\eta}(X_{I_{va}}).

This includes scaling, imputation, vocabulary, PCA, feature selection, target encoding, oversampling, and learned augmentation. Cross-validation refits each transform per fold. Nested CV uses an outer loop for evaluation and an inner loop for selection; selecting features globally before CV still leaks.

Worked Example: 30-Day Readmission

The system must predict at discharge whether a patient returns within 30 days. A flawed design randomly splits visits, uses billing states completed after the 30-day window, selects codes on all data, and tunes thresholds against test AUC.

A stronger design freezes the prediction-time field list; groups by patient and holds out a later cohort; fits imputation, vocabulary, and selection on training only; chooses model and threshold on validation; runs test once with hospital/time/subgroup slices; and excludes examples whose 30-day labels have not matured.

A lower score may reveal that the old system relied on identity or future information rather than that the corrected system became worse.

Leakage Probes

  • record event, ingestion, and revision time for every feature;
  • train suspicious features alone and trace anomalous performance;
  • remove identifiers and high-cardinality proxies;
  • audit exact and near duplicates;
  • run label-permutation controls;
  • assert groups do not cross sets and transforms never fit on test;
  • acquire a fresh holdout after repeated benchmark inspection.

Permutation tests do not find every leak: if a direct label-coded feature is permuted together with the label, their relation may remain. Combine controls with lineage.

Distinctions

Overfitting learns sample noise through a valid pipeline. Leakage crosses an information boundary. Distribution shift changes the deployment distribution. Confounding distorts a causal interpretation. All four can coexist.

prediction_time: explicit
label_horizon_and_maturity: explicit
unit_and_group_key: explicit
split_algorithm_and_seed: versioned
all_learned_transforms_fit_on_train_only: true
test_used_for_selection: false
duplicate_and_overlap_audit: complete
feature_availability_lineage: reviewed
known_residual_risks: listed

This note focuses on offline supervised prediction. Online experiments, RL, federated learning, and continual learning add intervention, feedback, and policy leakage.