2

I am having problem with plotting results of SVM classification for the spam dataset from kernlab package..

Code:

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:

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

2 Answers2

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.

Sarkom
  • 823
  • 10
  • 12
0

You should use plot from package kernlab so that it is supporting format of ksvm objects. kernlab::plot(object, data=NULL, grid = 50, slice = list())

More info in doc on kernab plot here: http://cran.r-project.org/web/packages/kernlab/kernlab.pdf

kiriloff
  • 25,609
  • 37
  • 148
  • 229