DEV Community

Cover image for The Naive Bayes Classifier
Carlos Almonte
Carlos Almonte

Posted on

The Naive Bayes Classifier

This machine learning algorithm is used to make predictions whether something belongs to a class or not. For example, if a girl has jimmy choo shoes in her closet, is she rich or not? – I'm really dating myself talking about jimmy choo here, there's probably a cooler brand nowadays. In order to make the prediction the Bayes classifier uses a formula called the Bayes Theorem:

P(A|B) = (P(B|A) * P(A)) / P(B)
Enter fullscreen mode Exit fullscreen mode

P=probability
A=event A (has jimmy choo shoes)
B=event B (is rich, yes or no)

One important fact about the Bayes theorem is that the two events must be dependent of each other, meaning that the girl having jimmy choo shoes means she is really rich or not.

from sklearn.naive_bayes import MultinomialNB
classifier = MultinomialNB()
classifier.fit(has_jimmy_choo_data, is_rich)

classifier.predict_proba(has_jimmy_choo)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)