Actuarial Notes

Test Error

Study guides: Exam MAS-I, Exam MAS-II

A Test Error is the average error of a fitted model's predictions for test observations, which were not used to fit the model. It measures how well the model predicts new data, which is the aim of supervised learning. For a quantitative response, the test mean squared error is

\text{Test MSE} = \text{Ave}\left(y_0 - \hat{f}(x_0)\right)^{2}

  • (x_0, y_0) is a test observation, and \hat{f}(x_0) is the model's prediction for it.
  • \text{Ave} is the average over the test observations.

The training mean squared error is the same average over the n observations used to fit the model:

\text{Training MSE} = \frac{1}{n}\sum_{i=1}^{n}\left(y_i - \hat{f}(x_i)\right)^{2}

The fitting procedure minimizes the training error, so the training MSE decreases, or does not increase, as the flexibility of the model increases. For the same reason, adding a parameter to a GLM never increases its residual deviance. The training error therefore cannot choose between models of different flexibility. The test MSE first falls as flexibility increases and then rises once the model overfits, a U-shape explained by the bias-variance tradeoff. The model with the lowest test error is the best model.

Two severity models are compared by 5-fold cross-validation. Model A has training MSE 380 and fold MSEs 412, 398, 455, 430 and 405. Model B has training MSE 310 and fold MSEs 470, 380, 520, 445 and 435. Which model has the lower estimated test error?

  • The estimated test MSE of model A is the average of its fold MSEs, 2{,}100/5 = 420.
  • The estimated test MSE of model B is 2{,}250/5 = 450.
  • Model A has the lower estimated test error, although model B has the lower training error.

Test error rate of a classifier

For a qualitative response, the test error rate is the proportion of test observations that the model misclassifies:

\text{Test error rate} = \text{Ave}\left(I(y_0 \neq \hat{y}_0)\right)

  • \hat{y}_0 is the predicted class of the test observation, and y_0 is its actual class.
  • I(y_0 \neq \hat{y}_0) is 1 when the two classes differ and 0 when they are the same.

A classifier predicts fraud for 200 test claims. It labels 12 legitimate claims as fraudulent and misses 8 fraudulent claims. What is its test error rate?

  • The classifier misclassifies 12 + 8 = 20 of the 200 test claims.
  • The test error rate is 20/200 = 0.10.

Estimating the test error

When no separate test data are available, the test error is estimated by holding out part of the training data. The three methods of cross-validation compare as follows:

Method Model fits Bias of the estimate Variance of the estimate
Validation set 1 Highest, because the model is fitted to only part of the data High, because it depends on the random split
k-fold cross-validation k Moderate, because each fit uses (k-1)/k of the data Lower than leave-one-out
Leave-one-out cross-validation n Lowest, because each fit uses n - 1 observations Highest, because the n fits are highly correlated

A model fitted to fewer observations tends to fit worse, so an estimate from a smaller training set tends to overstate the test error of the model fitted to all the data. The n training sets of leave-one-out cross-validation are nearly identical, so their errors are highly positively correlated, and the mean of highly correlated quantities has a higher variance. AIC, BIC and C_p estimate the test error only indirectly, by adding a penalty for the number of parameters to the training error. They are computed on the same data used to choose the model and rely on an estimate of the error variance, so they are unreliable when the number of predictors is large compared with n (high-dimensional data).

Choosing the model with the lowest training error The most flexible model always has the lowest training error. In the example above, model B has the lower training MSE, 310 against 380, but the higher estimated test MSE, 450 against 420.

Practice questions

Actuarial Notes