问题描述 在下载 MNIST 数据集的时候报错,报错信息如下: /usr/local/lib/python3.7/dist-packages/sklearn/utils/deprecation.py:77: DeprecationWarning: Function fetch_mldata is deprecated; ..

Error Downloading MNIST 解决方案

问题描述

在下载 MNIST 数据集的时候报错,报错信息如下:

/usr/local/lib/python3.7/dist-packages/sklearn/utils/deprecation.py:77: DeprecationWarning: Function fetch_mldata is deprecated; fetch_mldata was deprecated in version 0.20 and will be removed in version 0.22
  warnings.warn(msg, category=DeprecationWarning)
/usr/local/lib/python3.7/dist-packages/sklearn/utils/deprecation.py:77: DeprecationWarning: Function mldata_filename is deprecated; mldata_filename was deprecated in version 0.20 and will be removed in version 0.22
  warnings.warn(msg, category=DeprecationWarning)
Traceback (most recent call last):
  File "classification_sklearn.py", line 2, in <module>
    mnist = fetch_mldata('MNIST original')
  File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/deprecation.py", line 78, in wrapped
    return fun(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/sklearn/datasets/mldata.py", line 133, in fetch_mldata
    mldata_url = urlopen(urlname)
  File "/usr/lib/python3.7/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.7/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/usr/lib/python3.7/urllib/request.py", line 543, in _open
    '_open', req)
  File "/usr/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.7/urllib/request.py", line 1345, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/usr/lib/python3.7/urllib/request.py", line 1320, in do_open
    r = h.getresponse()
  File "/usr/lib/python3.7/http/client.py", line 1321, in getresponse
    response.begin()
  File "/usr/lib/python3.7/http/client.py", line 296, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.7/http/client.py", line 257, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/lib/python3.7/socket.py", line 589, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer

下载数据集的代码如下:

from sklearn.datasets import fetch_mldata
mnist = fetch_mldata('MNIST original')
mnist

解决方案

下载mnist-original.mat并且保存到~/scikit_learn_data/mldata/(scikit data home dir)下面即可

查找 scikit data home dir 的代码:

from sklearn.datasets.base import get_data_home 
print (get_data_home())

  • 机器学习

    机器学习(Machine Learning)是一门多领域交叉学科,涉及概率论、统计学、逼近论、凸分析、算法复杂度理论等多门学科。专门研究计算机怎样模拟或实现人类的学习行为,以获取新的知识或技能,重新组织已有的知识结构使之不断改善自身的性能。

    51 引用 • 19 回帖
  • Python

    Python 是一种面向对象、直译式电脑编程语言,具有近二十年的发展历史,成熟且稳定。它包含了一组完善而且容易理解的标准库,能够轻松完成很多常见的任务。它的语法简捷和清晰,尽量使用无异义的英语单词,与其它大多数程序设计语言使用大括号不一样,它使用缩进来定义语句块。

    336 引用 • 484 回帖 • 664 关注
回帖   
请输入回帖内容...