Search code examples
pythonscikit-learnnaivebayes

Sklearn Naive Bayes print Probability Results


The output of the classifier is basically 1 and 0 depending on the transformed label, right? But how do I print out its calculation result? Rather than,

Predicted: 1

1 means High, 0 means Low

I wanted to have the output

Predicted: 86.4% Low

How to print its percentage?


Solution

  • Try using the model's method: predict_proba(X)

    This function will return you the probability of the samples for each class in the model. For example, if you have a binary classification problem, your output will be something like:

    [0.22 , 0.78]
    

    Meaning that the sample you tested is 22% possible to be class 0, and 78% to be class 1. So, you are obtaining the percentages of belonging each class.