小编Arj*_*wal的帖子

为什么在 MNIST 分类器代码中使用 X[0] 会给我一个错误?

我正在学习使用 MNIST 数据集进行分类。我遇到了一个错误,我无法弄清楚,我已经做了很多谷歌搜索,但我什么也做不了,也许你是专家,可以帮助我。这是代码——

>>> from sklearn.datasets import fetch_openml
>>> mnist = fetch_openml('mnist_784', version=1)
>>> mnist.keys()
Run Code Online (Sandbox Code Playgroud)

输出:dict_keys(['data', 'target', 'frame', 'categories', 'feature_names', 'target_names', 'DESCR', 'details', 'url'])

>>> X, y = mnist["data"], mnist["target"]
>>> X.shape
Run Code Online (Sandbox Code Playgroud)

输出:(70000, 784)

>>> y.shape
Run Code Online (Sandbox Code Playgroud)

输出:(70000)

>>> X[0]

output:KeyError                                  Traceback (most recent call last)
c:\users\khush\appdata\local\programs\python\python39\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
   2897             try:
-> 2898                 return self._engine.get_loc(casted_key)
   2899             except KeyError as err:

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 0

The above exception was …
Run Code Online (Sandbox Code Playgroud)

machine-learning mnist

2
推荐指数
3
解决办法
1372
查看次数

标签 统计

machine-learning ×1

mnist ×1