Python Can';t负载';mnist原件';使用sklearn的数据集
这个问题类似于所问的和所问的。不幸的是,就我而言,建议的解决方案并没有解决问题 我需要使用MNIST数据集,但我无法获取它,即使我指定了Python Can';t负载';mnist原件';使用sklearn的数据集,python,scikit-learn,mnist,Python,Scikit Learn,Mnist,这个问题类似于所问的和所问的。不幸的是,就我而言,建议的解决方案并没有解决问题 我需要使用MNIST数据集,但我无法获取它,即使我指定了scikit\u learn\u data/mldata/文件夹的地址(见下文)。我怎样才能解决这个问题 如果有帮助的话,我用的是蟒蛇 代码: 错误: --------------------------------------------------------------------------- IOError
scikit\u learn\u data/mldata/
文件夹的地址(见下文)。我怎样才能解决这个问题
如果有帮助的话,我用的是蟒蛇
代码:
错误:
---------------------------------------------------------------------------
IOError Traceback (most recent call last)
<ipython-input-5-dc4d45bc928e> in <module>()
----> 1 mnist = fetch_mldata('MNIST original')
/Users/michelangelo/anaconda2/lib/python2.7/site-packages/sklearn/datasets/mldata.pyc in fetch_mldata(dataname, target_name, data_name, transpose_data, data_home)
168 # load dataset matlab file
169 with open(filename, 'rb') as matlab_file:
--> 170 matlab_dict = io.loadmat(matlab_file, struct_as_record=True)
171
172 # -- extract data from matlab_dict
/Users/michelangelo/anaconda2/lib/python2.7/site-packages/scipy/io/matlab/mio.pyc in loadmat(file_name, mdict, appendmat, **kwargs)
134 variable_names = kwargs.pop('variable_names', None)
135 MR = mat_reader_factory(file_name, appendmat, **kwargs)
--> 136 matfile_dict = MR.get_variables(variable_names)
137 if mdict is not None:
138 mdict.update(matfile_dict)
/Users/michelangelo/anaconda2/lib/python2.7/site-packages/scipy/io/matlab/mio5.pyc in get_variables(self, variable_names)
290 continue
291 try:
--> 292 res = self.read_var_array(hdr, process)
293 except MatReadError as err:
294 warnings.warn(
/Users/michelangelo/anaconda2/lib/python2.7/site-packages/scipy/io/matlab/mio5.pyc in read_var_array(self, header, process)
250 `process`.
251 '''
--> 252 return self._matrix_reader.array_from_header(header, process)
253
254 def get_variables(self, variable_names=None):
mio5_utils.pyx in scipy.io.matlab.mio5_utils.VarReader5.array_from_header()
mio5_utils.pyx in scipy.io.matlab.mio5_utils.VarReader5.array_from_header()
mio5_utils.pyx in scipy.io.matlab.mio5_utils.VarReader5.read_real_complex()
mio5_utils.pyx in scipy.io.matlab.mio5_utils.VarReader5.read_numeric()
mio5_utils.pyx in scipy.io.matlab.mio5_utils.VarReader5.read_element()
streams.pyx in scipy.io.matlab.streams.FileStream.read_string()
IOError: could not read bytes
---------------------------------------------------------------------------
IOError回溯(最近一次呼叫最后一次)
在()
---->1 mnist=获取数据('mnist original')
/用户/michelangelo/anaconda2/lib/python2.7/site-packages/sklearn/datasets/mldata.pyc在fetch\u mldata(数据名、目标名、数据名、转置数据、数据主)中
168#加载数据集matlab文件
169打开(文件名为“rb”)作为matlab_文件:
-->170 matlab_dict=io.loadmat(matlab_文件,struct_as_record=True)
171
172#——从matlab dict中提取数据
/loadmat中的Users/michelangelo/anaconda2/lib/python2.7/site-packages/scipy/io/matlab/mio.pyc(文件名、MDCT、appendmat、**kwargs)
134 variable_names=kwargs.pop('variable_names',无)
135 MR=材料读取器工厂(文件名,附录,**kwargs)
-->136 matfile\u dict=MR.get\u变量(变量名称)
137如果MDCT不是无:
138 MDCT.更新(matfile\U dict)
/get_变量(自身、变量名称)中的Users/michelangelo/anaconda2/lib/python2.7/site-packages/scipy/io/matlab/mio5.pyc
290继续
291试试:
-->292 res=self.read\u var\u数组(hdr,进程)
293除MatReadError作为错误外:
294.warn(
/read_var_数组中的Users/michelangelo/anaconda2/lib/python2.7/site-packages/scipy/io/matlab/mio5.pyc(self、header、process)
250“过程”。
251 '''
-->252返回自。\u矩阵\u读取器。数组\u来自\u头(头,进程)
253
254 def get_变量(自身,变量名称=无):
scipy.io.matlab.mio5_utils.VarReader5.array_from_header()中的mio5_utils.pyx
scipy.io.matlab.mio5_utils.VarReader5.array_from_header()中的mio5_utils.pyx
scipy.io.matlab.mio5_utils.VarReader5.read_real_complex()中的mio5_utils.pyx
scipy.io.matlab.mio5_utils.VarReader5.read_numeric()中的mio5_utils.pyx
scipy.io.matlab.mio5_utils.VarReader5.read_element()中的mio5_utils.pyx
scipy.io.matlab.streams.FileStream.read_string()中的streams.pyx
IOError:无法读取字节
而不是:
from sklearn.datasets.mldata import fetch_mldata
使用:
然后:
mnist = fetch_mldata('MNIST original')
X = mnist.data.astype('float64')
y = mnist.target
请参见此示例:
mnist original.mat
文件。当前文件大小:55.4 MB。我刚刚遇到了相同的问题,我花了一些时间才找到问题。原因之一是,数据可能在运行过程中被破坏第一次下载。删除缓存数据。按如下方式查找scikit数据主目录:
from sklearn.datasets.base import get_data_home
print (get_data_home())
清理目录并重新下载数据集。这个解决方案适合我。
供参考:
这也与以下问题有关:
此处是问题的快速更新: mldata.org似乎仍处于关闭状态。然后scikit learn将删除fetch_mldata 目前的解决方案: 由于使用上面的行将在数据的位置创建一个空文件夹a,请在此处找到数据的副本:并下载它。然后将其放置在~/sklearn\u data/mldata/中,该文件夹为空
它对我有用。试试这个,这个会有用的
from sklearn.datasets import fetch_mldata
mnist = fetch_mldata('MNIST original')
在最新的sklearn版本(0.21)中,使用以下命令:
不幸的是,在最新版本的sklearn中将fetch_mldata()替换为fetch_openml()
因此,与其使用:
from sklearn.datasets import fetch_mldata
mnist = fetch_mldata('MNIST original')
您必须使用:
from sklearn.datasets import fetch_openml
mnist = fetch_openml('mnist_784')
x = mnist.data
y = mnist.target
x的形状将为=(70000784)y的形状为=(70000,)只需使用以下两行:
from sklearn.datasets import fetch_openml
mnist = fetch_openml('mnist_784', version=1, cache=True)
如果键入:从sklearn.datasets导入fetch_mldata,mnist=fetch_mldata('mnist original')是否有效?否,我获取语法错误:无效语法分别复制粘贴每个命令。1)从sklearn.datasets导入fetch_mldata 2)mnist=fetch_mldata('mnist original'))不幸的是,这不是问题所在。你的sklearn版本是什么?使用:导入sklearn和sklearn.\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu!我仍然收到
IOError:无法读取字节@albus\c可能下载已损坏。请在scikit\u learn\u data/mldata
中检查下载文件的大小。它至少应该是52MB。如果没有,请删除并重试。@albus_c精确到52.9 MB。如果仍不成功,请从浏览器中下载该文件并替换该文件夹中的文件。很可能就是问题所在。现在我将尝试直接链接。FETCHYMLDATA现在被贬低:(是的,在系统中,它显示为55.4 MB,但是在下载时显示为52.9 MB。如果有帮助,请考虑投票并接受答案。嗨,PuneET!您能解释一下为什么这是正确答案吗?这现在抛出<代码> URLOPENT错误[ErNONO - 3 ]。名称解析暂时失败
from sklearn.datasets import fetch_mldata
mnist = fetch_mldata('MNIST original')
from sklearn.datasets import fetch_openml
mnist = fetch_openml('mnist_784')
x = mnist.data
y = mnist.target
from sklearn.datasets import fetch_openml
mnist = fetch_openml('mnist_784', version=1, cache=True)