Ask Your Question
0

SVM class weights

asked 2014-10-23 04:37:16 -0600

thdrksdfthmn gravatar image

updated 2014-10-23 09:45:28 -0600

I am trying to tune my SVM classifier, so I have created a config file for not building the application of training/testing every time I change a parameter. Everything goes ok, but I have a little problem with the class_weights parameter: because I use a json, I need to know how does the parameter look like? I know that is is a CvMat pointer, but how many values do I give to it, one for each class? is it a 1-row Mat, or a 1-col Mat (like a vector)? Or it has a weight for each image (I do not think so)? So is it ok to read it as a vector and then create the Mat from it? Any suggestions?


And more: How to set the class_weights parameter? I have tried to do

cv::SVMParams parms;
parms.class_weights = someMat;

But it is not supported. What is the way to initialize a CvMat pointer, or object?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-10-23 10:00:19 -0600

berak gravatar image

it's a bit 'around the corner', but this should work:

vector<float> vf;   
CvMat someMat = Mat(vf);

cv::SVMParams parms;
parms.class_weights = &someMat;
edit flag offensive delete link more

Comments

And the vector must have 2 values (or one for each class)?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2014-10-27 03:18:11 -0600 )edit

i'd try one for each class first (no real idea, sorry, never tried.)

berak gravatar imageberak ( 2014-10-27 05:53:52 -0600 )edit

Couldn't this lead to undefined behaviour if I use a local variable CvMat?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2014-11-25 09:14:58 -0600 )edit

Question Tools

Stats

Asked: 2014-10-23 04:37:16 -0600

Seen: 1,583 times

Last updated: Oct 23 '14