[R] Help with plot.svm from e1071

Joshua Gilbert joshuacgilbert at gmail.com
Wed Jan 18 20:41:35 CET 2006


I'm trying to plot a pair of intertwined spirals and an svm that
separates them. I'm having some trouble. Here's what I tried.

> library(mlbench)
> library(e1071)
Loading required package: class
> raw <- mlbench.spirals(200,2)
> spiral <- data.frame(class=as.factor(raw$classes), x=raw$x[,1], y=raw$x[,2])
> m <- svm(class~., data=spiral)
> plot(m, spiral)
Error in -x$index : invalid argument to unary operator

So we delve into e1071:::plot.svm. When I run the code in plot.svm
everything is fine up until
 points(formula, data = data[-x$index, ], pch = dataSymbol,
                 col = symbolPalette[colind[-x$index]])
That gives me the same error message, "Error in -x$index : invalid
argument to unary operator". The weird thing is that I can run either
of the those statements in isolation
data[-x$index, ]
and neither gives me an error. I looked in the two points functions I
can see (points.default and points.formula) but neither calls x$index.

I was following along the documentation for plot.svm, which has a
simple example (that works)
    ## a simple example
    m <- svm(Sex~., data = cats)
    plot(m, cats)

I don't see what the difference between their example and mine.

Can anyone help me?

Thank you,

More information about the R-help mailing list