LearnQuestion bank

How does k-fold cross-validation work, when is it the wrong tool, and what are three ways data leakage can silently inflate a validation score?

ResearchTechnicalEasy

Answer it yourself first, out loud or on paper, then compare.

Answer

Model answer, written in a candidate's voice

In short

  • Split into k folds; train on k-1, validate on the held-out fold, rotate until each fold validates once, then average.
  • When tuning hyperparameters, use nested CV: inner loop tunes, outer loop estimates generalisation.
  • Wrong for time series and grouped data: use forward-chaining/rolling-origin splits and group/scaffold splits, especially for same patient or same molecular scaffold in drug discovery.
  • Leakage: preprocessing fitted on all data before splitting; duplicates or same-entity records across folds; target-leaking features or benchmark contamination, e.g. LLM eval items seen in training.

In full

K-fold CV partitions the data into k folds, trains on k-1 and validates on the remaining fold, rotating until every fold has been the validation set, then averages the scores. It is the wrong tool when the data are ordered or clustered: time series need forward-chaining or rolling-origin splits so the model never sees the future, and grouped data—same patient, same molecular scaffold, same user—need group or scaffold splits, which is critical in drug discovery because a scaffold seen in training can make a novel-looking prediction look artificially good. When hyperparameters are tuned, plain k-fold is optimistic; nested CV is used, with an inner loop for tuning and an outer loop for honest estimation. Leakage silently inflates validation when preprocessing or feature selection is fitted on all data before splitting, when duplicates or same-entity records appear in both train and validation folds, or when features or benchmarks contain the target or the evaluation item—e.g., an LLM benchmark contaminated by training data.

Corrected by an independent AI reviewer.

What a strong answer covers

  • k folds with rotation; nested CV when tuning hyperparameters.
  • Time series need forward-chaining splits.
  • Grouped data (the same patient, or the same molecular scaffold) needs group or scaffold splits; this matters for drug discovery.
  • Leakage sources: preprocessing fitted on all the data, duplicates across splits, target-leaking features, benchmark contamination in LLMs.

Common mistakes

  • Random splits on temporally or structurally correlated data.
  • Tuning on the test set.