获取 MNIST 数据时出现 KeyError
KeyError while fetching MNIST data
我正在尝试使用 MNIST 数据集,这是我一开始遇到的错误。
Error while fetching MNIST image
from sklearn.datasets import fetch_openml
mnist = fetch_openml('mnist_784')
x, y = mnist['data'], mnist['target']
digit = x[36001]
x
是二维的;试试这个:
digit = x[36001, :]
既然您遇到了错误,这一定是由于 x 未被视为 numpy array
,请尝试以下两种方法:
digit = x.iloc[36001, :]
或
digit = x.to_numpy()[36001,:]
扩展我的评论,我认为 openml 的 MNIST 数据集最近(?)切换到 return 一个 pandas DataFrame 而不是 numpy 数组。另一个可能的修复是在函数调用中:
mnist = fetch_openml('mnist_784', as_frame=False)
我正在尝试使用 MNIST 数据集,这是我一开始遇到的错误。 Error while fetching MNIST image
from sklearn.datasets import fetch_openml
mnist = fetch_openml('mnist_784')
x, y = mnist['data'], mnist['target']
digit = x[36001]
x
是二维的;试试这个:
digit = x[36001, :]
既然您遇到了错误,这一定是由于 x 未被视为 numpy array
,请尝试以下两种方法:
digit = x.iloc[36001, :]
或
digit = x.to_numpy()[36001,:]
扩展我的评论,我认为 openml 的 MNIST 数据集最近(?)切换到 return 一个 pandas DataFrame 而不是 numpy 数组。另一个可能的修复是在函数调用中:
mnist = fetch_openml('mnist_784', as_frame=False)