Overfitting
Study guides: Exam SRM, ACIA-M2, Exam F2FIE
Overfitting is fitting a model so closely to its training data that it follows the noise in that sample as well as the signal, so that it predicts new observations worse than a simpler model would. James et al. (ISLR, §2.2.1) describe it as a method that yields a small training MSE but a large test MSE, and they reserve the word for the case in which a less flexible model would have given a smaller test MSE. It is the high-variance end of the bias-variance tradeoff.
The training MSE of a model \hat{f} fitted to n training observations is
\text{MSE}_{\text{train}} = \frac{1}{n}\sum_{i=1}^{n}\left(y_i - \hat{f}(x_i)\right)^2
y_iandx_iare the response and predictors of training observationi.
The test MSE averages the same squared error over observations that were not used in the fit, and it measures how well the model predicts new data. Flexibility means the number of coefficients, the number of leaves of a tree, the degrees of freedom of a spline, or a small K in K-nearest neighbors.
Training and test error as flexibility grows
Training MSE falls every time flexibility is added, because a model with as many free parameters as observations can reproduce them exactly. Training error therefore cannot be used to choose among models of different flexibility. Test MSE is U-shaped instead: past the minimum, each added parameter fits errors \varepsilon_i that belong to this sample only and will not recur, so the variance of \hat{f} rises by more than its squared bias falls. Models to the left of the minimum underfit, and models to the right overfit.
How do the training and test MSE of these two severity models compare? The true mean claim severity is $12,000 at every vehicle age, but the analyst does not know this. Model A predicts the training mean for every claim. Model B is a regression tree grown until each leaf holds one claim, so a new claim is predicted by the training claim nearest to it in age. The claims (vehicle age, severity in thousands) are:
Training claims New claims (1, 10) (1.2, 13) (2, 14) (2.2, 10) (3, 9) (2.8, 12) (4, 15) (3.9, 11) Answer
- Model B reproduces each training claim, so its training MSE is 0.
- Model A predicts
\bar{y} = 12, with training errors-2, 2, -3, 3, so its training MSE is(4 + 4 + 9 + 9)/4 = 6.5.- On the new claims, model A predicts 12 throughout, so its test MSE is
(1 + 4 + 0 + 1)/4 = 1.5.- Model B predicts
10, 14, 9, 15, so its test MSE is(9 + 16 + 9 + 16)/4 = 12.5.- Model B fits the training claims perfectly and predicts the new claims more than eight times worse than the flat model.
- Every split it made chased a random deviation from $12,000, and those deviations did not repeat in the new data.
Detecting overfitting
Overfitting shows only on data the fit did not use, so it is measured with a held-out validation set, k-fold cross-validation or the out-of-bag error of a bagged model. The signature is a validation or CV error that turns upward as flexibility keeps rising while the training error keeps falling.
To compare actual with predicted on holdout data, sort the holdout records by predicted value, group them into buckets of equal weight (quintiles, deciles), and compare the average actual with the average predicted in each. Actual-to-predicted ratios that run from above 1 in the lowest-predicted buckets to below 1 in the highest mean the predictions are too extreme. The model then predicts more variation between risks than the new data show, which is what an overfit model is expected to produce.
Which of these three severity models overfit, by ISLR's definition? Three severity models enter driver age in increasingly flexible ways:
Model Driver age entered as Training MSE Hold-out MSE A linear term 410 450 B spline, 6 degrees of freedom 360 400 C spline, 25 degrees of freedom 250 470 Answer
- Model C overfits. Its training MSE is the lowest, but a less flexible model, B, has a smaller hold-out MSE (
400 < 470).- Model B does not overfit, even though its hold-out MSE exceeds its training MSE by 40, because the only less flexible model, A, predicts worse (
450 > 400).- Model A underfits, because B shows that a curve in driver age predicts better than a line.
- B has the lowest hold-out MSE of the three and is the model to choose.
Remedies for overfitting
Each remedy lowers the variance of the fit. Pruning removes leaves, variable selection removes predictors and regularization (ridge or lasso) shrinks coefficients. Bagging and random forests average many trees, and more data reduces the variance of every estimate. The strength of each remedy (the pruning penalty \alpha, the penalty \lambda, the number of predictors) is itself a hyperparameter chosen by cross-validation.
A larger \alpha, \lambda or K makes the model less flexible and less prone to overfit. Adding trees does not overfit bagging or a random forest, but too many trees can overfit boosting, because each new tree fits the residuals of the last.
Reading a gap between training and test error as overfitting Training error below test error does not by itself mean the model overfits. Almost every model has this gap; overfitting means a less flexible model would have predicted better.
Practice questions
- Exam ATPA Practice Question 25
- Exam ATPA Practice Question 31
- Exam DISC-DA Practice Question 211
- Exam MAS-I Practice Question 128
- Exam MAS-I Practice Question 142
- Exam MAS-II Practice Question 7
- Exam PA Practice Question 4
- SOA Exam SRM Sample Question 25
- SOA Exam SRM Sample Question 60
- SOA Exam SRM Sample Question 73
- Exam SRM Practice Question 2