I am using libsvm and I did a very simple experiment, training 10k vectors and testing with only 22. I am using the linear kernel with parameter cost C=1
. My problem is multiclass. So Libsvm will use the one-versus-one approach to classify my data.
Libsvm uses SMO to find the separating hyperplane.
A friend of mine did the same experiment, but the SVM classifier used was from the Statistics Toolbox. He also used the e1071 package from R. Again, the kernel used was the linear kernel, the parameter cost C
is equal to one, and the one-versus-one approach is used to classify the data in MATLAB (the one-versus-one approach was coded by my friend) and e1071 R package. Both the MATLAB Statistics Toolbox and e1071 from R use the SMO approach for finding the separating hyperplane by default.
I also tried the latest LIBLINEAR library. Again, the same configuration was used.
Here are the codes used:
libsvm 3.18 (command-line)
./svm-scale -s train.range train.libsvm > train.scale
./svm-scale -r train.range test.libsvm > test.scale
./svm-train -t 0 -c 1 train.scale train.model
./svm-predict test.scale train.model test.predict
liblinear 1.94 (command-line)
./svm-scale -s train.range train.libsvm > train.scale
./svm-scale -r train.range test.libsvm > test.scale
./train train.scale train.model
./predict test.scale train.model test.predict
R
rm(list = ls())
cat("\014")
library(e1071)
cat("Training model\n")
Traindata = read.csv("train.csv", header=FALSE)
SVM_model = svm(Traindata[,2:ncol(Traindata)], Traindata[,1], kernel="linear", tolerance=0.1, type="C-classification")
print(SVM_model)
cat("Testing model\n")
Testdata = read.csv("test.csv", header=FALSE)
Preddata = predict(SVM_model, Testdata[,2:ncol(Testdata)])
ConfMat = table(pred=Preddata, true=Testdata[,1])
print(ConfMat)
accuracy = 0
for (i in 1 : nrow(ConfMat)) {
for (j in 1 : ncol(ConfMat)) {
if (i == j) {
accuracy = accuracy + ConfMat[i, i]
}
}
}
accuracy = (accuracy / sum(ConfMat)) * 100
cat("Test vectors:", dim(Testdata), ", Accuracy =", accuracy, "%\n")
There are some accuracies differences:
- Libsvm correctly classified 11 of 22 test feature vectors
- Liblinear correctly classified 18 of 22 test feature vectors
- R correctly classified 17 of 22 test feature vectors
- My friend's one-versus-one MATLAB implementation correctly classified 19 of 22 feature vectors.
So why are the predictions different? I mean, if all the SVMs use linear kernels, with the same cost parameter and using the same approach for multiclass classification, shouldn't the result be the same?