简体   繁体   English

在R中使用e1071中的SVM

[英]Using SVM from e1071 in R

I am trying to use svm model from e1071 toolkit, simply like 我正在尝试使用e1071工具包中的svm模型,就像

model <- svm(train_set,set_label,scale=FALSE) 型号<-svm(trainset,set_label,scale = FALSE)

and the original form of label for each instance is array like [0,0,0,0,0,1,0,0,0] 每个实例的标签的原始格式为数组,例如[0,0,0,0,0,1,0,0,0]

Yet from this I would get the error : 但是从这个我会得到错误

 Error in predict.svm(ret, xhold, decision.values = TRUE) : 
 test data does not match model !

Then if every label is transformed to just one integer, it is fine. 然后,如果将每个标签转换为一个整数,就可以了。 So is it that the function svm just does not take array as output label? 那么函数svm只是不将数组作为输出标签吗?

From the e1071 docs: 从e1071文档中:

y - a response vector with one label for each row/component of x. Can 
be either a factor (for classification tasks) or a numeric vector (for  
regression).

What that means is that e1071's svm expects one label for each instance. 这意味着e1071的svm希望为每个实例分配一个标签。 It looks like you have 9 classes, represented as a 0-1 matrix. 看来您有9个类别,以0-1矩阵表示。 A factor vector with 9 levels should work. 具有9个级别的因子向量应该起作用。 That could be done as: 可以这样做:

labels <- as.factor(max.col(labels))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM