I am trying to optimize the hyperparameters of SVM and CART with tune() function of e1071 R package, but I have a doubt. Should I tune the parameters on the training data, fit the model on the training data and then test it on the test data, or may I avoid the second step?
1 Answer
There's two common approaches here, depending on how much data you have.
If you have plenty of data, you'll probably be fine to:
set part of the training set aside, and call it your validation set;
start with a set of hyperparameters, train a model on your training set, evaluate performance on the validation set;
repeat step 2 with different hyperparameters;
pick the hyperparameters which give you the best score on the validation set;
train your model on the training set and the validation set;
Test your model ONCE on your test set.
Otherwise, you can do the following:
start with a set of hyperparameters, evaluate your model's performance on unseen data via cross-validation on the training set;
repeat step 2 with different hyperparameters;
pick the hyperparameters which give you the best score on the validation set;
train your model on the entire training set;
Test your model ONCE on your test set.
-
$\begingroup$ I have 100 subjects, so I'll probably go with the second option. And in case I'd use CV also for testing the model should I nest the two Cross Validation? The inner one for choosing the hyperparameters and the outer one to validate the model? $\endgroup$ Commented Oct 5, 2018 at 20:58
-
$\begingroup$ Yes - with such a small dataset, that is probably the best you can do $\endgroup$ Commented Oct 8, 2018 at 8:27
-
$\begingroup$ Thank you...last question: at the end I'll have a series of, for example, RMSE, one for each loop of CV. Should I choose the 'best' one or present all of them? $\endgroup$ Commented Oct 8, 2018 at 9:33