sklearn Import error: cannot import name tfidfvectorizer

Question:

---------------------------------------------------------------------------
    ImportError                               Traceback (most recent call last)
    /usr/lib/python2.7/dist-packages/IPython/utils/py3compat.pyc in execfile(fname, *where)
    173             else:
    174                 filename = fname
--> 175             __builtin__.execfile(filename, *where)

     /home/sayghosh/doc.py in <module>()
     9 
     10 from sklearn.datasets import load_mlcomp
---> 11 from sklearn.feature_extraction.text import TfidfVectorizer
     12 from sklearn.linear_model import SGDClassifier
     13 from sklearn.metrics import confusion_matrix

     ImportError: cannot import name TfidfVectorizer

I am getting this error when I am trying to run this code

Asked By: novieq

||

Answers:

Wrapping up the discussion in the comments to have Stack Overflow remove this question from the list of unanswered questions:

The solution is to install a more recent version of scikit-learn (0.13 or later). Apparently the original poster was using an old version of Debian or Ubuntu that shipped scikit-learn 0.10 as specified in the sklearn.__version__ package attribute.

Answered By: ogrisel

For the later versions, you can find vectorizers and transformers like TfidVectorizer in sklearn.feature_extraction.text

Answered By: Chirag Sehra

First uninstall your current version of scikit-learn with the following syntax

$ pip uninstall scikit-learn

use the below syntax to install a new version of scikit-learn

$ pip install scikit-learn==0.13
Answered By: Tproffella

ImportError: cannot import name ‘TfidVectorizer’ from ‘sklearn.feature_extraction.text. what should i do now?

Answered By: Aryan raina
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.