Mal*_*dog 11 python artificial-intelligence machine-learning scikit-learn
使用scikit-learn 0.10
为什么以下简单的代码片段:
from sklearn.naive_bayes import *
import sklearn
from sklearn.naive_bayes import *
print sklearn.__version__
X = np.array([ [1, 1, 1, 1, 1],
[0, 0, 0, 0, 0] ])
print "X: ", X
Y = np.array([ 1, 2 ])
print "Y: ", Y
clf = BernoulliNB()
clf.fit(X, Y)
print "Prediction:", clf.predict( [0, 0, 0, 0, 0] )
Run Code Online (Sandbox Code Playgroud)
打印出"1"的答案?在[0,0,0,0,0] => 2训练模型后,我期待"2"作为答案.
为什么用Y替换Y.
Y = np.array([ 3, 2 ])
Run Code Online (Sandbox Code Playgroud)
给一个不同的类"2"作为答案(正确的)?这不仅仅是一个类标签吗?
有人可以对此有所了解吗?
您的训练集太小,可以显示
clf.predict_proba(X)
Run Code Online (Sandbox Code Playgroud)
产量
array([[ 0.5, 0.5],
[ 0.5, 0.5]])
Run Code Online (Sandbox Code Playgroud)
这表明分类器将所有分类视为等概率.与BernoulliNB文档中显示的样本进行比较,其predict_proba()收益率为:
array([[ 2.71828146, 1.00000008, 1.00000004, 1.00000002, 1. ],
[ 1.00000006, 2.7182802 , 1.00000004, 1.00000042, 1.00000007],
[ 1.00000003, 1.00000005, 2.71828149, 1. , 1.00000003],
[ 1.00000371, 1.00000794, 1.00000008, 2.71824811, 1.00000068],
[ 1.00000007, 1.0000028 , 1.00000149, 2.71822455, 1.00001671],
[ 1. , 1.00000007, 1.00000003, 1.00000027, 2.71828083]])
Run Code Online (Sandbox Code Playgroud)
我在哪里应用于numpy.exp()结果,使它们更具可读性.显然,概率甚至不接近相等,实际上很好地对训练集进行了分类.