Error in plot, formula missing

前提是你 提交于 2019-11-27 23:51:57

问题


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.

回答1:


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.



来源:https://stackoverflow.com/questions/25716998/error-in-plot-formula-missing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!