“从sklearn导入数据集”时出错

时间:2019-12-18 02:19:26

标签: scikit-learn

from sklearn import datasets

运行上面的代码时,出现错误:

`Traceback` (most recent call last):
  File "perceptron_ml.py", line 2, in <module>
    from sklearn import datasets
  File "/home/remember/.local/lib/python3.6/site-packages/sklearn/datasets/__init__.py", line 22, in <module>
    from ._twenty_newsgroups import fetch_20newsgroups
  File "/home/remember/.local/lib/python3.6/site-packages/sklearn/datasets/_twenty_newsgroups.py", line 45, in <module>
    from ..feature_extraction.text import CountVectorizer
  File "/home/remember/.local/lib/python3.6/site-packages/sklearn/feature_extraction/__init__.py", line 8, in <module>
    from ._hashing import FeatureHasher
ImportError: cannot import name 'FeatureHasher'

Ubuntu:18.04,Python:3.6.9,Numpy:1.17.4,scikit-learn:0.22

1 个答案:

答案 0 :(得分:0)

该错误是由于pip导致的更新期间出现故障。相关的SO帖子为https://stackoverflow.com/a/59355676/6513708

但是长话短说,您需要删除以下文件,这些文件是在更新过程中pip允许的:

  • ~/.local/lib/python3.6/site-packages/sklearn/decomposition/_online_lda.cpython-36m-x86_64-linux-gnu.so
  • ~/.local/lib/python3.6/site-packages/sklearn/feature_extraction/_hashing.cpython-36m-x86_64-linux-gnu.so
  • ~/.local/lib/python3.6/site-packages/sklearn/datasets/_svmlight_format.cpython-36m-x86_64-linux-gnu.so