Swa*_*har 2 python scikit-learn mnist
我是ML的新手,正在尝试下载MNIST数据。我使用的代码是:
from sklearn.datasets import fetch_mldata
mnist = fetch_mldata('MNIST original')
Run Code Online (Sandbox Code Playgroud)
但是,它给出了一个错误:
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Run Code Online (Sandbox Code Playgroud)
谁能帮我解决这个问题?
这是问题和一些好人建议的解决方法:
https://github.com/scikit-learn/scikit-learn/issues/8588
最简单的方法是使用以下下载链接下载 MNIST 的 .mat 文件:
下载后将文件放入 ~/scikit_learn_data/mldata 文件夹中,如果此文件夹不存在,则创建它并将 Mnist.mat 放入其中。当您在本地拥有它们时,scikit learn 不会下载它并使用该文件。
由于不建议使用fetch_mldata,因此我们将不得不移至fetch_openml。确保将您的scikit-learn更新到0.20.0或更高版本以进行openml工作。
from sklearn.datasets import fetch_openml
# Load data from https://www.openml.org/d/554
X, y = fetch_openml('mnist_784', version=1, return_X_y=True)
Run Code Online (Sandbox Code Playgroud)
load_digits:from sklearn.datasets import load_digits
mnist = load_digits()
Run Code Online (Sandbox Code Playgroud)
请注意,如果您遵循《使用Scikit-Learn和TensorFlow进行机器学习动手》(带有mnist-784数据集)一书,则可能会注意到该代码
some_digit = X[36000]
some_digit_image = some_digit.reshape(28, 28)
plt.imshow(some_digit_image, cmap=matplotlib.cm.binary, interpolation="nearest")
plt.axis('off')
plt.show()
Run Code Online (Sandbox Code Playgroud)
返回的图片是9而不是5。我猜可能是mnist-784和mnist原始图像是nist数据的两个子集,或者两个数据集之间的数据顺序不同。
PS:尝试加载数据时遇到了关于ssl的错误,就我而言,我更新openssl并已解决问题。
| 归档时间: |
|
| 查看次数: |
4216 次 |
| 最近记录: |