我们正在实现的代码是

from NaiveBayes import  Pool
import os

DClasses = ["python",  "java",  "hadoop",  "django",  "datascience",  "php"]

base = "learn/"
p = Pool()
for i in DClasses:
    p.learn(base + i, i)



base = "test/"
for i in DClasses:
    dir = os.listdir(base + i)
    for file in dir:
        res = p.Probability(base + i + "/" + file)
        print(i + ": " + file + ": " + str(res))


但是我们遇到了错误,就像找不到像naivebayes一样的模块。

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-21-30788f518a4c> in <module>()
----> 1 from NaiveBayes import  Pool
      2 import os
      3
      4 DClasses = ["python",  "java",  "hadoop",  "django",  "datascience",  "php"]
      5

ModuleNotFoundError: No module named 'NaiveBayes'


帮助消除此错误。谢谢。

最佳答案

该代码似乎不是来自scikit-learn Naive Bayes algorithms,在任何情况下都没有Pool属性或方法。

似乎您正在尝试使用another NaiveBayes library,在这种情况下,您应该导入

from NaiveBayes.Pool import Pool


example所示。但是该消息表明您尚未安装它。从外壳尝试

git clone https://github.com/yveskaufmann/Naive-Bayes


在当前目录中(另请参见documentation克隆Github存储库)。

08-03 14:37