ML & Deep Learning Foundations·Question 16 of 55Intermediate

What is data leakage? Give me three subtle examples you've seen or could imagine, and how you'd detect them.

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

Leakage is any path by which information unavailable at prediction time contaminates training or evaluation, inflating offline metrics that collapse in production. The blatant case - training on test rows - is rare; the subtle ones are what kill real systems:

  1. Preprocessing fit on the full dataset: fitting a scaler, PCA, target encoder, or tokenizer/vocabulary on train+test before splitting. Test-set statistics bleed into the transform. Fix: fit transforms inside the training fold only (sklearn Pipeline inside CV exists precisely for this).
  2. Group leakage: the same patient, user, or document contributes rows to both train and test. The model learns to recognise the entity, not the pattern. Detect with group-aware splits; symptom is a big metric drop when you switch to GroupKFold.
  3. Temporal leakage: random splits on time-dependent data let the model train on the future. A churn feature like "days since last login" computed over a window that extends past the label date is a classic - the feature quietly encodes the outcome.
  4. Target leakage in features: a column causally downstream of the label - e.g., "account_frozen" as a fraud feature, when freezing happens because fraud was detected.
  5. LLM-era: benchmark contamination - eval questions present in the pretraining corpus. Detection: n-gram/substring overlap scans, canary strings, comparing performance on renamed/perturbed versions of the benchmark.
Full worked answer with diagram

Leakage is any path by which information unavailable at prediction time contaminates training or evaluation, inflating offline metrics that collapse in production. The blatant case - training on test rows - is rare; the subtle ones are what kill real systems:

  1. Preprocessing fit on the full dataset: fitting a scaler, PCA, target encoder, or tokenizer/vocabulary on train+test before splitting. Test-set statistics bleed into the transform. Fix: fit transforms inside the training fold only (sklearn Pipeline inside CV exists precisely for this).
  2. Group leakage: the same patient, user, or document contributes rows to both train and test. The model learns to recognise the entity, not the pattern. Detect with group-aware splits; symptom is a big metric drop when you switch to GroupKFold.
  3. Temporal leakage: random splits on time-dependent data let the model train on the future. A churn feature like "days since last login" computed over a window that extends past the label date is a classic - the feature quietly encodes the outcome.
  4. Target leakage in features: a column causally downstream of the label - e.g., "account_frozen" as a fraud feature, when freezing happens because fraud was detected.
  5. LLM-era: benchmark contamination - eval questions present in the pretraining corpus. Detection: n-gram/substring overlap scans, canary strings, comparing performance on renamed/perturbed versions of the benchmark.

Detection heuristics: results too good to be true (near-perfect AUC on a hard problem); one feature with absurd importance; adversarial validation - train a classifier to distinguish train from test rows, and if it succeeds, your splits differ systematically; and large offline→online metric gaps.

Worth sketching. Four gates on one path is a much better answer than a list, because it shows leakage is a property of the pipeline order, not of the model.

flowchart TD
    A["Raw data"] --> B{"Split before<br/>fitting any transform?"}
    B -->|"no: scaler or encoder<br/>saw the test rows"| L["Leak"]
    B -->|"yes"| C{"Split by group?"}
    C -->|"no: same user in<br/>train and test"| L
    C -->|"yes"| D{"Split by time?"}
    D -->|"no: random folds<br/>train on the future"| L
    D -->|"yes"| E{"Any feature caused<br/>by the label?"}
    E -->|"yes: account_frozen"| L
    E -->|"no"| F["Estimate you can trust"]

What a good answer covers

  • Leakage is any path by which information unavailable at prediction time contaminates training or…
  • Group leakage: the same patient, user, or document contributes rows to both train and test
  • Temporal leakage: random splits on time-dependent data let the model train on the future
  • Target leakage in features
  • LLM-era: benchmark contamination - eval questions present in the pretraining corpus

Key terms: Group leakage · Temporal leakage · Target leakage in features · LLM-era: benchmark contamination · adversarial validation

Interviewer follow-ups to expect

  1. Your model gets 0.99 AUC on a fraud problem - walk me through your audit. How does k-fold CV make preprocessing leakage worse if done naively?

  2. How would you check whether an LLM has memorized your eval set?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep