简体   繁体   中英

sklearn Import error: cannot import name tfidfvectorizer

---------------------------------------------------------------------------
    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.

对于更高版本,您可以在sklearn.feature_extraction.text找到向量化器和转换器,例如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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM