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
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.
For the later versions, you can find vectorizers and transformers like TfidVectorizer in sklearn.feature_extraction.text
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
ImportError: cannot import name ‘TfidVectorizer’ from ‘sklearn.feature_extraction.text. what should i do now?
---------------------------------------------------------------------------
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
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.
For the later versions, you can find vectorizers and transformers like TfidVectorizer in sklearn.feature_extraction.text
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
ImportError: cannot import name ‘TfidVectorizer’ from ‘sklearn.feature_extraction.text. what should i do now?