No module named NaiveBayes

痴心易碎 提交于 2019-12-11 14:17:31

问题


The code we are implementing is

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))

but we are getting error like no module found like 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'

Help to eradicate this error.Thanks.


回答1:


The code does not seem to be from the scikit-learn Naive Bayes algorithms, which, in any case, do not have a Pool attribute or method.

It seems you are trying to use another NaiveBayes library, in which case your import should be

from NaiveBayes.Pool import Pool

as shown in the example there. But the message implies that you have not installed it; try from the shell

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

in your current directory (see also the documentation for cloning Github repos).



来源:https://stackoverflow.com/questions/52078969/no-module-named-naivebayes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!