Summary
Cross-validation scores a training procedure on held-out observations under a declared deployment boundary. Decide whether the target is a new row, an unseen entity, or a future observation before choosing folds. The preprocessing, selection, fitting, scoring, and aggregation must all respect that boundary.
For a hypothetical new-patient task, patients A, B, and C each supply three visits. Hold out each entire patient, fitting on the other two; suppose the respective held-out errors are zero, one, and two. Equal-patient mean error is , matching because sizes are equal. Putting A1 into fitting and A2 into scoring fails this particular unseen-patient claim, even with balanced labels.
Learning objective
Choose splits that preserve users, time, and the evaluation claim
Derivation
Which assignment keeps user A from appearing on both sides?
Standard schemes
Single hold-out
Fit on one subset and score once on another. Use when the held-out population is adequate and repeated training costs more than its expected diagnostic value. One split does not by itself quantify selection or sampling uncertainty.
k-fold
Fit models, holding out one fold each time. For equal-sized folds and the same loss definition, average their scores; unequal folds need estimand-appropriate weights. For equal-user risk, first average within users instead of letting frequent users silently dominate. Fold training sets overlap, so their scores are dependent. The fixture’s fold sample standard deviation is , descriptive variability rather than a justified confidence interval.
Stratified k-fold
Preserve label proportions when compatible with the deployment boundary and available independent units. Check that each fold supports the requested metric. Class balance does not repair group overlap, future-derived features, or preprocessing leakage.
Group / GroupKFold
Assign every observation of an entity to the same fold when evaluating unseen entities. User, patient, or document grouping prevents that identity from crossing the boundary, not every possible leakage mechanism.
Time-series / TimeSeriesSplit
For forecasting, train on information available before the validation cutoff and score later observations. Check label availability, overlapping outcome windows, and necessary gaps or purging. A timestamp alone does not establish that forecasting is the intended evaluation task.
New task: Predict later visits for already known patients.
Picture and change: Replace unseen-patient exclusion with valid temporal cutoffs while retaining permitted identity history.
Check: Training through day ten may score day eleven, not day nine using day-ten information.
Use when: Future behavior, rather than unseen identity, is the claim.
Nested CV
Keep configuration selection inside each outer training subset; reserve its outer validation subset for scoring the selection procedure. Fit preprocessing, feature selection, and calibration only within their permitted training subsets too.
New task: Compare two configurations using two inner folds inside each of three outer folds.
Picture and change: Run the inner search, select, then refit on the outer training subset.
Check: fits, versus three without tuning. A later full-data refit adds one more.
Use when: Selection needs independent outer scoring and the compute budget supports it. The estimate still reflects its sampling design and training sizes, not an unconditional unbiasedness guarantee.
When NOT to cross-validate
- Adapted test set. Repeatedly changing the procedure after seeing test results removes its untouched-test interpretation.
- Full-data fitting. Feature selection, normalization, imputation, and target-derived transformations belong inside their training boundaries.
- Inappropriate deployment model. Repeated random splits cannot establish a future-only or unseen-entity claim they do not enforce.
Common pitfalls
- Wrong aggregation. Equal-fold, equal-row, and equal-entity averages need not match when sizes differ.
- False interval. Mean plus/minus fold standard deviation is not automatically a confidence interval.
- Wrong information time. Event timestamps do not prove that their features and labels were available at training time.
Reconstruct
What does the three-patient result fail to establish?
It does not provide a causal policy effect, a calibrated confidence interval, or a universal deployment guarantee. Its interpretation remains conditional on the hypothetical held-out predictions, chosen population, loss, and sampling design.
Related
- Data leakage and point-in-time correctness. Prevent future, target, group, and preprocessing leakage.
- A/B testing for ML. Online evaluation, complementary to offline CV.
- Calibration. Also evaluated on held-out data.