Tutorials › Multivariate Statistics (Graduate) › Comparing Classifiers Across Cross-Validation Splits

Discriminant Inference and Risk · Tutorial 619 of 975

Comparing Classifiers Across Cross-Validation Splits

Use paired fold differences to compare classifiers fairly, then interpret corrected cross-validation uncertainty with appropriate caution.

Advanced 10 min read

What You'll Learn

  • Define paired differences in classification error on shared cross-validation test folds
  • Explain how overlapping training sets and reused observations induce dependence across splits
  • Derive the variance of an average under a common positive correlation
  • Calculate the Nadeau–Bengio corrected standard error for repeated cross-validation
  • Interpret uncertainty without treating a correction as an exact guarantee
  • Distinguish cross-validation comparison from inference about a final model trained on all observations

Why Compare Classifiers Pairwise?

When two classification procedures are evaluated on the same cross-validation splits, their errors should be compared within each split. A split on which the test cases are unusually difficult may raise both classifiers' errors. Subtracting their errors on that shared test fold removes some of this common variation and targets the difference between the procedures rather than the difficulty of the fold.

Pairing does not, however, make results from different folds or repetitions independent. Cross-validation training sets overlap, and repeated cross-validation reuses the same observations. This tutorial develops paired split-level differences and explains a commonly used correction for the resulting uncertainty. The correction is useful as a warning against overly small standard errors, but it is not an exact solution to the dependence problem.

Paired Differences on Shared Test Folds

Suppose \(J\) cross-validation evaluations use the same training and test split for classifiers A and B. On split \(j\), let \(\hat e_{Aj}\) and \(\hat e_{Bj}\) be their respective proportions of misclassified test observations. Define the paired difference as A's error minus B's error.

Definition: The split-level paired error difference is \(d_j=\hat e_{Aj}-\hat e_{Bj}\). A positive value means classifier B has lower error on split \(j\); a negative value means classifier A has lower error. The average difference is \(\bar d=J^{-1}\sum_{j=1}^J d_j\), and the sample variance of the split-level differences is \(s_d^2=(J-1)^{-1}\sum_{j=1}^J(d_j-\bar d)^2\).

The test observations must be shared for this pairing to be meaningful. For example, if A and B are assessed on different folds, the difference combines classifier performance with differences in test-set difficulty. A paired comparison holds that source of variation in common. When fold sizes are equal, averaging the \(d_j\)'s also gives the difference between the two classifiers' average fold errors. With unequal fold sizes, an observation-weighted overall error difference and an unweighted average of fold differences need not be the same quantity.

Worked Example: Calculating Paired Fold Differences

On three shared test folds, classifier A has error rates \(0.20, 0.10, 0.30\), while classifier B has error rates \(0.15, 0.15, 0.25\). Calculate the paired differences and their average.

Subtract B's error from A's error on each fold:

$$ d_1=0.20-0.15=0.05,\qquad d_2=0.10-0.15=-0.05,\qquad d_3=0.30-0.25=0.05. $$

Thus,

$$ \bar d=\frac{0.05-0.05+0.05}{3} =\frac{0.05}{3}\approx 0.0167. $$

A's average fold error is \((0.20+0.10+0.30)/3=0.20\), and B's is \((0.15+0.15+0.25)/3\approx 0.1833\). Their difference is about \(0.0167\), agreeing with \(\bar d\). The observed average favors B, but this calculation alone does not establish that the procedures differ beyond cross-validation variability.

Pairing Helps Within a Split, Not Across Splits

The benefit of pairing within a split can be stated directly in terms of variance. For any two error-rate random variables \(U\) and \(V\) with finite variances,

$$ \operatorname{Var}(U-V) =\operatorname{Var}(U)+\operatorname{Var}(V)-2\operatorname{Cov}(U,V). $$

If A's and B's errors tend to rise together on difficult test folds, their covariance is positive. Subtracting their errors can then be less variable than treating the two error rates as unrelated quantities. Pairing is therefore important even before considering the dependence between folds.

The usual standard error \(s_d/\sqrt{J}\) treats the \(J\) differences as independent observations. That assumption is generally implausible for cross-validation. In \(K\)-fold cross-validation, the training sets for two different folds overlap substantially. In repeated \(K\)-fold cross-validation, each observation appears in test folds repeatedly, while the fitted classifiers are based on highly overlapping training samples. Consequently, split-level differences can be correlated even though they are paired correctly within each split.

The effect of positive dependence can be derived in a simple model. This derivation does not assert that cross-validation differences have exactly this correlation structure; it shows why the independent-split calculation can be too optimistic.

Result: If \(D_1,\ldots,D_J\) have common variance \(\sigma^2\) and every distinct pair has common correlation \(\rho\), then \[ \operatorname{Var}(\bar D)=\frac{\sigma^2}{J}\{1+(J-1)\rho\}. \] This formula holds when the stated variances and pairwise covariances exist.

Derivation. By definition, \(\bar D=J^{-1}\sum_j D_j\). Expanding the variance as a sum of variances and covariances gives

$$ \begin{aligned} \operatorname{Var}(\bar D) &=\frac{1}{J^2}\left\{\sum_{j=1}^J\operatorname{Var}(D_j) +2\sum_{1\leq j<k\leq J}\operatorname{Cov}(D_j,D_k)\right\}\\ &=\frac{1}{J^2}\left\{J\sigma^2+2\binom{J}{2}\rho\sigma^2\right\}\\ &=\frac{\sigma^2}{J}\{1+(J-1)\rho\}. \end{aligned} $$

There are \(J(J-1)/2\) distinct pairs, which accounts for the second term in the expansion. When \(\rho=0\), the result reduces to \(\sigma^2/J\). When \(\rho>0\), the variance exceeds that independent-split value. In particular, collecting more highly correlated splits does not provide as much new information as the same number of independent evaluations would.

A Corrected Standard Error

A widely used approximate adjustment is the Nadeau–Bengio corrected resampled standard error. For \(J\) paired split differences, let \(n_{\text{train}}\) and \(n_{\text{test}}\) denote the training and test sizes for a split. The corrected variance estimate is

$$ \widehat{\operatorname{Var}}_{\mathrm{corr}}(\bar d) =\left(\frac{1}{J}+\frac{n_{\text{test}}}{n_{\text{train}}}\right)s_d^2, \qquad \widehat{\operatorname{SE}}_{\mathrm{corr}}(\bar d) =s_d\sqrt{\frac{1}{J}+\frac{n_{\text{test}}}{n_{\text{train}}}}. $$

For equal-sized \(K\)-fold splits, \(n_{\text{test}}/n_{\text{train}}=1/(K-1)\). In repeated \(K\)-fold cross-validation with \(R\) repetitions, \(J=RK\). Thus the correction factor is \(1/(RK)+1/(K-1)\), rather than just \(1/(RK)\). This formula uses the observed variability of the paired differences and adds a term intended to reflect dependence from the overlapping training samples.

The corrected standard error is an approximate uncertainty measure, not an exact variance formula under arbitrary cross-validation dependence. A commonly used corrected resampled \(t\) procedure divides \(\bar d\) by this standard error and compares the result with a \(t\) reference distribution using \(J-1\) degrees of freedom. That reference distribution does not make the split differences independent; the procedure is an approximation, and its calibration can be unreliable when the number of independent data units is small or the dependence structure is complicated.

Worked Example: Correcting the Standard Error

Suppose repeated five-fold cross-validation is run three times. There are \(J=3\times5=15\) paired differences, their mean is \(\bar d=0.04\), and their sample standard deviation is \(s_d=0.06\). Each test fold has one-fifth of the observations, so \(n_{\text{test}}/n_{\text{train}}=(1/5)/(4/5)=1/4\). Calculate the naive and corrected standard errors.

The naive independent-split standard error is

$$ \widehat{\operatorname{SE}}_{\mathrm{naive}} =\frac{0.06}{\sqrt{15}} \approx 0.0155. $$

The corrected factor is

$$ \frac{1}{15}+\frac{1}{4} =0.0667+0.25 \approx 0.3167. $$

Therefore,

$$ \widehat{\operatorname{SE}}_{\mathrm{corr}} =0.06\sqrt{0.3167} \approx 0.0338. $$

The corrected standard error is more than twice the naive value. The mean difference is positive, favoring B in observed error, but it is not large relative to this corrected uncertainty. For scale only, a normal-approximation interval would be \(0.04\pm1.96(0.0338)\), or approximately \((-0.026,0.106)\). This interval is illustrative rather than a guarantee of valid coverage: the correction and reference distribution remain approximate.

Worked Example: Four-Fold Cross-Validation

A single four-fold comparison produces paired error differences \(0.03,-0.01,0.02,0.00\). Compute the mean, sample standard deviation, and corrected standard error.

The mean is

$$ \bar d=\frac{0.03-0.01+0.02+0.00}{4}=0.01. $$

The deviations from the mean are \(0.02,-0.02,0.01,-0.01\). Their squared sum is

$$ 0.02^2+(-0.02)^2+0.01^2+(-0.01)^2 =0.0004+0.0004+0.0001+0.0001 =0.001. $$

With \(J-1=3\) in the sample-variance denominator,

$$ s_d^2=\frac{0.001}{3}\approx0.0003333, \qquad s_d\approx0.01826. $$

The test-to-training size ratio is \((1/4)/(3/4)=1/3\). The naive standard error is \(0.01826/\sqrt{4}\approx0.00913\), while the corrected value is

$$ 0.01826\sqrt{\frac{1}{4}+\frac{1}{3}} =0.01826\sqrt{\frac{7}{12}} \approx0.01394. $$

The positive mean again favors B, but the correction increases the estimated uncertainty. With only four split differences, neither the estimated standard deviation nor a \(t\)-based approximation should be treated as highly stable.

What the Correction Does—and Does Not—Establish

A cross-validation comparison concerns the procedures as trained on subsets of the available data. It does not directly measure the difference between two particular final classifiers fitted on the entire data set, nor does it automatically give an exact confidence interval for their population risks. The training-set size matters: a procedure trained on a fraction of the data may behave differently from the same procedure refitted on all observations.

The corrected standard error also cannot repair a poorly designed comparison. If model selection or tuning uses information from the test folds, the resulting evaluation can be optimistic; use nested cross-validation when selection must be included in the assessment. The comparison should otherwise hold the splits and evaluation metric in common, and should state whether algorithmic randomness is fixed or included in the procedure being evaluated.

A frequent mistake is to count all \(RK\) fold results as independent replications and report \(s_d/\sqrt{RK}\) as though each fold came from a new data set. The arithmetic is correct only under the independence assumption. Cross-validation folds share training observations, and repeated folds reuse test observations, so the assumption generally lacks justification. The corrected formula is a practical adjustment, not a proof that the resulting test has exact size or that more repetitions eliminate uncertainty.

Key takeaway: Compare classifiers by subtracting their errors on the same test folds. Summarize those paired differences, recognize that the differences across splits are dependent, and present corrected uncertainty as approximate rather than exact.

Check Your Understanding

Use these questions to check both the calculations and their interpretation.

  1. Why should two classifiers be evaluated on the same test fold before their errors are subtracted?
  2. For \(J\) differences with common variance \(\sigma^2\) and common pairwise correlation \(\rho\), what happens to the variance of their mean when \(\rho\) is positive?
  3. In repeated six-fold cross-validation with four repetitions, what are \(J\) and \(n_{\text{test}}/n_{\text{train}}\) for equal-sized folds?
  4. What assumption makes the naive standard error \(s_d/\sqrt{J}\) appropriate, and why is it questionable for cross-validation?
  5. Does the Nadeau–Bengio correction guarantee exact confidence-interval coverage? Explain what it adjusts and what it cannot guarantee.
Clinical Biostats