libsvm : C++ vs. MATLAB : What's With The Different Accuracies?

核能气质少年 提交于 2020-02-06 23:54:40

问题


I have two multi-class data sets with 5 labels, one for training, and the other for cross validation. These data sets are stored as .csv files, so they act as a control in this experiment.

I have a C++ wrapper for libsvm, and the MATLAB functions for libsvm.

For both C++ and MATLAB: Using a C-type SVM with an RBF kernel, I iterate over 2 lists of C and Gamma values. For each parameter combination, I train on the training data set and then predict the cross validation data set. I store the accuracy of the prediction in a 2D map which correlates to the C and Gamma value which yielded the accuracy.

I've recreated different training and cross validation data sets many, many times. Each time, the C++ and MATLAB accuracies are different; sometimes by a lot! Mostly MATLAB produces higher accuracies, but sometimes the C++ implementation is better.

What could be accounting for these differences? The C/Gamma values I'm trying are the same, as are the remaining SVM parameters (default).


回答1:


There should be no significant differences as both C and Matlab codes use the same svm.c file. So what can be the reason?

  • implementation error in your code(s), this is unfortunately the most probable one
  • used wrapper has some bug and/or use other version of libsvm then your matlab code (libsvm is written in pure C and comes with python, Matlab and java wrappers, so your C++ wrapper is "not official") or your wrapper assumes some additional default values, which are not default in C/Matlab/Python/Java implementations
  • you perform cross validation in somewhat randomized form (shuffling the data and then folding, which is completely correct and reasonable, but will lead to different results in two different runs)
  • There is some rounding/conversion performed during loading data from .csv in one (or both) of your codes which leads to inconsistencies (really not likely to happen, yet still possible)


来源:https://stackoverflow.com/questions/18880652/libsvm-c-vs-matlab-whats-with-the-different-accuracies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!