Notes on Prediction Error
These are my notes after reading Chapter 7 of The Elements of Statistical Learning. The main question is simple: after fitting a model, how should we think about the error it will make on data that was not used to train it?
1. Several Errors That Sound Similar
The most immediate quantity is the training error:
This is easy to compute, but it is usually too optimistic. The model has already seen these responses, so a flexible model can reduce this number by fitting not only the signal but also part of the noise.
For a fixed training set \(\mathcal{T}\), the conditional test error is the expected loss on a new independent observation:
If we also average over possible training sets, we get the expected test error:
ESL also discusses in-sample error. Here the input points \(x_i\) are fixed at the observed training inputs, but the responses are imagined as newly sampled:
This separates two issues: evaluating on the same input locations, but not reusing the same noisy labels. It is useful for understanding why training error is biased downward.
2. Optimism
Optimism is the gap between in-sample error and training error:
A correction to my original notes: optimism is usually positive in expectation, not negative. The training error is called optimistic because it is smaller than the error we expect on newly sampled responses.
Under squared-error loss, fixing the predictors and averaging over the responses gives the expected optimism:
This formula is a compact way to say that overfitting is related to how strongly the fitted values move with the observed noisy responses. If \(\hat y_i\) changes a lot when \(y_i\) changes, then the model is using the training labels very aggressively.
Suppose the data follow:
The goal is to learn \(f\), not the realized noise \(\varepsilon_i\). When a model is too flexible, it may behave like:
This makes the training error look small, but the fitted function has absorbed random noise that will not repeat in future samples.
3. Effective Degrees of Freedom
For many linear fitting methods, the fitted values can be written as:
where \(S\) is a smoother matrix. In this case:
The quantity \(\operatorname{tr}(S)\) is called the effective degrees of freedom. Therefore:
For ordinary least squares with \(d\) parameters, \(\operatorname{tr}(S)=d\), giving the familiar correction:
For ridge regression,
Its effective degrees of freedom are:
where \(\eta_j\) are the eigenvalues of \(X^TX\). As \(\lambda\) increases, \(df(\lambda)\) decreases, so the model becomes less sensitive to individual noisy responses.
4. Bias-Variance Decomposition
For regression with squared error, assume:
At a fixed point \(x_0\), averaging over possible training sets and response noise:
This decomposes into:
A very simple model tends to have high bias and low variance. A very flexible model tends to have low bias and high variance. The useful model is rarely the one with the smallest training error; it is the one that manages this tradeoff best for new data.
5. How to Estimate Prediction Error
In practice, we usually do not know \(Err\). We estimate it. Common approaches include:
- Validation set: simple and honest, but can waste data when the sample size is small.
- Cross-validation: repeatedly holds out parts of the data and averages the error.
- Bootstrap: resamples the data to estimate uncertainty and prediction error.
- Analytic corrections such as \(C_p\), AIC, and related optimism-based criteria.
The conceptual link is that all of these methods try to correct the same problem: training error is not the same as future prediction error.
6. A Small Bayesian Note
A Bayesian model can express prediction uncertainty through the posterior predictive distribution:
This does not remove prediction error, but it changes how uncertainty is represented. Instead of only producing one fitted value, the model produces a distribution over possible future responses. From that distribution, we can evaluate expected loss under a chosen loss function.
What I Want to Remember
Prediction error is not just one number. Training error, in-sample error, conditional test error, and expected test error answer different questions. The most important warning is that a model can look good because it has learned the particular noise pattern in the training set. Optimism, effective degrees of freedom, and bias-variance decomposition are three different ways to describe this same danger.
Reference
- Hastie, T., Tibshirani, R., & Friedman, J. (2009). The Elements of Statistical Learning: Data Mining, Inference, and Prediction. Second Edition. Springer. Chapter 7.
© 2026 Hanwen Ju. All rights reserved. These notes are my own summary and interpretation of prediction error concepts from ESL. The original book remains the property of its authors and publisher.