0

I am trying to use svm model from e1071 toolkit, simply like

model <- svm(train_set,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]

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?

roottraveller
  • 7,942
  • 7
  • 60
  • 65
jwlu
  • 1
  • 1
  • 1
  • Welcome to SO. To get better help, try to make a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – phiver Dec 27 '15 at 09:50
  • It's hard to tell without seeing a reproducible example, however I would suggest ensuring that all variables present in your test data are also present in your train data. – NGaffney Dec 27 '15 at 12:54

1 Answers1

1

From the e1071 docs:

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. It looks like you have 9 classes, represented as a 0-1 matrix. A factor vector with 9 levels should work. That could be done as:

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

Dthal
  • 3,216
  • 1
  • 16
  • 10