I have constructed SVM models with 5-fold cross validation technique. I want to use tune.svm() function for tuning best parameters. But, defaultly , 10-fold cross validation technique is used in tune.svm(). At the beginning of SVM when using 5-fold cross validation technique, we divide our data to 5 folds. But after, when we use tune.svm(), defaultly, it uses 10 fold-cross validation. I just want to learn that, how can we use tune.svm when we are using cross validation technique in SVM? And how can we find our best parametres in linear kernel with cross validation technique?
0
votes
1 Answers
1
votes
You can specify the the number of cross validations by using tunecontrol=tune.control(cross=..)
. If you read the help page (?tune.svm
), you will see that:
degree, gamma, coef0, cost, nu, class.weights, epsilon: ‘svm’
parameters.
These means that you can try to tune these parameters in svm, but you need to specify them.
So for example, if we tune gamma and cost, with cv=5:
m = tune.svm(x = iris[,1:4],y=as.numeric(iris$Species=="versicolor"),
tunecontrol=tune.control(cross=5),cost=1:3,gamma=seq(0,0.5,by=0.1))
m$performances
gamma cost error dispersion
1 0.0 1 0.30413429 0.074359870
2 0.1 1 0.05252970 0.015033730
3 0.2 1 0.03824034 0.010252205
4 0.3 1 0.03423748 0.009514754
5 0.4 1 0.03156347 0.008972839
6 0.5 1 0.03095934 0.009128068
7 0.0 2 0.30413429 0.074359870
8 0.1 2 0.04600002 0.013275795
9 0.2 2 0.03488123 0.008582790
10 0.3 2 0.03165164 0.008197322
11 0.4 2 0.03123569 0.008004122
12 0.5 2 0.03082393 0.009569036
13 0.0 3 0.30413429 0.074359870
14 0.1 3 0.04345943 0.012687920
15 0.2 3 0.03256819 0.006965251
16 0.3 3 0.03167265 0.007482398
17 0.4 3 0.03121712 0.008437225
18 0.5 3 0.03108899 0.010158448
m$best.parameters
gamma cost
12 0.5 2