Why must validation and test sets preserve the original class distribution?

Last updated 15 November 2026

Validation and test sets exist to estimate how the model will perform in deployment. Many key metrics, and the choice of decision threshold, depend on class prevalence, so evaluating on an altered distribution gives misleading numbers.

  • Prevalence-dependent metrics:

    • Precision, PR-AUC, F1 and expected cost all change with the base rate.

    • On a balanced test set, precision looks far better than it will be at 1% prevalence. ROC-AUC, recall and specificity are prevalence-invariant, but they hide that problem.

  • Threshold and calibration tuning: Thresholds and calibrators fit on resampled validation data are tuned to the wrong prior. They then misfire in production.

  • Leakage and fabricated evidence: Synthetic or duplicated points in evaluation sets either mirror training data (leakage) or aren't real cases at all. Either way, scores are inflated.

  • How to do it:

    • Split first, using a stratified split (StratifiedKFold, train_test_split(stratify=y)).

    • Then resample only the training portion.

  • Nuance: the real goal is to match the deployment distribution. If production prevalence differs from your historical data, evaluate at (or reweight to) the expected production prior.

All Imbalanced Datasets interview questions