There are numerous threads in CrossValidated on the topic of model selection and cross validation. Here are a few:
- Internal vs external cross-validation and model selection
- @DikranMarsupial's top answer to Feature selection and cross-validation
However, the answers to those threads are fairly generic and mostly highlight the issues with particular approaches to cross validation and model selection.
To make things as concrete as possible, say for example that we are working with an SVM with an RBF kernel: $K(x, x' ) = (\gamma \, \vert x - x'\vert)^2$, and that I have a dataset of features X and labels y, and that I want to
- Find the best possible values of my model ($\gamma$ and $C$)
- Train the SVM with my dataset (for final deployment)
- Estimate the generalization error and the uncertainty (variance) around this error
To do so, I would personally do a grid search, e.g. I try every possible combination of $C$ and $\gamma$. For simplicity, we can assume the following ranges:
- $C \in \{10, 100, 1000\}$
- $\gamma \in \{0.1, 0.2, 0.5, 1.0\}$
More specifically, using my full dataset I do the following:
- For every ($C$,$\gamma$) pair, I do repeated iterations (e.g. 100 random repetitions) of $K$-fold cross validation (e.g. $K=10$), on my dataset, i.e. I train my SVM on $K-1$ folds and evaluate the error on the fold left, iterating through all $K$ folds. Overall, I collect 100 x 10 = 1000 test errors.
- For each such ($C$,$\gamma$) pair, I compute the mean and the variance of those 1000 test errors $\mu_M, \sigma_M$.
Now I want to choose the best model (the best kernel parameters) that I would use to train my final SVM on the full dataset. My understanding is that choosing the model that had the lowest error mean and variance $\mu_M$ and $\sigma_M$ would be the right choice, and that this model's $\mu_M$ are $\sigma_M$ are my best estimates of the model's generalization error bias and variance when training with the full dataset.
BUT, after reading the answers in the threads above, I am getting the impression that this method for choosing the best SVM for deployment and/or for estimating its error (generalization performance), is flawed, and that there are better ways of choosing the best SVM and reporting its error. If so, what are they? I am looking for a concrete answer please.
Sticking to this problem, how specifically can I choose the best model and properly estimate its generalization error?