Can't import multinomialNB
and make_pipeline
from sklearn.naive_bayes
and sklearn.pipeline
respectively, screenshot is attached.I'm using python3. I uninstalled and installed anaconda from "https://conda.io/docs/user-guide/install/index.html" last time.
I installed and uninstalled from separate sources too.
I tried installing packages separately also. sklearn,scipy or other packages are installed and upgraded but this piece of code is giving the same error again and again.
I tried every possible solutions on internet and 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)
答案 0 :(得分:0)
You have some spelling mistakes in your imports. Also, include the error messages the next time you have an error.
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
EDIT: Also, please read this about a minimum example, it will make your life a lot easier when trying to get answers from SO in the future.
Welcome to SO!