Python中的朴素贝叶斯

问题描述 投票:1回答:1

我正试图在我的朴素贝叶斯代码上做拉普拉斯平滑。 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 nlp bayesian naivebayes smoothing
1个回答
0
投票

我的Python有点生疏,但对于pos,你不想要neg吗?似乎这个版本只会调整你在ifif (w not in pos) and (w not in neg)中找到的单词的分数。

© www.soinside.com 2019 - 2024. All rights reserved.