2

我在为包SVM中的垃圾邮件数据集绘制分类结果时遇到问题kernlab

代码

require(kernlab)

data(spam)

index <- sample(1:dim(spam)[1])
spamtrain <- spam[index[1:floor(dim(spam)[1]/2)], ]
spamtest <- spam[index[((ceiling(dim(spam)[1]/2)) + 1):dim(spam)[1]], ]

filter <- ksvm(type~.,data=spamtrain,kernel="rbfdot",kpar=list(sigma=0.05),C=5,cross=3)

plot(filter, data=spamtrain)

错误:

Error in `[.data.frame`(expand.grid(lis), , labels(terms(x))) : 
  undefined columns selected
4

2 回答 2

1

From what I can tell, plot.ksvm (which is called when you use plot on a ksvm object) can only plot objects with two features, i.e., the data matrix can only have two columns. Unfortunately, this is not mentioned anywhere in the documentation, and I just spent a couple of hours trying to understand what was going wrong. I don't know if this is planned to be fixed in the future.

于 2014-06-13T18:34:52.410 回答
0

您应该使用plotfrom packagekernlab以便它支持ksvm对象的格式。kernlab::plot(object, data=NULL, grid = 50, slice = list())

此处有关kernab图的文档中的更多信息:http: //cran.r-project.org/web/packages/kernlab/kernlab.pdf

于 2013-05-19T13:00:49.847 回答