【问题标题】:Naive Bayes in PythonPython中的朴素贝叶斯
【发布时间】:2013-11-24 21:40:21
【问题描述】:

我正在尝试对我的朴素贝叶斯代码进行拉普拉斯平滑。它在 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))

posneg 是默认字典。

【问题讨论】:

  • 这可能有助于修复所有缩进,它的可读性不是很高

标签: python nlp bayesian naivebayes smoothing


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2018-12-15
    • 2012-02-21
    • 2011-12-28
    • 2017-03-17
    • 2014-01-13
    • 2011-10-07
    • 2019-03-16
    • 1970-01-01
    • 2018-02-24
    相关资源
    最近更新 更多