Tutorials › Statistical Learning (Graduate) › Consistency of K-Fold Cross-Validation for Finite Procedures

Validation and Data-Driven Tuning · Tutorial 277 of 989

Consistency of K-Fold Cross-Validation for Finite Procedures

Learn when K-fold cross-validation consistently estimates the risks of finitely many procedures, and why overlap between training sets requires care.

Advanced 12 min read

What You'll Learn

  • Define the random risk target associated with the training sets used in K-fold cross-validation
  • Distinguish unbiasedness in expectation from consistency in probability
  • Prove a finite-procedure consistency result under bounded loss and prediction convergence
  • See why the proof does not treat fold scores as independent
  • Apply uniform consistency to a finite validation-based selection rule

Why Consistency Needs More Than Unbiasedness

K-fold cross-validation reuses observations: each observation is assessed once and belongs to the training set for the other folds. Consequently, fold scores are generally dependent. Their dependence does not by itself rule out consistency, but it does mean that a law of large numbers for independent fold scores cannot simply be invoked.

A second issue is the target. A fold trains on fewer observations than the full data set, and each fold has its own fitted model. We first define the risk target that matches those fitted models. We then give sufficient conditions under which cross-validation estimates this target consistently for a finite collection of procedures.

Definition: Let \(Z_1,\ldots,Z_n\) be independent and identically distributed observations with common distribution \(F\), and let \(\ell(a,z)\) be a loss in \([0,1]\) for prediction or action \(a\) on observation \(z\). Divide the indices into \(K\) disjoint folds \(I_1,\ldots,I_K\) of equal size, where \(K\) is fixed and divides \(n\). For procedure \(j\), write \(A_j(D_{-k})\) for its fitted rule using all observations outside fold \(k\). Its \(K\)-fold score and its fold-risk target are

$$ \widehat R_{j,\mathrm{CV}} =\frac{1}{n}\sum_{k=1}^K\sum_{i\in I_k} \ell\bigl(A_j(D_{-k}),Z_i\bigr), \qquad T_{j,n} =\frac{1}{K}\sum_{k=1}^K R\bigl(A_j(D_{-k})\bigr), $$
where \(D_{-k}=(Z_i:i\notin I_k)\) and \(R(a)=E[\ell(a,Z)]\) for an independent \(Z\sim F\). The target is random because each fitted rule depends on its training data.

The training-set size in this definition is \(m=n(K-1)/K\). Thus \(T_{j,n}\) concerns the procedure trained on \(m\) observations, averaged over the \(K\) training sets. It is not automatically the risk of the same procedure trained on all \(n\) observations. If fold sizes differ by at most one, the definitions use weights \(|I_k|/n\) and the corresponding training sizes instead.

Unbiasedness for the Random Fold-Risk Target

Assume the folds are fixed in advance or are assigned independently of the observations. Conditional on \(D_{-k}\), each \(Z_i\) with \(i\in I_k\) remains an independent draw from \(F\). Therefore each held-out loss has conditional expectation equal to the risk of the rule fitted without that fold.

Proposition: Under the preceding sampling and fold-assignment conditions, for every procedure \(j\),

$$ E\!\left[\widehat R_{j,\mathrm{CV}}-T_{j,n}\right]=0. $$
This is unconditional unbiasedness for a random target. It does not assert that the score equals the target for each realized data set or fold assignment.

Proof. For any \(k\) and \(i\in I_k\), condition on the fold assignment and on \(D_{-k}\). The fitted rule \(A_j(D_{-k})\) is then fixed, while \(Z_i\) is independent of \(D_{-k}\) and has distribution \(F\). Hence

$$ E\!\left[\ell(A_j(D_{-k}),Z_i)\mid D_{-k},I_1,\ldots,I_K\right] =R(A_j(D_{-k})). $$

Summing over the \(n/K\) observations in each fold and dividing by \(n\) gives a conditional expectation of \(K^{-1}\sum_k R(A_j(D_{-k}))=T_{j,n}\). Taking expectations proves the proposition. The equality is an equality of expectations; it is not a sample-by-sample identity. \(\square\)

A Consistency Result for Finitely Many Procedures

Unbiasedness alone says nothing about whether the random difference between score and target becomes small. A convenient sufficient condition is that, in prediction loss, each fold-fitted rule approaches a fixed limiting rule. The condition below is deliberately explicit: it measures discrepancy on a fresh observation, averaged over the randomness in that fold’s training data.

Theorem: Let \(J\) be a fixed finite set of procedures. Suppose the observations are independent and identically distributed, the loss satisfies \(0\leq\ell\leq1\), and for each \(j\in J\) there is a fixed measurable rule \(a_j\) such that

$$ \max_{j\in J}\max_{1\leq k\leq K} E\left[ \left|\ell(A_j(D_{-k}),Z)-\ell(a_j,Z)\right| \right]\longrightarrow 0, $$
where \(Z\sim F\) is independent of \(D_{-k}\). If \(K\) is fixed and the fold assignment is independent of the observations, then

$$ \max_{j\in J}\left|\widehat R_{j,\mathrm{CV}}-T_{j,n}\right| \xrightarrow{p}0. $$

Proof. For each \(j\), let \(P_n\ell(a_j)=n^{-1}\sum_{i=1}^n\ell(a_j,Z_i)\), the empirical average for the fixed rule. Define

$$ W_{j,n} =\frac{1}{n}\sum_{k=1}^K\sum_{i\in I_k} \left|\ell(A_j(D_{-k}),Z_i)-\ell(a_j,Z_i)\right|. $$

The triangle inequality gives

$$ |\widehat R_{j,\mathrm{CV}}-T_{j,n}| \leq W_{j,n} +\left|P_n\ell(a_j)-R(a_j)\right| +\left|T_{j,n}-R(a_j)\right|. $$

For an observation \(Z_i\in I_k\), its fold-trained rule uses data outside \(I_k\), so \(Z_i\) is independent of that training data. Thus the expectation of each absolute difference in \(W_{j,n}\) is the discrepancy in the theorem’s assumption for fold \(k\). Because the folds have equal size,

$$ E[W_{j,n}] =\frac{1}{K}\sum_{k=1}^K E\left[\left|\ell(A_j(D_{-k}),Z)-\ell(a_j,Z)\right|\right] \longrightarrow 0. $$

Also, by the triangle inequality for integration,

$$ |T_{j,n}-R(a_j)| \leq \frac{1}{K}\sum_{k=1}^K E\left[\left|\ell(A_j(D_{-k}),Z)-\ell(a_j,Z)\right|\mid D_{-k}\right]. $$

Taking expectations shows \(E|T_{j,n}-R(a_j)|\to0\). Markov’s inequality therefore implies both \(W_{j,n}\xrightarrow{p}0\) and \(|T_{j,n}-R(a_j)|\xrightarrow{p}0\). Finally, the terms \(\ell(a_j,Z_i)\) are independent and bounded, so

$$ \operatorname{Var}\!\left(P_n\ell(a_j)\right) =\frac{\operatorname{Var}(\ell(a_j,Z))}{n} \leq \frac{1}{4n}. $$

Chebyshev’s inequality gives \(P_n\ell(a_j)\xrightarrow{p}R(a_j)\). The displayed triangle inequality now proves convergence for each \(j\). Since \(J\) is finite, the union bound gives convergence of the maximum: for every \(\varepsilon>0\), the probability that any procedure’s error exceeds \(\varepsilon\) is at most the sum of the finitely many corresponding probabilities, each of which tends to zero. \(\square\)

The proof handles overlapping training sets without pretending that fold scores are independent. It compares the fold-specific losses with losses from fixed rules, for which the ordinary independent-observation law of large numbers applies. The assumption is sufficient, not necessary; it may fail for procedures whose predictions continue to vary substantially with their training samples.

Worked Example: A Fixed Classifier

Let \(Y_i\sim\operatorname{Bernoulli}(0.3)\), let \(Z_i=Y_i\), and use the zero-one loss \(\ell(a,Y)=\mathbf{1}\{a\ne Y\}\). Consider a procedure that always predicts \(0\), regardless of its training data. Its fold-trained rule is the fixed rule \(a=0\), so every discrepancy in the theorem is zero.

The fold-risk target is \(T_{n}=P(Y=1)=0.3\). Each cross-validation loss is \(Y_i\), so

$$ \widehat R_{\mathrm{CV}}=\frac{1}{n}\sum_{i=1}^nY_i, \qquad E[\widehat R_{\mathrm{CV}}]=0.3, \qquad \operatorname{Var}(\widehat R_{\mathrm{CV}}) =\frac{0.3(0.7)}{n} =\frac{0.21}{n}. $$

For \(n=100\), the variance is \(0.0021\). Chebyshev’s inequality gives \(P(|\widehat R_{\mathrm{CV}}-0.3|\geq0.1)\leq0.0021/0.01=0.21\). This bound is conservative, but it tends to zero as \(n\) increases and confirms consistency directly.

Worked Example: A Fold-Fitted Probability Estimate

Suppose \(Y_i\sim\operatorname{Bernoulli}(p)\). A procedure estimates \(p\) by the training-sample mean \(q_{-k}\) and predicts that probability. Use the Brier loss \(\ell(q,y)=(y-q)^2\), which lies in \([0,1]\) for \(q,y\in[0,1]\). The limiting fixed rule predicts \(p\).

For \(y\in\{0,1\}\), factor the difference of squares:

$$ |(y-q)^2-(y-p)^2| =|q-p|\,|2y-q-p| \leq 2|q-p|, $$

because \(q,p,y\in[0,1]\) implies \(|2y-q-p|\leq2\). The training set has size \(m=n(K-1)/K\), so \(E[q_{-k}]=p\) and \(\operatorname{Var}(q_{-k})=p(1-p)/m\). By Cauchy–Schwarz,

$$ E|q_{-k}-p| \leq \sqrt{E[(q_{-k}-p)^2]} =\sqrt{\frac{p(1-p)}{m}}. $$

Consequently, the theorem’s loss discrepancy is at most \(2\sqrt{p(1-p)/m}\), which tends to zero as \(m\to\infty\). For \(p=0.4\), \(n=120\), and \(K=5\), \(m=96\), and this upper bound is \(2\sqrt{0.4(0.6)/96}=2\sqrt{0.0025}=0.1\). The bound is a finite-sample guarantee on the expected discrepancy; its convergence to zero as sample size increases is what supplies the theorem’s asymptotic condition.

Consequences for Choosing Among a Finite Set

Uniform consistency matters when the same cross-validation scores are used to select a procedure. Let \(\widehat j\) minimize \(\widehat R_{j,\mathrm{CV}}\) over \(j\in J\), and let \(j_n^*\) minimize the fold-risk targets \(T_{j,n}\). If there is a unique minimizer it is unambiguous; otherwise choose any minimizer. For each realized data set,

$$ T_{\widehat j,n} \leq \widehat R_{\widehat j,\mathrm{CV}}+\Delta_n \leq \widehat R_{j_n^*,\mathrm{CV}}+\Delta_n \leq T_{j_n^*,n}+2\Delta_n, \qquad \Delta_n=\max_{j\in J}|\widehat R_{j,\mathrm{CV}}-T_{j,n}|. $$

The first and last inequalities follow from the definition of \(\Delta_n\); the middle one follows because \(\widehat j\) minimizes the cross-validation score. The theorem implies \(\Delta_n\xrightarrow{p}0\), so the selected procedure’s target risk approaches the smallest target risk in the finite set, in the sense of this excess-risk bound. This statement concerns the fold-size targets, not automatically the risks of procedures refitted on all \(n\) observations.

Worked Example: Selecting Between Two Fixed Classifiers

Again let \(Y_i\sim\operatorname{Bernoulli}(0.3)\) and use zero-one loss. Compare the fixed classifier \(a_0=0\) with \(a_1=1\). Their risks are \(R(a_0)=0.3\) and \(R(a_1)=0.7\), so \(a_0\) is better by \(0.4\). Their cross-validation scores are respectively \(\bar Y\) and \(1-\bar Y\), regardless of the fold partition.

The procedure choosing \(a_1\) makes an error only if \(1-\bar Y\leq\bar Y\), or \(\bar Y\geq0.5\), with ties assigned to \(a_1\). Hoeffding’s inequality for independent Bernoulli observations yields

$$ P(\bar Y\geq0.5) =P(\bar Y-0.3\geq0.2) \leq \exp\{-2n(0.2)^2\} =\exp(-0.08n). $$

At \(n=100\), this upper bound is \(e^{-8}\approx0.0003355\). The bound tends to zero as \(n\) grows, illustrating reliable selection in this fixed-procedure example. For general trained procedures, the consistency theorem’s assumptions, rather than this particular Hoeffding calculation, are what justify the conclusion.

What Overlap Does—and Does Not—Permit

The training sets \(D_{-k}\) overlap heavily, so the random fold risks \(R(A_j(D_{-k}))\) can be dependent. Likewise, losses in different folds can be dependent because the fitted rules share training observations. The proof above does not require these fold quantities to be independent: it uses an expected discrepancy bound and an empirical average of fixed-rule losses.

A common mistake is to apply a concentration inequality for \(K\) independent fold scores, or to treat all \(n\) fitted losses as independent just because they are evaluated on \(n\) different observations. The correction is to identify which observations a fitted rule depends on and justify concentration for the actual dependence structure. Here, the theorem supplies a different route: compare with fixed limiting rules, then use independence only for their empirical losses.

Finally, the fact that \(E[\widehat R_{j,\mathrm{CV}}-T_{j,n}]=0\) does not mean the two quantities are close for a particular data set. Unbiasedness is an expectation statement; consistency is a probability statement about the absolute error shrinking. The prediction-convergence assumption is one transparent sufficient condition connecting the latter to the former.

Key takeaway: For a fixed finite set of procedures, bounded loss and convergence of fold-fitted predictions toward fixed rules imply uniform consistency of K-fold cross-validation for the fold-risk targets. The proof accounts for overlapping training sets rather than assuming away their dependence.

Check Your Understanding

Use the definitions and assumptions above to answer the following questions.

  1. Why is \(T_{j,n}\) random, and what training-set size does it target when folds are equal?
  2. What independence fact justifies the conditional expectation of a held-out loss given its fold’s training data?
  3. Why does the consistency proof not require the \(K\) fold scores to be independent?
  4. For the probability-estimation example, which quantity tends to zero as the training size grows, and what bound establishes this?
  5. Why does unbiasedness for \(T_{j,n}\) not by itself establish consistency for a realized data set?
Clinical Biostats