I have two lists of parameters (gamma and cost) that I want to select using a SVM. I want to do 5-fold crossvalidation, but my code makes 10-fold cross validation (which is the default). My code is looking like this:
prioir_svm <- tune.svm(train, y = trainY, cost = Cs, gamma = gammas, cross = 5)
Can anyone tell me what is wrong?
You can use 'tune' function from 'e1071' package in R to tune the hyperparameters of SVM using a grid search algorithm. e.g. It will perform 10 fold cross-validation by partitioning our data into 10 parts. As proposed by Mojtaba Zeraatpisheh, you can also use 'caret' package for tuning.
Set the method parameter to “cv” and number parameter to 10. It means that we set the cross-validation with ten folds. We can set the number of the fold with any number, but the most common way is to set it to five or ten. The train() function is used to determine the method we use.
Try this instead:
tc <- tune.control(cross = 5)
prioir_svm <- tune.svm(train, y = trainY, cost = Cs, gamma = gammas,
tunecontrol = tc)
see ?tune.control
for details
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With