rish
rish

Reputation: 6005

SVM type in openCV

I am using opencv to develop a very simple classifer for image. I want to use svm type poly but it gives error while other like sigmoid, RBF works fine. I defined the parameters as follows:

SVMParams params;
params.svm_type = SVM::C_SVC;
params.kernel_type = SVM::POLY;
params.gamma = 20;
params.degree = 0;
params.coef0 = 0;

params.C = 7;
params.nu = 0.0;
params.p = 0.0;

params.class_weights = NULL;
params.term_crit.type = CV_TERMCRIT_ITER +CV_TERMCRIT_EPS;
params.term_crit.max_iter = 1000;
params.term_crit.epsilon = 1e-6;

The error reads openCV Error: One of arguments' values is out of range (The kernel parameter must be positive) in CvSVM::set_params. I am unsure what is the error about.?

Upvotes: 3

Views: 3479

Answers (1)

Marc Claesen
Marc Claesen

Reputation: 17026

For a polynomial kernel, degree must be larger than 1 (0 is invalid, 1 is linear). For most packages, the default value for degree is 3.

RBF and sigmoid kernels work fine with your settings because they don't use degree. For reference, the kernel functions in question are:

  • polynomial: k(u,v)=(gamma*u'*v + coef0)^degree,
  • RBF: k(u,v)=exp(-gamma*|u-v|^2),
  • sigmoid: k(u,v)=tanh(gamma*u'*v + coef0).

Upvotes: 9

Related Questions