Solved – SVM in R (package e1071): predicting class using predict()

e1071machine learningrsvm

I have difficulties to understand predict.svm.
Please find an illustration of my confusion below.
As we can see, results are different depending on the probability argument of predict().
So my question is: what is the difference between probability=TRUE and probability=FALSE?

library(e1071)

# some illustrative data
data(iris)
attach(iris)
x <- subset(iris, select=-Species)
y <- factor(Species == "setosa")

# SVM
SVM <- svm(y ~ x[, 1], probability=TRUE) 

# predictions with 'probability=FALSE'
pred <- predict(SVM, x[, 1], probability=FALSE)
table(true=iris$Species == "setosa", pred=pred)
#        pred
# true    FALSE TRUE
#   FALSE    93    7
#   TRUE      5   45

# predictions with 'probability=TRUE'
pred <- predict(SVM, x[, 1], probability=TRUE)
table(true=iris$Species == "setosa", pred=pred)
#        pred
# true    FALSE TRUE
#   FALSE    94    6
#   TRUE     10   40

Best Answer

From the documentation you can read that see ?svm (or here):

The probability model for classification fits a logistic distribution using maximum likelihood to the decision values of all binary classifiers, and computes the a-posteriori class probabilities for the multi-class problem using quadratic optimization. The probabilistic regression model assumes (zero-mean) laplace-distributed errors for the predictions, and estimates the scale parameter using maximum likelihood.

Some more information can be found in libsvm documentation that svm function uses, and in JSS article Support Vector Machines in R.