Search code examples
svmscikit-learn

How can i know probability of class predicted by predict() function in Support Vector Machine?


How can i know sample's probability that it belongs to a class predicted by predict() function of Scikit-Learn in Support Vector Machine?

>>>print clf.predict([fv])
[5]

There is any function?


Solution

  • Use clf.predict_proba([fv]) to obtain a list with predicted probabilities per class. However, this function is not available for all classifiers.

    Regarding your comment, consider the following:

    >> prob = [ 0.01357713, 0.00662571, 0.00782155, 0.3841413, 0.07487401, 0.09861277, 0.00644468, 0.40790285]
    >> sum(prob)
    1.0
    

    The probabilities sum to 1.0, so multiply by 100 to get percentage.