CHI2 response in opencv SVM

asked 2017-04-14 04:37:24 -0600

alexMm1 gravatar image

Hi guys,

I'm having troubles understanding the output of the openCV CHI2 svm. Everything works fine but the output of:

float response1 = svm->predict(testing_matrix);

is a float number and not an integer like the case of LINEAR svm....It means that I have to take only the integer part of the response or I'm missing something?

thanks

edit retag flag offensive close merge delete

Comments

1

i can't reproduce it:

Ptr<ml::SVM> svm = ml::SVM::create();
svm->setKernel(ml::SVM::CHI2);

Mat_<float> data(4,2);
data << 1,1,  1.2,0.9,  3.3,2.8, 3.1,3.6;
Mat_<int> labels(4,1);
labels << -1,-1, 1,1;
svm->train(data,0,labels);

Mat_<float> query(4,2);
query << 0.8,1,  1.5,1.3,  3.9,2.5, 2.9,3.1;
Mat result;
svm->predict(query, result, 0); // use ml::StatModel::RAW_OUTPUT for the raw dot product;
cerr << result.t() << endl;

[-1,-1,1,1]
berak gravatar imageberak ( 2017-04-14 05:27:29 -0600 )edit

I'm trying your example.....I don't know why in your case it works perfectly....In my case, instead, I obtain something like 1.23456

alexMm1 gravatar imagealexMm1 ( 2017-04-14 07:50:34 -0600 )edit
1

the problem is in the use of ml::SVM::EPS_SVR instead of ml::SVM::C_SVC

alexMm1 gravatar imagealexMm1 ( 2017-04-14 07:56:35 -0600 )edit

can you specify the platform you are working on?

StevenPuttemans gravatar imageStevenPuttemans ( 2017-04-14 07:59:22 -0600 )edit

Linux ubuntu 16.04 and opencv3.0

alexMm1 gravatar imagealexMm1 ( 2017-04-14 08:03:36 -0600 )edit

Can you run OpenCV3.2 first? 3.0 is deprecated and not supported anymore ...

StevenPuttemans gravatar imageStevenPuttemans ( 2017-04-14 09:25:04 -0600 )edit
2

@alexMm1 , if the context is still your previous BOW idea - i'd think , you'd want classification(C_SVC), not regression(C_SVR) here, or not ?

(and indeed, regression returns float values, which are more like a "distance to class margin", not a label, so thresholding would not make any sense)

berak gravatar imageberak ( 2017-04-14 09:40:33 -0600 )edit

ok thanks @berak, understood

alexMm1 gravatar imagealexMm1 ( 2017-04-19 03:31:04 -0600 )edit