# 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;
```

Are you doing auto_train or simple train?

In OpenCV docs it says that RBF is using the NormL2 and in LibSVM it says that RBF is using square absolute value (if you take in consideration the signs:

`|`

for LibSVM and`||`

for OpenCV). Could this be because of the distance function?These results are for simple train, since I obtained the parameters with my own cross validation. I will investigate the distance function, although OpenCV capped a 68% for other kernels and parameters.

Other tests with POLY kernel gave me different results also. For instance, OpenCV after training reach 64% of accuracy on the training set, while libSVM reach 90%, with the same parameters and data.

Did you find any clues to solve the problem？