我正试图在我的朴素贝叶斯代码上进行拉普拉斯平滑。 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))
pos
和neg
是默认值。
答案 0 :(得分:0)
我的Python有点生疏,但对于if
,你不想要if (w not in pos) and (w not in neg)
吗?似乎此版本只会调整您在pos
和neg
中以某种方式找到的字词的分数。