Bayes’ Theorem

Naïve Bayes

Continuous Probability Distribution: consider probability=density*size_of_neighborhood(delta d), and delta will be cancel out in quotient, so just plug in density will be ok

Applications

Code

sklearn

training = np.array([[0, 0, 0, 1], [0, 0, 0, 0], [2, 0, 0, 1], [1, 1, 0, 1], [1, 2, 1, 1],
[1, 2, 1, 0], [2, 2, 1, 0], [0, 1, 0, 1], [0, 2, 1, 1], [1, 1, 1, 1],
[0, 1, 1, 0], [2, 1, 0, 0], [2, 0, 1, 1], [1, 1, 0, 0]])
outcome = np.array([1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1])
new_sample = np.array([[0, 2, 0, 0]])
clf = sklearn.naive_bayes.CategoricalNB(alpha=1.0e-10).fit(training, outcome)
pred_class = clf.predict(new_sample); prob = clf.predict_proba(new_sample)
print(pred_class, prob)