Ask Your Question
4

Get a probability out of svm->predict

asked 2012-08-13 00:59:42 -0500

tmanthey gravatar image

I have trained an SVM with 6 classes.

I want to determine if my picture belongs to one of the classes and if yes to which class.

Currently I use this code

CvSVM *pSvm = new CvSVM();
pSvm->load("filename.xml", 0);
float pred = pSvm->predict(detectionImage);

The problem with this code is that no matter what picture I send to the svm it always return one out of my 6 classes. So to filter the pictures which belong to none of the classes I would need the probability that this picture belongs to my class.

e.g.
Currently I only get the information that my picture belongs to class N (pred)

What I would like to get is: Picture belongs to class N with a probability of P

Then I could put a threshold on the probability to filter out my negatives.

If this is not working what is suggested way to filter out the negatives?

Thanks

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
4

answered 2012-08-13 01:49:17 -0500

sammy gravatar image

updated 2012-08-13 01:49:34 -0500

SVM, at least in the OpenCV implementation, does not output any measure that can be used as extra threshold.

However, internall, it calculates a distance to the separation plane, by which it determines the class where the input vector belongs to. That distance may be interesting for you.

If you are not ready to fork OpenCV in order to output it, you may want to control it the other way: set it as input for the train() method. So it will automatically discard those vectors that are too close to the separation plane (i.e. The probability is low).

The parameter in question is CvSVM::EPS_SVR and you can set it through the CvSVMParams class

edit flag offensive delete link more

Comments

I tried setting the params to CvSVM::EPS_SVR. My program has a self test loop where it asserts that the training samples are classified correctly. Using EPS_SVR the self test fails. What would be a good setting for the p parameter? I tried these values CvSVMParams svm_param = CvSVMParams(CvSVM::EPS_SVR,CvSVM::LINEAR, 10,8,1,10,0.5,0.1,NULL,cvTermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 100000, 0.00000000001) );

tmanthey gravatar imagetmanthey ( 2012-08-13 02:36:34 -0500 )edit

No idea about params - just try them, and understand their effects on the result. It's higly likely that the best params depend on your data - this is why you can set them, after all :)

sammy gravatar imagesammy ( 2012-08-13 03:47:22 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2012-08-13 00:59:42 -0500

Seen: 3,723 times

Last updated: Aug 13 '12