我正在尝试使用 BernoulliNB。使用相同的数据进行训练和测试,我得到了训练数据以外的预测和 1 以外的概率。请问这是为什么?
import pandas as pd
from sklearn.naive_bayes import BernoulliNB
BNB = BernoulliNB()
# Data
df_1 = pd.DataFrame({'O' : [1,2,3,1,1,3,1,2,2,1],
'I1': [1,0,0,1,0,0,1,1,0,1],
'I2': [0,0,1,0,0,1,0,0,1,0],
'I3': [1,0,0,0,0,0,1,0,0,0]})
df_I = df_1.iloc[:,1:4]
S_O = df_1['O']
# Bernoulli Naive Bayes Classifier
A_F = BNB.fit(df_I, S_O)
A_P = BNB.predict(df_I)
A_R = BNB.predict_proba(df_I)
df_P = pd.DataFrame(A_P)
df_R = pd.DataFrame(A_R)
df_P.columns = ['Predicted A']
df_R.columns = ['Prob 1', 'Prob 2', 'Prob 3']
df_1 = df_1.join(df_P)
df_1 = df_1.join(df_R)
结果
O I1 I2 I3 Predicted A Prob 1 Prob 2 Prob 3
1 1 0 1 1 .80 .15 .05
2 0 0 0 2 .59 .33 .08
3 0 1 0 3 .18 .39 .43
1 1 0 0 1 .59 .33 .08
1 0 0 0 2 .59 .33 .08
3 0 1 0 3 .18 .39 .43
1 1 0 1 1 .80 .15 .48
2 1 0 0 1 .59 .33 .08
2 0 1 0 3 .18 .39 .43
1 1 0 0 1 .59 .33 .08
我试图在这里描述我正在尝试做的事情:
https://stats.stackexchange.com/questions/367829/how-probable-is-a-set