4.9 Model selection

We have seen that in statistical learning a model that is too flexible will lead to overfitting and a model that is not flexible enough will lead to underfitting. We can control the flexibility of our model by either choosing the model class, e.g. the degree of a polynomial, or by introducing regularization. In either case this introduces a new parameter that we can not learn from the in-sample error. In this section we discuss how choose this parameter.

One approach is to use a validation set. We would take the available observations and divide them (randomly) into a training set and a validation set. The training set is used only for fitting the model(s) and the validation set is used for estimating the out-of-sample error. We could then choose the model that achieves the smallest error on the validation set. However note that the error of the chosen model is not a good estimate of the out-of-sample error, since again we have used the validation set for choosing a model. The drawback of this method is that the division into training and validation set is random and so if we are unlucky, the division does not represent the underlying distribution well.

An approach that tries to address this drawback is leave-one-out cross-validation (LOOCV). Here we again divide the observations into a training set and a validation set. The difference is that the validation set will only contain one observation, call this \((x_1,y_1)\). We fit the model on the \(n-1\) observations in the training set and predict the observation in the validation set. We then calculate the prediction error and call this (in the regression case) \(MSE_1\). We now repeat this, instead keeping \((x_2,y_2)\) in the validation set and all other in the training set. The LOOCV estimate of the out-of-sample error is then \[ CV_{(n)}= \frac{1}{n}\sum_{i=1}^n MSE_i. \]

The advantage compared to the validation set approach is that it always yields the same results and that there is less bias. This is because the size of the training set, \(n-1\), is almost the same as the full data set, \(n\). Therefore the fit should be almost as good as using the full data set.

The main drawback of LOOCV is that if \(n\) is large, it could be expensive to implement. An alternative is therefore k-fold cross-calidation. Here the data is divided randomly into \(k\) groups. We take the first group as validation set and the others as training set. This gives an out-of-sample error, call it \(MSE_1\). We continue by treating the second group as validation set, giving \(MSE_2\), and so on. The k-fold CV estimate of the out-of-sample error is then \[ CV_{(k)} = \frac{1}{k}\sum_{i=1}^k MSE_i. \] In practice usually \(k=5\) or \(k=10\) is used.