Naive Bayes is based on Bayes' theorem and is based on prior probabilities and their likelihoods (Explanation of Likelihoods). The posterior probability is calculated and classified into the category with the highest posterior probability. It is famous for being used to judge spam emails.
Extracted from 'Introduction to Machine Learning', Udacity
The above is a naive Bayesian prediction of whether Sara or Chris sent it from the text of the'LIFE DEAL'email. The probability of sending each email of Chris and Sara is 50% (prior probability) Chris uses words at a rate of LOVE 10%, DEAL 80%, LIFE 10%, while Sara uses words at a rate of LOVE 30%, DEAL 20%, and LIFE 30%. (Likelihood)
So the posterior probability is Prior probability x Likelihood = Posterior probability Chris 10% × 80% × 50% = 0.04 Sara 30% × 20% × 50% = 0.03
If you fix this, 0.04 + 0.03 = 0.07 (this is 100%) Chris 0.04 / 0.07 = 0.57 → 57% Sara 0.03 / 0.07 = 0.43 → 43%
In other words, there is a 57% chance that it is Chris, so the result is that this email that says LIFE DEAL It is classified as Chris.
python
from sklearn.naive_bayes import GaussianNB
GaussianNB(priors=None)
#That's the default code, it's simple.
Since each feature is considered independently and expressed on one dimension, the curse of dimentionality can be alleviated.
--Bad point
For example, as you can see from the first Chris and Sara email decisions, Naive Bayes only looks at the frequency of words, so it can't determine the order or combination of sentences. For example, in English, just adding not just before a verb can change the meaning by 180 degrees. That is, the features are regarded as one independent feature, and the correlation between the features is not considered.
The above is the outline of Naive Bayes as far as I can understand. We will update it daily, so if you have something to add or fix, we would appreciate it if you could comment.
Recommended Posts