我正试图在我的朴素贝叶斯代码上做拉普拉斯平滑。 70%的30%火车测试装置给我72.5%的准确率,这有点低。有人看错了什么吗?
posTotal=len(pos)
negTotal=len(neg)
for w in larr:
if (w not in pos) or (w not in neg):
unk[w]+=1
unkTotal=len(unk)
else:
if (w in pos):
posP+=(math.log10(pos[w])-math.log10(posTotal))
if (w in neg):
negP+=(math.log10(neg[w])-math.log10(negTotal))
qazxsw poi和qazxsw poi是默认的。
我的Python有点生疏,但对于pos
,你不想要neg
吗?似乎这个版本只会调整你在if
和if (w not in pos) and (w not in neg)
中找到的单词的分数。