Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python nltk naive bayes probabilities

Is there a way to get at the individual probabilities using nltk.NaiveBayesClassifier.classify? I want to see the probabilities of classification to try and make a confidence scale. Obviously with a binary classifier the decision is going to be one or the other, but is there some way to see the inner workings of how the decision was made? Or, do I just have to write my own classifier?

Thanks

like image 207
English Grad Avatar asked Dec 25 '13 13:12

English Grad


1 Answers

How about nltk.NaiveBayesClassifier.prob_classify?

http://nltk.org/api/nltk.classify.html#nltk.classify.naivebayes.NaiveBayesClassifier.prob_classify

classify calls this function:

def classify(self, featureset):
    return self.prob_classify(featureset).max()

Edit: something like this should work (not tested):

dist = classifier.prob_classify(features)
for label in dist.samples():
    print("%s: %f" % (label, dist.prob(label)))
like image 70
ales_t Avatar answered Oct 10 '22 23:10

ales_t