支持向量机分类器错误

时间:2018-01-05 16:37:37

标签: r machine-learning classification svm

我不明白为什么当我运行tune.svm然后我运行摘要时,我只有这个结果:

  

使用10倍交叉验证对'svm'进行错误估计:0.01385764,而我也期望最佳参数等。

我试过了:

tuned <- tune.svm(y~.,
                  data = training,
                  gamma = 10^-2, cost = 10^2,
                  tunecontrol = tune.control(cross = 10))

summary(tuned)
#> Error estimation of ‘svm’ using 10-fold cross validation: 0.01385764

和此:

set.seed(222)
tunesvm <- tune(svm, y ~ ., data = training, kernel = "sigmoid",
                ranges = list(cost = 0.001)
plot(tunesvm)
summary(tunesvm)
#> Error estimation of ‘svm’ using 10-fold cross validation: 0.01788785

1 个答案:

答案 0 :(得分:1)

您遇到的问题是由于您已经为每个超级参数指定了一个值。当每个参数中有一个可供选择时,您期望哪些最佳参数?

要获得最佳参数,您必须为超参数指定一系列值,CV将通过网格搜索从中选择最佳组合。

以下是一个完整的例子:

library(mlbench)
library(e1071)

data(Sonar)
set.seed(222)
tuned <- tune.svm(Class~.,
                  data = Sonar,
                  gamma = 10^(-1:-3), cost = 10^(1:3), ,
                  tunecontrol = tune.control(cross = 10))

summary(tuned)
#output:

Parameter tuning of ‘svm’:

- sampling method: 10-fold cross validation 

- best parameters:
 gamma cost
  0.01   10

- best performance: 0.1247619 

- Detailed performance results:
  gamma cost     error dispersion
1 0.100   10 0.2064286 0.08641724
2 0.010   10 0.1247619 0.07165924
3 0.001   10 0.2359524 0.08655125
4 0.100  100 0.2064286 0.08641724
5 0.010  100 0.1247619 0.07165924
6 0.001  100 0.2209524 0.09521693
7 0.100 1000 0.2064286 0.08641724
8 0.010 1000 0.1247619 0.07165924
9 0.001 1000 0.1823810 0.10762794

 plot(tuned)

enter image description here