[R] repeated execution of svm(e1071) gives different results, if probability = TRUE is set
Valdas
vrkondrotas at gmail.com
Sun Jul 24 18:32:02 CEST 2011
Hello, Connoisseurs!
Please explain to novices, why svm model gives different results in the
loop with the same data? As a result, I can not find the best gamma and
cost parameters. Also tune.svm yields results that can not be repeated.
How can I avoid this?
My sessionInfo:
R version 2.11.1 (2010-05-31)
x86_64-pc-linux-gnu
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods
base
other attached packages:
[1] e1071_1.5-26 class_7.3-2
Here's a simple code example. You can run it a few times.
library('e1071')
prob <- function() {
model <- svm(Species ~ ., data = iris[-1,], probability=TRUE)
p <- predict(model, newdata=iris[1,], probability=TRUE)
pr <- attr(p, "probabilities")
print(pr)
return(pr)
}
cat('FirstCalc==SecondCalc:',all( prob() == prob() ),'\n')
Valdas
More information about the R-help
mailing list