Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
A probability-first classifier. It combines prior belief with evidence likelihoods and predicts the class with highest posterior.
Adjust priors and evidence in real time.
Read it as: .
The “naive” assumption treats features as conditionally independent.
import math
# toy Naive Bayes for binary class
def predict(prior_spam, likelihoods_spam, likelihoods_ham):
num = prior_spam
den_other = 1 - prior_spam
for ps, ph in zip(likelihoods_spam, likelihoods_ham):
num *= ps
den_other *= ph
return num / (num + den_other)
p = predict(0.3, [0.78, 0.14], [0.18, 0.72])
print('P(spam|x)=', round(p, 3))