R Tip: Support Vector Machines

This evening I was playing around with the support vector machines in R’s e1071 package. Following the suggestion of this excellent introduction I tried to tune the SVM, when I ran into this error:

> tune.mod1 <- tune(svm, fm1, data = train
, ranges = list(gamma = 2^(-1:1), cost = 2^(2:4))
, tunecontrol = tune.control(sampling = "cross", cross = 5)
, type = "C")

Error in double(nr * (nclass - 1)) : invalid 'length' argument

What does that mean?
After a while of messing with it I saw this error:

Error in tune(svm, fm1, data = train, ranges = list(gamma = 2^(-1:1), :
Dependent variable has wrong type!

This put me on the right track. I expected that the tune function would allow me to keep the dependent variable as an integer vector containing only 1’s and 0’s, since the function svm() allows this. I’d also expect that a factor with two levels would work fine.  For the tune function, neither is true. The dependent variable MUST BE LOGICAL!

Advertisements