“从 sklearn 导入数据集”时出错
Posted
技术标签:
【中文标题】“从 sklearn 导入数据集”时出错【英文标题】:error while "from sklearn import datasets" 【发布时间】:2020-04-10 13:37:17 【问题描述】: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
【问题讨论】:
请提供完整代码示例等详细信息。 你好,我输入python3
进入python shell,在python shell中输入from sklearn import datasets
。然后我得到错误。没有更多的代码。
【参考方案1】:
该错误是由于pip
导致的更新期间发生的故障。相关的 SO 帖子是 https://***.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
【讨论】:
谢谢。这确实向我展示了解决问题的方法。我删除了您显示的两个文件,并得到另一个错误:ImportError: cannot import name 'load_svmlight_file'
。然后我删除文件~/.local/lib/python3.6/site-packages/sklearn/datasets/_svmlight_format.cpython-36m-x86_64-linux-gnu.so
并成功。再次感谢您!
谢谢,我将编辑我的帖子以添加此文件。以上是关于“从 sklearn 导入数据集”时出错的主要内容,如果未能解决你的问题,请参考以下文章