[R] training svm's with probability flag (re-send in plain text)

Jessie Tenenbaum jessiet at stanford.edu
Fri Aug 4 21:14:17 CEST 2006


Hi-

I'm seeing some weirdness with svm and tune.svm that I can't figure out- was
wondering if anyone else has seen this? Perhaps I'm failing to make
something the expected class?
Below is my repro case, though it *sometimes* doesn't repro. I'm using
R2.3.1 on WindowsXP. I was also seeing it happen with R2.1.1 and have seen
it on 2 different machines.
 
data(iris)
attach(iris)
library(e1071)
train<- iris[c(1:30,50:80,100:130),]
test<- iris[-c(1:30,50:80,100:130),]
y.train<- train$Species
y.test<- test$Species
obj<- tune.svm(train[,-5], y.train, gamma = 2^(-1:1), cost = 2^(2:4),
probability=T)
my.svm<- obj$best.model
pred1<- predict(my.svm, test[,-5])
pred2<- predict(my.svm, test[,-5], probability=T)
table(pred1, y.test)
table(pred2, y.test)

When I do this, the two different tables often come out different, as below:
> table(pred1, y.test)
            y.test
pred1        setosa versicolor virginica
  setosa         19          0         0
  versicolor      0         18         1
  virginica       0          1        19
> table(pred2, y.test)
            y.test
pred2        setosa versicolor virginica
  setosa         18          0         0
  versicolor      1         18         1
  virginica       0          1        19
> 

I'm not sure 1. why the results would differ based on whether I choose to
calculate the probabilities, and 2. which one to trust??
Anyone come across this before, or have any ideas?
 
thanks,
jessie



More information about the R-help mailing list