[R] Help with plot.svm from e1071
David Meyer
david.meyer at wu-wien.ac.at
Fri Jan 20 04:03:42 CET 2006
Josh,
the problem here is that your code and mine refer to "x" and
non-standard evaluation happens in points(), looking up "x" in the
object supplied to "data". So your code will work when you are using,
e.g., "xx" instead of "x" in the data frame and the call to svm(). I
will fix this ASAP, thanks for pointing this out...
Cheers,
David.
----------
Hi.
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, ]
symbolPalette[colind[-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
library(MASS)
data(cats)
m <- svm(Sex~., data = cats)
plot(m, cats)
I don't see what the difference between their example and mine.
--
Dr. David Meyer
Department of Information Systems and Operations
Vienna University of Economics and Business Administration
Augasse 2-6, A-1090 Wien, Austria, Europe
Fax: +43-1-313 36x746
Tel: +43-1-313 36x4393
HP: http://wi.wu-wien.ac.at/~meyer/
More information about the R-help
mailing list