[R] Using svm.plot with mlbench.spirals.

From: Joshua Gilbert <joshuacgilbert_at_gmail.com>
Date: Fri 20 Jan 2006 - 03:56:41 EST


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.

Can anyone help me?

Thank you,
Josh.



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Jan 20 04:04:15 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:06 EST