# Get a probability out of svm->predict

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();
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 close merge delete

Sort by » oldest newest most voted

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

more

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) );

( 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 :)

( 2012-08-13 03:47:22 -0500 )edit

Official site

GitHub

Wiki

Documentation