[R] Help with plot.svm from e1071

From: Joshua Gilbert <joshuacgilbert_at_gmail.com>
Date: Thu 19 Jan 2006 - 06:41:35 EST


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,

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 Thu Jan 19 06:50:10 2006

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