# How to get a probability for a SVM prediction?

I am doing a prediction using a SVM classifier. I have read that the output of predict may be the distance/decision function value. How shall I interpret it? What means the sign? In which class is the image classified as? Is there a possibility to compute a probability from that value?

edit retag close merge delete

Sort by » oldest newest most voted The output of predict will be the label which you have set the class with. For example, if you have set up a binary SVM then you will have likely also set up 2 labels (say -1 and 1). If the SVM decides that the Mat in question is of class -1 then it will return -1.

The sign is dependent entirely on the labels you set, if you don't use a sign then there will be none.

All that said, If you look at the [documentation] then you'll find that there is a second parameter to the predict function:

returnDFVal – Specifies a type of the return value. If true and the problem is 2-class classification then the method returns the decision function value that is signed distance to the margin, else the function returns a class label (classification) or estimated function value (regression).

In simple terms, if you pass true for the second parameter you don't get back your class label, but the distance from the margin, and here the sign matters as it will be the direction away from the hyperplane. But only if you are doing a binary classification!

I'm not sure about your last question about the probability for non-binary problems, but in the case of a binary problem then the distance is your probability (Or can be converted, see the comments below), the farther from the margin the more likely the object belongs to the class on that side of the cutting plane. The negative/positive will tell you which class it is.

The documentation for predict is here: http://docs.opencv.org/modules/ml/doc/support_vector_machines.html#cvsvm-predict

more

I suppose that negative values are for negative class (that I have labelled 0) and the positive values are for positive class (that I have labelled 1). If I have a distance, then I can compute a probability (even if it may be more than 100%), but I need the centre (or the distance of the centre of each class). Is there any way to obtain this?

2

Just a comment to ejehardenberg's post: The distances are actually not really probabilities, however, you can convert them to it. The most known method is Platt's calibration. Afaik LibSVM also ships that calibration method. Note that you need another cross-validation or held-out set to "learn" the calibration parameters.

Official site

GitHub

Wiki

Documentation