朴素贝叶斯分类器 (Naive Bayes Classifier) UP主: 正月点灯笼
http://www.bilibili.com/video/av7719936?share_medium=android&share_source=more&bbid=NgI6DWhYaQ87XzoLdwt3infoc&ts=1538034756640
(其中将朴素(独立)概念误理解为马尔科夫)
考挂了 | 喝酒 | 逛街 | 学习 |
---|---|---|---|
1 | 1 | 1 | 0 |
0 | 0 | 0 | 1 |
0 | 1 | 0 | 1 |
1 | 1 | 0 | 0 |
1 | 0 | 1 | 0 |
0 | 0 | 1 | 1 |
0 | 0 | 1 | 0 |
1 | 0 | 0 | 1 |
求? 0 0 1
条件概率
Bayes
先验概率:是指根据以往经验和分析得到的概率(Bayes公式中的P(A)).
后验概率:事情已经发生,要求这件事情发生的原因是由某个因素引起的可能性的大小(Bayes公式中的P(A|B))
假设各特征之间相互独立 Naive Bayes
挂科P(A) = 1/2
酒 P(B'|A) = 2/4
逛街P(C'|A) = 2/4
学习P(D |A) = 1/4
酒 P(B'|A') = 3/4
逛街P(C'|A') = 2/4
学习P(D |A') = 3/4
P(A|B'C'D):P(A'|B'C'D) = 4/128:18/128
P(A|B'C'D) = 18/22
import numpy as np
X = np.array([[1, 1, 0], [0, 0, 1], [1, 0, 1], [1, 0, 0], [0, 1, 0], [0, 1, 1], [0, 1, 0], [0, 0, 1]])
Y = np.array([1, 0, 0, 1, 1, 0, 0, 1])
from sklearn.naive_bayes import GaussianNB
clf = GaussianNB()#参数
clf.fit(X, Y)
print("==Predict result by predict==")
print(clf.predict([[0, 0, 1]]))
print("==Predict result by predict_proba==")
print(clf.predict_proba([[0, 0, 1]]))
print("==Predict result by predict_log_proba==")
print(clf.predict_log_proba([[0, 0, 1]]))
from sklearn.naive_bayes import MultinomialNB
clf = MultinomialNB()#参数
clf.fit(X, Y)
print("==Predict result by predict==")
print(clf.predict([[0, 0, 1]]))
print("==Predict result by predict_proba==")
print(clf.predict_proba([[0, 0, 1]]))
print("==Predict result by predict_log_proba==")
print(clf.predict_log_proba([[0, 0, 1]]))
from sklearn.naive_bayes import BernoulliNB
clf = BernoulliNB()#参数
clf.fit(X, Y)
print("==Predict result by predict==")
print(clf.predict([[0, 0, 1]]))
print("==Predict result by predict_proba==")
print(clf.predict_proba([[0, 0, 1]]))
print("==Predict result by predict_log_proba==")
print(clf.predict_log_proba([[0, 0, 1]]))
网友评论