[英]Running sklearn PCA on MNIST data gives memory allocation error
[英]MNIST data download from sklearn datasets gives Timeout error
我是 ML 的新手,正在嘗試下載 MNIST 數據。 我正在使用的代碼是:
from sklearn.datasets import fetch_mldata
mnist = fetch_mldata('MNIST original')
但是,它給出了一個錯誤說:
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
任何人都可以幫我解決這個問題需要做些什么嗎?
這是問題和一些好人建議的解決方法:
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)
load_digits
:from sklearn.datasets import load_digits
mnist = load_digits()
請注意,如果您正在閱讀使用 Scikit-Learn 和 TensorFlow 的 Hands-On Machine Learning一書,使用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()
返回 9 而不是 5 的圖片。我猜,可能是 mnist-784 和 mnist 原始是 nist 數據的兩個子集,或者兩個數據集之間的數據順序不同。
PS:我在嘗試加載數據時遇到了一些關於 ssl 的錯誤,在我的情況下,我更新了 openssl 並且問題已經解決。
雖然我不確定您收到錯誤的原因,但您可以嘗試以下可能的方法來糾正錯誤。
有時,數據可能會在第一次下載時損壞。 在這種情況下,您需要清除可以從 scikit 數據主目錄中刪除的緩存。 要獲取此目錄,您可以使用 -
from sklearn.datasets.base import get_data_home print (get_data_home())
現在清理目錄,然后重新下載。
https://github.com/ageron/handson-ml/issues/143
https://github.com/scikit-learn/scikit-learn/issues/8588
https://github.com/ageron/handson-ml/issues/8
如果您仍然遇到問題,我想請求您提供詳細的回溯以幫助我確定問題。
謝謝!!
如果您的 sklearn 版本低於 .19,則“fetch_mldata”將不起作用。 您需要將 sklearn 升級到 .23 版本
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.