首页 > 解决方案 > 为什么我会收到以下 mnist = fetch_mldata 的连接重置错误?

问题描述

每当我尝试从 mnist 获取数据时,我都会收到一个连接重置错误,不确定它为什么会发生。这是来自 sklearn 的用于执行 PCA 和 t-sne 数据降维的教程。我认为这可能是 python 版本的问题,但在 2.6、3.5 或 3.7 中不起作用

from sklearn.datasets import fetch_mldata

mnist = fetch_mldata("MNIST original")
X = mnist.data / 255.0
y = mnist.target

ConnectionResetError                      Traceback (most recent call last)
<ipython-input-11-781ac9f03cc8> in <module>()
----> 1 mnist = fetch_mldata("MNIST original")
      2 X = mnist.data / 255.0
      3 y = mnist.target

/anaconda3/envs/py35/lib/python3.5/site-packages/sklearn/datasets/mldata.py in fetch_mldata(dataname, target_name, data_name, transpose_data, data_home)
    152         urlname = MLDATA_BASE_URL % quote(dataname)
    153         try:
--> 154             mldata_url = urlopen(urlname)
    155         except HTTPError as e:
    156             if e.code == 404:

ConnectionResetError: [Errno 54] Connection reset by peer

标签: pythonscikit-learnmnist

解决方案


fetch_mldata自 scikit-learn v0.20 起已弃用,并替换为fetch_openml; 以下是在 v0.21 中您应该如何将其用于 MNIST:

from sklearn.datasets import fetch_openml
X, y = fetch_openml('mnist_784', version=1, return_X_y=True)

有关示例,请参阅文档。


推荐阅读