Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying k-fold cross validation using tune.svm() in R

Tags:

r

svm

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?

like image 406
Mads Obi Avatar asked Mar 17 '15 12:03

Mads Obi


People also ask

How do I tune a support vector machine in R?

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.

How do you do a 10 fold cross-validation in R?

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.


1 Answers

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

like image 80
Zelazny7 Avatar answered Sep 28 '22 08:09

Zelazny7