Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in plot, formula missing when using svm

Tags:

r

svm

I am trying to plot my svm model.

library(foreign)
library(e1071)

x <- read.arff("contact-lenses.arff")
#alt: x <- read.arff("http://storm.cis.fordham.edu/~gweiss/data-mining/weka-data/contact-lenses.arff")
model <- svm(`contact-lenses` ~ . , data = x, type = "C-classification", kernel = "linear")

The contact lens arff is the inbuilt data file in weka.

However, now i run into an error trying to plot the model.

 plot(model, x)
Error in plot.svm(model, x) : missing formula.
like image 763
aceminer Avatar asked Sep 08 '14 03:09

aceminer


1 Answers

The problem is that in in your model, you have multiple covariates. The plot() will only run automatically if your data= argument has exactly three columns (one of which is a response). For example, in the ?plot.svm help page, you can call

data(cats, package = "MASS")
m1 <- svm(Sex~., data = cats)
plot(m1, cats)

So since you can only show two dimensions on a plot, you need to specify what you want to use for x and y when you have more than one to choose from

cplus<-cats
cplus$Oth<-rnorm(nrow(cplus))
m2 <- svm(Sex~., data = cplus)
plot(m2, cplus) #error
plot(m2, cplus, Bwt~Hwt) #Ok
plot(m2, cplus, Hwt~Oth) #Ok

So that's why you're getting the "Missing Formula" error.

There is another catch as well. The plot.svm will only plot continuous variables along the x and y axes. The contact-lenses data.frame has only categorical variables. The plot.svm function simply does not support this as far as I can tell. You'll have to decide how you want to summarize that information in your own visualization.

like image 114
MrFlick Avatar answered Oct 15 '22 07:10

MrFlick