R:调整SVM参数 - {e1071}包中的class.weights

时间:2015-04-14 21:59:42

标签: r machine-learning classification svm training-data

我想用包{e1071}训练svm分类器。我意识到class.weight是我想调整的参数之一。例如。我想测试两个类权重c(25,50)和c(20,55)我想知道内置调整功能是否可以完成这项工作,如果是,那该怎么办?

以下是我的培训数据:

training.data  = 

  height0 height1 height2 weight0 weight1 gender class
1     0      1       0       1       0      1       1
2     0      1       0       0       1      0       1
3     0      1       0       0       0      1       1
4     1      0       0       1       0      0       1
5     0      1       0       0       1      0       2
6     0      1       0       0       1      0       2

并且响应变量中有2个级别' class'

training.data$class = 

[1] 1 1 1 1 2 2
Levels: 1 2

我想使用这样的函数,

param.obj <- tune(svm, class ~., data = training.data, 
    ranges = list("1" = c(25, 20), "2" = c(50,55) ),
    tunecontrol = tune.control(sampling = "cross", cross = 5) )

但我不认为这是正确的方法,因为如果我改变&#34; 2&#34;到&#34; 3&#34;它仍然有效。

param.obj <- tune(svm, class ~., data = training.data, 
    ranges = list("1" = c(25, 20), "3" = c(50,55) ),
    tunecontrol = tune.control(sampling = "cross", cross = 5) )

没有给我一个错误。我用Google搜索,但似乎无法找到正确的方法...感谢任何帮助!

1 个答案:

答案 0 :(得分:4)

ranges列表是参数的命名列表,您要调整的参数是class.weights。我相信你的音调范围就像是:

ranges=list (class.weights=list(c("1"=25, "2"=20), c("1"=50, "2"=55))