Cross Validation for Correlated Data in Classification Models

Oren Yuval, Saharon RossetAISTATS 2025

Abstract

We present a methodology for model evaluation and selection in binary classification models with the presence of correlations in the data, where the sampling mechanism violates the i.i.d. assumption. Our methodology involves a formulation of the bias term between the standard Cross-Validation (CV) estimator and the mean generalization error, and practical data-based procedures to estimate this term. Consequently, we present the bias-corrected CV estimator, which is the standard CV estimate supplemented by an estimate of the bias term. This concept was introduced in the literature only in the context of a linear model with squared error loss as the criterion for prediction performance. Our suggested bias-corrected CV estimator can be applied to any learning model, including deep neural networks, and to standard criteria for prediction performance for classification tasks, including misclassification rate, cross-entropy and hinge loss. We demonstrate the applicability of the proposed methodology in various scenarios where the data contains complex correlation structures (such as clustered and spatial relationships) with synthetic data and real-world datasets, providing evidence that the bias-corrected CV estimator is better than the standard CV estimator.

Introduction

Standard machine learning evaluation often relies on the assumption that data points are Independent and Identically Distributed (i.i.d.). Under this assumption, $K$-fold Cross-Validation (CV) serves as a reliable estimator for generalization error. However, real-world datasets—such as medical records with multiple entries per patient, spatial data in real estate, or temporal observations—frequently exhibit complex correlation structures. In these cases, the i.i.d. assumption is violated, and standard CV yields biased estimates of model performance, often leading to over-optimistic results or incorrect model selection.

Methodology

We propose a bias-corrected CV estimator, $CV_c$, designed to account for sampling mechanisms that violate the i.i.d. assumption.

The Bias-Corrected Estimator

We derive a general expression for the bias term, $w_{cv}$, defined as the difference between the standard CV estimator and the true mean generalization error. For common classification loss functions—including 0-1 loss, cross-entropy, and hinge loss—this bias is shown to be related to the covariance between predictions and actual labels across different sampling scenarios. The corrected estimator is defined as: $$CV_c = CV + w_{cv}$$

Estimation via Parametric Bootstrap

Since the true bias is typically unknown, we employ a parametric bootstrap approach. By fitting a model to the observed data and simulating synthetic datasets, we can estimate the covariance behavior and calculate $w_{cv}$.

Scaling to Deep Learning

To mitigate the computational cost of retraining deep neural networks (DNNs) during the bootstrap process, we introduce two techniques:

  1. Hot-start training: Initializing bootstrap training with pre-fitted weights.
  2. Last-layer analysis: Treating the DNN as a fixed feature extractor and applying the bias correction only to the final classification layer, modeled as a Generalized Linear Mixed Model.

Model Selection and Bias Correction

A critical consequence of CV bias in correlated data is the potential for incorrect model selection. Standard CV may favor sub-optimal models because the correlation structure within training folds does not accurately reflect the relationship with unseen test data. The bias-corrected estimator addresses this by aligning the selection criteria with true generalization performance.

Figure 2: Model selection task comparing Generalization Error (Gen-Err), standard CV, and bias-corrected CV ($CV_c$). Standard CV incorrectly ranks the models, while $CV_c$ aligns with the true generalization error.

Experimental Results

The proposed methodology was validated across synthetic mixed logistic regression, the CelebA facial image dataset (clustered by identity), and NYC Airbnb listings (spatial correlation).

Performance Estimation

In all scenarios, the $CV_c$ estimator provided a significantly more accurate estimate of the true generalization error compared to standard CV. As shown in Figure 1, the distribution of $CV_c$ estimates is shifted closer to the true generalization error, effectively correcting the over-optimism inherent in standard CV for correlated data.

Figure 1: Comparison of error distributions for Cross-entropy and Zero-One loss. The bias-corrected estimator ($CV_c$, green) consistently tracks the true generalization error (Gen-Err, dotted) more closely than standard CV (blue).

Conclusion

This work extends bias-corrected cross-validation from linear models with squared error loss to general classification tasks and complex learning models, including deep neural networks. By accounting for data correlations, the $CV_c$ estimator provides a more robust framework for model evaluation and selection in real-world, non-i.i.d. settings. Future work includes extending this framework to multi-class problems and metrics such as Area Under the ROC Curve (AUC).

Summary updated

BibTeX
@inproceedings{yuval2025cross,
  author = {Oren Yuval and Saharon Rosset},
  title = {{Cross Validation for Correlated Data in Classification Models}},
  booktitle = {International Conference on Artificial Intelligence and Statistics},
  year = {2025},
  url = {https://openreview.net/forum?id=zkTdiuQSnR},
}
Figure