【问题标题】:ImportError: cannot import name 'TfidVectorizer' in anacondaImportError:无法在 anaconda 中导入名称“TfidVectorizer”
【发布时间】:2018-09-19 11:15:52
【问题描述】:

无法分别从sklearn.naive_bayessklearn.pipeline 导入multinomialNBmake_pipeline,附上截图。我使用的是python3。我上次从“https://conda.io/docs/user-guide/install/index.html”卸载并安装了anaconda。

我也从不同的来源安装和卸载。

我也尝试单独安装软件包。 sklearn、scipy 或其他软件包已安装和升级,但这段代码一次又一次地给出相同的错误。

我在互联网和 stackoverflow 上尝试了所有可能的解决方案。

#importing necessary packages
from sklearn.feature_extraction.text import TfidVectorizer
from sklearn.naive_bayes import multinomialNB
from sklearn.pipeline import make_pipeline

#creating a model based on multinomial naive-bayes
model = make_pipeline(TfidVectorizer(), multinomialNB())

#training the model with train data
model.fit(train.data, train.target)

#creating labels for test data
labels = model.predict(test.data)

【问题讨论】:

    标签: scikit-learn anaconda


    【解决方案1】:

    您的导入中有一些拼写错误。此外,请在下次遇到错误时包含错误消息。

    from sklearn.feature_extraction.text import TfidfVectorizer # notice the spelling with the f before Vectorizer
    from sklearn.naive_bayes import MultinomialNB # notice the Caps on the M
    from sklearn.pipeline import make_pipeline
    

    编辑:另外,请read this about a minimum example,将来尝试从 SO 获得答案时,这将使您的生活更轻松。

    欢迎来到 SO!

    【讨论】:

    • 非常感谢伊万 :)
    猜你喜欢
    • 2017-05-25
    • 1970-01-01
    • 2016-07-11
    • 2016-03-31
    • 2014-10-10
    • 2014-09-20
    • 2014-08-28
    • 2014-06-10
    • 2016-05-16
    相关资源
    最近更新 更多