Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV SVM gives different results than libSVM

I've looked around for posts on the same subject but I couldn't find any similar problem. Here is my situation :

I'm running OpenCV's SVM and libSVM algorithm on the same data, with the same settings and they give very different results. On the training set, OpenCV reaches an accuracy of 68% while libSVM reaches 85%. On the test set, OpenCV reaches 53% while libSVM gives 66%.

What could explain such differences ?

I also noticed that toying around with parameters on libSVM will change my results, but if I do the same kind of tests on OpenCV, the training accuracy reaches 68% and seems to be "capped" at that value. It rarely changes except with extreme parameter values.

The latest parameters I use came from a cross validation algorithm I ran on the data. SVM type : C_SVC, kernel = RBF, gamma = 0.08192, C = 12.8

My OpenCV settings :

_svm->setTermCriteria(cv::TermCriteria(cv::TermCriteria::MAX_ITER, 10000000, 1e-5));
_svm->setType(cv::ml::SVM::C_SVC);
_svm->setKernel(cv::ml::SVM::RBF);
_svm->setGamma(0.08192);
_svm->setC(12.8);

My libsvm settings :

svm_parameter param;
param.svm_type = 0;
param.C = 12.8;
param.nu = 0;
param.nr_weight = 0;
param.weight_label = NULL;
param.weight = NULL;
param.cache_size = 50;
param.eps = 1e-5;
param.p = 0;
param.shrinking = 0;
param.probability = 0;
param.kernel_type = 2;
param.degree = 0;
param.gamma = 0.08192;
param.coef0 = 0;