Abstract
Cross-validation is a widely-used technique to estimate prediction error, but its behavior is complex and not fully understood. Ideally, one would like to think that cross-validation estimates the prediction error for the model at hand, fit to the training data. We prove that this is not the case for the linear model fit by ordinary least squares; rather it estimates the average prediction error of models fit on other unseen training sets drawn from the same population. We further show that this phenomenon occurs for most popular estimates of prediction error, including data splitting, bootstrapping, and Mallow's $C_p$. Next, the standard confidence intervals for prediction error derived from cross-validation may have coverage far below the desired level. Because each data point is used for both training and testing, there are correlations among the measured accuracies for each fold, and so the usual estimate of variance is too small. We introduce a nested cross-validation scheme to estimate this variance more accurately, and show empirically that this modification leads to intervals with approximately correct coverage in many examples where traditional cross-validation intervals fail. Lastly, our analysis also shows that when producing confidence intervals for prediction accuracy with simple data splitting, one should not re-fit the model on the combined data, since this invalidates the confidence intervals.
Introduction
Cross-validation (CV) is the standard tool for assessing the performance of machine learning models. Despite its ubiquity, fundamental questions remain: what exactly does CV estimate, and how reliable are the uncertainty measures (confidence intervals) it provides? This paper addresses these questions, revealing that CV often estimates a different quantity than practitioners expect and that standard confidence intervals are frequently over-optimistic due to ignored correlations.
The Estimand Problem: What are we measuring?
Most practitioners believe CV estimates the prediction error of the specific model they have just trained on their available data, a quantity we denote as $Err_{XY}$. However, our theoretical analysis of linear models fit by Ordinary Least Squares (OLS) shows that CV is a "weak" estimator of this instance-specific error.
Instead, CV more accurately tracks the average error of the learning algorithm across the entire population ($Err$) or the average error over different label realizations for the same feature set ($Err_X$). This hierarchy of error targets is illustrated in Figure 2.
The lack of correlation between the CV estimate and $Err_{XY}$ is a critical finding. It implies that a low CV score does not necessarily mean the specific model in hand is better than average; it simply means the algorithm performs well on average for that data distribution. We prove this for OLS through the concept of linear invariance, showing that the CV estimate is statistically independent of the specific model's error, given the features.
The Uncertainty Problem: Why Confidence Intervals Fail
The second major issue identified is the "Uncertainty Problem." Standard confidence intervals (CIs) for CV error typically assume that the errors calculated in each fold are independent. In reality, because data points are reused for both training and testing across different folds, these errors are positively correlated.
Ignoring this correlation leads to variance estimates that are too small, resulting in confidence intervals that are too narrow. Consequently, these "naïve" intervals fail to provide the promised coverage—for example, a 90% CI might only contain the true error 70% of the time in high-dimensional settings.
Nested Cross-Validation (NCV)
To address the uncertainty problem, we propose Nested Cross-Validation (NCV). This method is designed to provide an unbiased estimate of the mean squared error (MSE) of the CV point estimate by accounting for internal correlations. The core idea is based on a "holdout MSE identity" that allows for an unbiased estimate of the variance of the CV point estimate.
NCV repeatedly splits the data into training and holdout sets. It performs CV on the training set and validates the resulting estimate against the holdout set. By averaging these differences, NCV "inflates" the confidence intervals to reflect the true underlying variance. While computationally more intensive—requiring significantly more model fits—it provides a much more robust measure of uncertainty.
Empirical Results
We validated our findings using both simulated Gaussian linear models and real-world datasets like "Communities and Crimes" and "Crop Mapping." As shown in Figure 4, the MSE of CV is significantly higher when targeting the instance-specific error ($Err_{XY}$) compared to the average error ($Err$). Furthermore, the miscoverage rate for standard CV intervals is unacceptably high for $Err_{XY}$. The rightmost panel of Figure 4 highlights the near-zero correlation between the CV estimate and the true $Err_{XY}$.
Conclusion
Cross-validation primarily estimates the average performance of an algorithm rather than the performance of a specific model instance. Practitioners should be wary of standard CV confidence intervals, especially in high-dimensional or small-sample settings. Nested Cross-Validation offers a principled way to obtain more reliable uncertainty estimates. Finally, we caution against the common practice of refitting models on combined data after a train-test split if valid confidence intervals are required, as refitting adds independent variation that invalidates the original interval.
Summary updated