Tutorials › Exam SRM - Statistics for Risk Modeling › Generalization Error as the Prediction Target

Exam SRM · Bias, Variance, and Overfitting · Tutorial 756 of 926

Generalization Error as the Prediction Target

Learn to define the prediction target precisely, calculate expected loss for new observations, and recognize why the fitting sample’s error may give a different picture.

Intermediate 10 min read

What You'll Learn

  • Define generalization error for a fitted predictor and a specified target population.
  • Distinguish expected loss on a fresh observation from average loss on fitting data.
  • Calculate generalization error from a discrete population distribution.
  • Compare predictors when the target population has different group proportions from the observed sample.
  • Identify how the chosen loss function changes the quantity being evaluated.
  • Recognize why reusing fitting data can give a misleading assessment of prediction quality.

Introduction

A prediction model is used because it will encounter observations that were not available when it was fitted. Its performance on those future observations is therefore a different question from how closely it matches the data used to build it. The distinction matters whenever a model is assessed for a target population: the relevant quantity is the expected loss on a new observation from that population.

For example, a hypothetical insurer might use application information to predict whether a policy will generate a claim. The average error among applications used to fit the model describes its performance on those particular records. To describe expected performance on new applications, we need a probability distribution for the target population and a specified measure of prediction loss.

Definition: Let \(D\) denote the data used to fit a predictor, and let \(f_D\) be the resulting predictor. Let \((X_{\mathrm{new}},Y_{\mathrm{new}})\) be a new observation from the target population, and let \(L(y,\hat y)\) be the loss for predicting \(\hat y\) when the outcome is \(y\). The generalization error for the fitted predictor is $$ R(f_D)=E\left[L\left(Y_{\mathrm{new}},f_D(X_{\mathrm{new}})\right)\mid D\right]. $$ Here the fitted predictor and the fitting data are held fixed; the expectation is over a new observation from the specified target population.

The loss function and target population are both part of this definition. Squared error, absolute error, and zero-one classification loss measure different kinds of prediction performance. Likewise, expected loss for new policy applications in one mix of applicant groups need not equal expected loss for a different mix. A numerical generalization error is not fully specified until both choices are clear.

The expectation is conditional on the fitted data \(D\): once the model has been fitted, \(f_D\) is treated as fixed. If the fitting data were collected again and the model refitted, the resulting predictor—and its generalization error—could change. Averaging over possible fitting data as well is a distinct quantity, \(E_D[R(f_D)]\), which describes performance averaged over repeated fits. It should not be confused with the conditional generalization error of the particular model currently in hand.

Why Generalization Error Is an Expectation

A new observation is uncertain. Even with the predictor fixed, the outcome and the input for that observation may vary. Expected loss averages the loss over their joint distribution in the target population. In a finite, discrete population model, this is a probability-weighted sum. For a continuous distribution, the corresponding expectation is an integral.

For a discrete set of possible new observations \(z_j=(x_j,y_j)\), with target-population probabilities \(p_j\), the formula follows directly from the definition of expectation:

$$ R(f_D)=\sum_j p_j L\left(y_j,f_D(x_j)\right), \qquad \sum_j p_j=1. $$

Each possible observation contributes its loss multiplied by the probability of that observation. The formula requires probabilities for the target population, not merely counts in the fitting sample. If observations instead have a continuous distribution, the same logic is expressed as \(R(f_D)=\int L(y,f_D(x))\,dP(x,y)\), where \(P\) is the joint target-population distribution.

1
Fix the prediction task.
State what \(X\) contains, what outcome \(Y\) is being predicted, and which population the future observations represent.
2
Choose the loss.
Specify how the difference between \(Y\) and its prediction is scored. The loss must match the prediction goal.
3
Average over new observations.
Weight each possible loss by its probability in the target population, or take the corresponding expectation.

Worked Examples

Worked Example: Squared Loss for a Warranty Model

A hypothetical appliance warranty model predicts the claim amount \(Y\) for a new warranty record. The fitted predictor gives a prediction of 2 thousand dollars for group A and 6 thousand dollars for group B. In the target population, a new record is in group A with probability 0.75 and group B with probability 0.25. Conditional on group A, the claim amount is 0 thousand dollars with probability 0.8 and 10 thousand dollars with probability 0.2. Conditional on group B, the two claim amounts, 0 and 10 thousand dollars, each have probability 0.5. Calculate generalization error using squared loss, with amounts measured in thousands of dollars. For comparison, the fitting sample contains four group A records with claim amounts 0, 0, 0, and 10.

Method. Calculate the expected squared loss within each group, then weight the group results by their probabilities in the target population. Use \(L(y,\hat y)=(y-\hat y)^2\).

Group A. The prediction is 2. For a 0 claim, the squared error is \((0-2)^2=4\); for a 10 claim, it is \((10-2)^2=64\). Thus the expected squared loss within group A is

$$ 0.8(4)+0.2(64)=3.2+12.8=16. $$

Group B. The prediction is 6. The squared errors for claims of 0 and 10 are \((0-6)^2=36\) and \((10-6)^2=16\), respectively. Therefore, its expected squared loss is

$$ 0.5(36)+0.5(16)=18+8=26. $$

Target-population average. Weight the group-specific expectations by the target probabilities:

$$ R(f_D)=0.75(16)+0.25(26)=12+6.5=18.5. $$

The generalization error is 18.5 squared-thousand-dollars units. The fitting-sample squared errors are 4, 4, 4, and 64, so their average is \((4+4+4+64)/4=19\) in the same units. The two quantities are close here, but they are calculated from different information: the sample average uses four observed records, while generalization error uses the target distribution, including group B. The calculation is checked by verifying that the group probabilities, 0.75 and 0.25, sum to 1 and that 18.5 lies between the group-specific risks of 16 and 26. A common mistake is to treat the four fitting records as if they defined the target population; doing so would omit group B altogether.

Worked Example: Classification Error in a New Applicant Population

A hypothetical model classifies applications as either “refer for review” or “do not refer.” Use zero-one loss: a correct classification has loss 0 and an incorrect classification has loss 1. In the target population, 80% of applications are in a low-risk group and 20% are in a high-risk group. The model predicts “do not refer” for every low-risk application and “refer” for every high-risk application. In the low-risk group, 5% of outcomes actually require referral; in the high-risk group, 30% do not require referral. A fitting sample has 8 low-risk and 2 high-risk applications, and all 10 are classified correctly. Find the target generalization error and the fitting-sample error.

Method. For each group, the zero-one loss is 1 exactly when the predicted class is wrong. First calculate each group’s error probability, then weight by the target group proportions.

For the low-risk group, the model predicts “do not refer,” so its error probability is the probability that referral is actually required: 0.05. For the high-risk group, it predicts “refer,” so its error probability is the probability that referral is not required: 0.30. The target-population error probability is therefore

$$ R(f_D)=0.80(0.05)+0.20(0.30)=0.04+0.06=0.10. $$

Thus, expected zero-one loss for a new target-population application is 0.10, or 10%. All 10 fitting records are classified correctly, so the average zero-one loss on that sample is \(0/10=0\). Both calculations are consistent with the data: a sample with no errors can occur even when the target error probability is positive. The common mistake is to report the fitting-sample error of 0% as if it were the expected error for new applications. The correction is to average the group-specific error probabilities using the target mix, which gives 10%.

Worked Example: Target Group Proportions Change the Comparison

Two fixed predictors estimate a future service cost, measured in dollars, for customers in groups A and B. The target population has 90% group A and 10% group B. The true costs for the two group profiles are 10 and 30 dollars. Predictor \(f_1\) predicts 11 dollars for A and 22 dollars for B. Predictor \(f_2\) predicts 6 dollars for A and 29 dollars for B. The fitting sample used to produce the predictors has one record from each group, with the stated costs. Compare the predictors using absolute loss.

Method. With absolute loss \(L(y,\hat y)=|y-\hat y|\), calculate each predictor’s group-specific errors and average them using the target probabilities. Then separately calculate the average errors on the two-record fitting sample.

For \(f_1\), the absolute errors are \(|10-11|=1\) dollar in group A and \(|30-22|=8\) dollars in group B. Its target generalization error is

$$ R(f_1)=0.90(1)+0.10(8)=0.90+0.80=1.70\text{ dollars}. $$

For \(f_2\), the absolute errors are \(|10-6|=4\) dollars in A and \(|30-29|=1\) dollar in B. Its target generalization error is

$$ R(f_2)=0.90(4)+0.10(1)=3.60+0.10=3.70\text{ dollars}. $$

On the fitting sample, each group appears once. The average absolute error for \(f_1\) is \((1+8)/2=4.50\) dollars, while for \(f_2\) it is \((4+1)/2=2.50\) dollars. Thus the fitting-sample comparison favors \(f_2\), but the target-population comparison favors \(f_1\). This is not a contradiction: equal weighting of the two sample records differs from the target population’s 90-to-10 group mix. The arithmetic checks because the target weights sum to 1, and each reported risk is the corresponding weighted average. The trap is to assume the sample proportions are the target proportions; use the specified target distribution when that is the prediction goal.

What the Quantity Does—and Does Not—Say

Generalization error answers a specific question: for this fitted predictor, this loss, and this target distribution, what is the expected loss for a new observation? It does not say that every future prediction will have that loss. Individual losses vary, and an expectation summarizes them across the target population.

The target population must be chosen deliberately. It could be all eligible applications next month, a specified region, or a particular mixture of risk groups. The distribution used in the calculation must correspond to that target. If the target differs from the data used to fit the model, the target distribution—not the fitting-sample proportions—defines the expectation.

The choice of loss also affects interpretation. Squared loss gives greater weight to large errors because errors are squared. Absolute loss measures error magnitude in the outcome’s original units. Zero-one loss records whether a classification is wrong, without distinguishing a small error from a costly one. A model’s generalization error under one loss does not, by itself, establish its performance under another.

A useful check is to name all three elements before calculating: the fitted predictor, the loss function, and the target distribution. Then make clear whether the reported quantity is an expectation over fresh observations or an average over the particular observations already used. The two may happen to be numerically equal, but they are not the same definition.

Key takeaway: Generalization error is expected loss for a new observation drawn from a stated target population, with the fitted predictor held fixed. Loss calculated on fitting data is an average over those particular observations and need not equal that expectation.

Check Your Understanding

For each problem, identify the relevant target distribution and loss before calculating.

  1. A fitted predictor gives \(\hat y=3\). In the target population, \(Y=1\) with probability 0.6 and \(Y=5\) with probability 0.4. Find generalization error under squared loss. (Answer: 4)
  2. A classifier has target-population error probabilities of 0.08 in group A and 0.20 in group B. The target population is 75% A and 25% B. Find its zero-one generalization error. (Answer: 0.1100, or 11%)
  3. A predictor has absolute errors of 2 dollars in group A and 12 dollars in group B. The fitting sample is half A and half B, but the target population is 80% A and 20% B. Find the fitting-sample average absolute error and target generalization error. (Answer: fitting-sample average = 7 dollars; target generalization error = 4 dollars)
  4. Two predictors have absolute errors of 3 and 9 dollars in groups A and B for predictor 1, and 5 and 2 dollars for predictor 2. The target population is 60% A and 40% B. Calculate each generalization error and state which predictor has lower expected loss. (Answer: predictor 1 = 5.40 dollars; predictor 2 = 3.80 dollars; predictor 2 has lower expected loss)
  5. A binary classifier has error probability 0.10 in group A and 0.30 in group B. A fitting sample contains 90% A, while the target population contains 50% A. Calculate both the fitting-proportion weighted error and target generalization error. (Answer: fitting-proportion weighted error = 0.1200; target generalization error = 0.2000)
Clinical Biostats