ImportError:无法在 anaconda 中导入名称“TfidVectorizer”

0 scikit-learn anaconda

无法分别导入multinomialNBmake_pipelinefromsklearn.naive_bayessklearn.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)
Run Code Online (Sandbox Code Playgroud)

iva*_*707 5

您的导入中存在一些拼写错误。另外,下次出现错误时请包含错误消息。

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
Run Code Online (Sandbox Code Playgroud)

编辑:另外,请阅读有关最小示例的内容,这将使您将来尝试从 SO 获得答案时的生活变得更加轻松。

欢迎来到SO!