Ask Your Question
0

How to get a probability for a SVM prediction?

asked 2014-09-30 09:54:25 -0600

thdrksdfthmn gravatar image

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 flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
5

answered 2014-09-30 12:54:06 -0600

ejehardenberg gravatar image

updated 2014-10-01 09:29:26 -0600

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

edit flag offensive delete link more

Comments

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?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2014-10-01 02:13:24 -0600 )edit
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.

Guanta gravatar imageGuanta ( 2014-10-01 02:40:22 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-09-30 09:54:25 -0600

Seen: 10,268 times

Last updated: Oct 01 '14