绘图错误,使用 svm 时缺少公式 [英] Error in plot, formula missing when using svm
问题描述
我正在尝试绘制我的 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")
隐形眼镜arff是weka中内置的数据文件.
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.
推荐答案
问题是在您的模型中,您有多个协变量.plot()
仅在您的 data=
参数正好有三列(其中一列是响应)时才会自动运行.例如,在 ?plot.svm
帮助页面中,您可以调用
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)
因此,由于您只能在图上显示两个维度,因此当您有多个可供选择时,您需要指定要用于 x
和 y
的内容来自
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.
还有一个问题.plot.svm
只会沿着 x
和 y
轴绘制连续变量.隐形眼镜 data.frame 只有分类变量.据我所知,plot.svm
函数根本不支持这一点.您必须决定如何在自己的可视化中总结这些信息.
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.
这篇关于绘图错误,使用 svm 时缺少公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!