【发布时间】:2016-07-26 20:07:21
【问题描述】:
我在 R 中使用包 e1071 来构建一类 SVM 模型。 我能够对其进行建模并打印模型,但我在绘制它时遇到了困难。
我关注了这个link,也关注了this,它使用了iris 数据集,但是所有SVM 示例都使用C 分类。
library(e1071)
day = c(0,1,2,3,4,5,6)
weather = c(6,5,4,3,2,1,0) #on the example, it was: c(1,0,0,0,0,0,0)
happy = factor(c(T,T,T,T,T,T,T)) #on the example it was: happy = factor(c(T,F,F,F,F,F,F))
d = data.frame(day=day, weather=weather, happy=happy)
model = svm(happy ~ day + weather, data = d, type='one-classification') #on the example it was: model = svm(happy ~ day + weather, data = d)
plot(model, d)
由于它是一类,我将因素修改为相同的标签。它给出了以下错误:
Error in rect(0, levels[-length(levels)], 1, levels[-1L], col = col)
cannot mix zero-length and non-zero-length coordinates
In addition: Warning messages:
1: package 'e1071' was built under R version 3.2.3
2: In Ops.factor(yorig, ret$fitted) : '-' not meaningful for factors
我使用的是 R 版本 3.2.2 (2015-08-14) (windows)。
如何绘制这个模型?
谢谢
【问题讨论】:
-
一分类不需要
nu参数吗? -
嗨@Sebastian M. Müller。是的,确实如此,但如果你不放,它会采用默认值 0.5
-
你试过
plot(model)吗? -
嗨@lejlot 我有。它给出了丢失数据的错误...参数数据丢失...
标签: r machine-learning classification svm libsvm