7

I want to optimize SVM parameters in Opencv. But, every time I use train_auto I get C=1 and gamma=1. Some people use LibSVM but I could not write a wrapper for that. Both trainingData and labels are taken from an existing code which gives good results so I am trying to get the same parameters for that code with train_auto. In the original code C=312.5 and gamma=0.50625. I saw that somebody used CvStatModel for python, is it necessary for C++? Where do I make a mistake? Thanks in advance.

The Code:

CvParamGrid CvParamGrid_C(pow(2.0,-5), pow(2.0,15), pow(2.0,2));
CvParamGrid CvParamGrid_gamma(pow(2.0,-15), pow(2.0,3), pow(2.0,2));
if (!CvParamGrid_C.check() || !CvParamGrid_gamma.check())
    cout<<"The grid is NOT VALID."<<endl;
CvSVMParams paramz;
paramz.kernel_type = CvSVM::RBF;
paramz.svm_type = CvSVM::C_SVC;
paramz.term_crit = cvTermCriteria(CV_TERMCRIT_ITER,100,0.000001);
svm.train_auto(trainingData, labels, Mat(), Mat(), paramz,10, CvParamGrid_C, CvParamGrid_gamma, CvSVM::get_default_grid(CvSVM::P), CvSVM::get_default_grid(CvSVM::NU), CvSVM::get_default_grid(CvSVM::COEF), CvSVM::get_default_grid(CvSVM::DEGREE), true);
svm.get_params();
cout<<"gamma:"<<paramz.gamma<<endl;
cout<<"C:"<<paramz.C<<endl;

1 Answer 1

5

I modified the code as follows paramz = svm.get_params() and it worked fine.

Sign up to request clarification or add additional context in comments.

1 Comment

Have you tried the initial parameters? How was the result? How long it took tor training? Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.