Tutorials › Exam PA - Predictive Analytics › Cross-Validation As A Generalization Estimate

Exam PA · Splits, Resampling, and Cross-Validation · Tutorial 690 of 966

Cross-Validation As A Generalization Estimate

Understand how held-out losses from repeated fits estimate the average generalization risk of a learning procedure trained on a specified number of observations.

Intermediate 12 min read

What You'll Learn

  • Define generalization risk for a learning procedure trained on a specified sample size
  • Derive why an observation held out from a fit can estimate risk on a new case
  • Interpret the average held-out loss when observations are reused across fits
  • Distinguish average risk across training samples from the risk of one final fitted model
  • Identify how predictor-based selection or unequal training sizes changes the target
  • Calculate cross-validated squared-error and Brier-loss estimates

What Does Cross-Validation Estimate?

A validation error is useful only when its target is clear. Cross-validation repeatedly fits a learning procedure on part of the observed data and evaluates that fit on observations left out of that particular fit. The held-out observations can be reused in other fits: an observation used for evaluation once may be used for training elsewhere. The key question is not simply how many times data are reused, but what average prediction risk the resulting held-out losses represent.

The target is generally the average performance of a learning procedure trained on a specified sample size, evaluated on a new case from the population. It is not automatically the error of the final model fitted on all available data. Nor does a held-out average have this interpretation merely because the held-out outcomes were not used to choose the split. The split design must also preserve the relevant distributions of training and evaluation observations.

Definition: Let \(D_m\) be a training sample of \(m\) independent observations from a population distribution \(P\). A learning procedure \(\mathcal{A}\), including its fitting steps, produces a prediction rule \(f_{D_m}\). For a new observation \(Z=(X,Y)\) from \(P\), and a loss function \(L\), the generalization risk at training size \(m\) is $$ R_m = E_{D_m}\left[E_{Z\sim P}\left\{L\bigl(Y,f_{D_m}(X)\bigr)\mid D_m\right\}\right]. $$ The inner expectation is the risk of the fitted rule on new cases, conditional on the training data. The outer expectation averages that risk over possible training samples of size \(m\).

For squared-error prediction, \(L(y,\hat y)=(y-\hat y)^2\). For binary classification with predicted event probability \(p\) and outcome \(y\in\{0,1\}\), the Brier loss is \(L(y,p)=(y-p)^2\). Other loss functions define other targets. The learning procedure includes any data-dependent operations that affect predictions, such as estimating preprocessing quantities or selecting model terms; those operations must be based on the training sample for the corresponding held-out loss to represent performance without access to the held-out case.

Why Held-Out Losses Can Estimate This Risk

Consider a split that assigns observations to training and evaluation sets independently of all their measured values. Suppose the observations are independent draws from the same population, every training set has size \(m\), and the entire learning procedure for each fit uses only that training set. For a particular fit, its training observations and its held-out observations are then independent samples from \(P\). Conditional on the fitted rule, each held-out case has the same distribution as a new case from \(P\).

This gives a short justification for the estimate. Let \(T_j\) denote training indices for fit \(j\), \(V_j\) its held-out indices, and \(n_j=|V_j|\). The average held-out loss for that fit is $$ \widehat R_j = \frac{1}{n_j}\sum_{i\in V_j} L\bigl(Y_i,f_{D_{T_j}}(X_i)\bigr). $$ Under the conditions just stated, each validation observation is independent of the training data used to construct its prediction and is distributed as a new observation from \(P\). Thus its expected loss, averaging over both the training sample and the new case, is \(R_m\). Averaging these expected losses gives $$ E\left[\frac{1}{J}\sum_{j=1}^{J}\widehat R_j\right] =\frac{1}{J}\sum_{j=1}^{J}E[\widehat R_j] =\frac{1}{J}\sum_{j=1}^{J}R_m =R_m. $$ This is an expectation statement about the validation design and repeated samples from the population. In one realized data set, the calculated cross-validation value is an estimate, not a guarantee that the population risk has been measured exactly.

The argument does not require the different held-out losses to be independent. The same observation can appear in several training sets, and fitted models can share much of their training data. These overlaps make the estimates related. Reuse is compatible with the expectation argument, but it does not turn the held-out losses into independent observations or, by itself, provide a standard error.

Worked Example: Averaging Squared Errors Across Reused Observations

A hypothetical exercise uses six independent policy records. A constant-mean prediction rule is fitted three times, each time to four records; the other two records are held out for that fit. The assignments were made independently of the recorded outcomes. The outcomes and resulting training means are shown below. Calculate the average held-out squared error and identify its risk target.

Fit 1. The training outcomes are 6, 8, 10, and 12, so the fitted constant is \( (6+8+10+12)/4=36/4=9 \). The held-out outcomes are 2 and 4. Their squared errors are \( (2-9)^2=49 \) and \( (4-9)^2=25 \), for a total of \(49+25=74\).

Fit 2. The training outcomes are 2, 4, 10, and 12, giving fitted constant \( (2+4+10+12)/4=28/4=7 \). The held-out outcomes are 6 and 8. Their squared errors are \( (6-7)^2=1 \) and \( (8-7)^2=1 \), for a total of \(2\).

Fit 3. The training outcomes are 2, 4, 6, and 8, giving fitted constant \( (2+4+6+8)/4=20/4=5 \). The held-out outcomes are 10 and 12. Their squared errors are \( (10-5)^2=25 \) and \( (12-5)^2=49 \), for a total of \(74\).

There are six held-out predictions in all. The total squared error is \(74+2+74=150\), so the average is \(150/6=25\). Equivalently, the three fold means are \(74/2=37\), \(2/2=1\), and \(74/2=37\), whose average is \((37+1+37)/3=25\). These agree because each fit has the same number of held-out records.

The estimate targets the average squared-error risk of this constant-mean learning procedure trained on four observations, provided the stated independent sampling and split conditions hold. It does not directly estimate the risk of a constant fitted to all six records. Method: calculate each fit's predictions from its own training outcomes, then average the losses on the records held out from that fit. The common mistake to avoid is treating the six outcomes as though they were each evaluated by one model trained on all six.

The Training Size Is Part of the Target

A procedure trained on fewer observations may perform differently from the same procedure trained on more observations. Therefore, if every fit uses \(m\) observations, the natural target is \(R_m\), not a risk with an unspecified training size. For example, if each fit holds out one fifth of the available sample, the resulting estimate concerns models trained on the remaining four fifths, subject to the sampling and split assumptions. A final model refitted on the entire data set has a different training size, so its risk need not equal the estimated \(R_m\).

If training-set sizes differ, there may be no single \(R_m\) that describes every fit. An equally weighted average of fit-level validation means estimates an average of risks at the corresponding training sizes, when each fit and its validation cases have the required distributions. If instead the goal is to give each held-out case equal weight, use the pooled average of all held-out losses. With unequal validation-set sizes, these two summaries can differ. The averaging rule should match the intended target and be reported clearly.

The same reasoning applies to the loss scale. A mean squared error is in squared outcome units; a root mean squared error is its square root and is not itself the average of case-level squared errors. For a probability prediction, the average Brier loss summarizes squared probability errors. A metric must be calculated consistently across held-out predictions before its interpretation is stated.

Worked Example: Computing a Held-Out Brier Loss

A hypothetical binary model is evaluated on four held-out claims. For each claim, the table gives the observed outcome \(y\) and the event probability \(p\) predicted by a model fitted without that claim. Calculate the mean Brier loss and state the relevant target, assuming each fit used the same number of independent training observations and the evaluation assignments were independent of the data.

For the first claim, \(y=1\) and \(p=0.8\), so the loss is \((1-0.8)^2=0.2^2=0.04\). For the second, \(y=0\) and \(p=0.3\), so the loss is \((0-0.3)^2=(-0.3)^2=0.09\). For the third, \(y=1\) and \(p=0.6\), so the loss is \((1-0.6)^2=0.4^2=0.16\). For the fourth, \(y=0\) and \(p=0.1\), so the loss is \((0-0.1)^2=(-0.1)^2=0.01\).

The total loss is \(0.04+0.09+0.16+0.01=0.30\). Dividing by four gives a mean Brier loss of \(0.30/4=0.0750\). Under the stated assumptions, this estimates the average Brier risk of the learning procedure at the training size used for those fits. It is not the error rate, because Brier loss measures squared probability error rather than whether a thresholded class prediction is correct.

Method: use the observed outcome and its own held-out probability to calculate each squared loss, then average. The common mistake to avoid is substituting a classification accuracy calculation for the specified probability loss.

When the Split Changes the Population Being Evaluated

The expectation argument depends on more than keeping held-out outcomes out of the fitting step. A split based on predictor values can produce held-out cases whose predictor distribution differs from that of a new population case. It can also change the distribution of training samples. In that situation, the held-out average may estimate performance for the split-induced distributions rather than \(R_m\) for the original population.

A split independent of all observations is a straightforward condition that supports the stated interpretation when the observations are independent and identically distributed. Other designs may be appropriate, but they require a clear argument that training and evaluation cases represent the distributions in the target risk, or an explicit target defined for the design-induced distributions. Where evaluation cases have been sampled with unequal probabilities, appropriate weighting may be needed to recover a population-level target.

Worked Example: Why Outcome-Blind Selection Is Not Enough

Suppose a hypothetical population has a binary predictor \(X\), with \(P(X=1)=0.5\) and \(P(X=0)=0.5\). The outcome is \(Y=X\), and a deliberately simple learning procedure always predicts zero, regardless of its training data. Use squared-error loss. Compare its population risk with the average loss in a validation set formed by selecting only cases with \(X=1\). The selection uses no outcomes.

For a new population case, the loss is \( (Y-0)^2=Y^2 \). Since \(Y=X\) is either zero or one, the loss is zero with probability \(0.5\) and one with probability \(0.5\). Thus the population risk is \(R_m=0.5(0)+0.5(1)=0.5\), for any training size \(m\).

In the selected validation set, every case has \(X=1\), hence \(Y=1\). Each held-out loss is \( (1-0)^2=1 \), so the average held-out loss is 1. This is twice the population risk: \(1\ne0.5\). The split did not use outcomes, but it selected on a predictor and changed the validation distribution.

Correction: to estimate risk for a new case from the stated population, use a split independent of all observations, or justify a design and weighting that restore the relevant population distributions. If the intended target is performance specifically among cases with \(X=1\), then the value 1 can be relevant, but it estimates that conditional risk, not the original population risk. The common mistake is to infer population representativeness merely from not looking at \(Y\).

Practical Interpretation and Common Traps

Cross-validation is useful because it allows observations to contribute to fitting in some fits and to evaluation in others, rather than reserving every evaluation case permanently. That reuse makes efficient use of a data set, but it does not remove the need to define the prediction setting. Independent, identically distributed observations are a suitable basis for the simple risk argument above. Repeated entities or ordered observations can violate that basis if the split lets related records or future information cross the evaluation boundary. In such cases, the validation design needs to reflect the intended deployment setting.

For an actuarial analysis, a risk estimate is meaningful only when the cases used for validation resemble the cases on which predictions will be used, and the metric matches the decision. For example, squared error may be appropriate when the magnitude of numerical prediction errors matters, whereas a probability loss may be more informative when assessing predicted event probabilities. The estimate still has sampling variability, and a favorable value does not prove that a model will perform equally well under population or operating conditions that differ from those represented in the validation design.

Key takeaway: An averaged held-out loss estimates the average generalization risk of the fitted learning procedure at the training size represented by the fits only when training and held-out cases have the distributions required by that risk. The split must support that interpretation; avoiding outcomes during split selection alone is not sufficient.

Check Your Understanding

For each problem, identify the calculation and the quantity it estimates. Assume independent population sampling unless the problem states otherwise.

  1. A squared-error validation set has four held-out losses: 1, 4, 0, and 9. Calculate the mean held-out loss. (Answer: \(14/4=3.5\).)
  2. Two validation fits have mean losses 0.2 on two held-out cases and 0.5 on three held-out cases. Calculate the pooled case-weighted mean loss. (Answer: \((2(0.2)+3(0.5))/5=1.9/5=0.38\).)
  3. Three held-out predictions, each from a fit trained on eight observations, have losses 2, 3, and 5. Calculate their average and state the training size of the risk it is intended to estimate under a suitable independent split. (Answer: \(10/3=3.333\ldots\), estimating risk at training size 8.)
  4. A population has a binary outcome with event probability 0.2. A fixed rule predicts probability zero for every case. What is its population Brier risk, and what is the mean Brier loss if validation cases are selected to include only events? (Answer: population risk \(0.2(1-0)^2+0.8(0-0)^2=0.2\); selected validation mean \(1.0\).)
  5. Two fits have different training sizes and validation means: 4 for the fit trained on 5 observations and 1 for the fit trained on 9 observations. If the two fit-level means are averaged equally, what is the result, and why is it not automatically a single \(R_m\)? (Answer: \((4+1)/2=2.5\); it averages performance at two different training sizes, so it does not automatically estimate risk at one common \(m\).)
Clinical Biostats