[Python] KeyError while fetching MNIST data

Discussão em 'Python' iniciado por Stack, Agosto 6, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to play around MNIST dataset:

    from sklearn.datasets import fetch_openml
    mnist = fetch_openml('mnist_784')
    x, y = mnist['data'], mnist['target']
    digit = x[36001]


    Here is the error I got at the very beginning:

    Error screenshot to text:

    KeyError Traceback (most recent call last)
    ~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
    2896 try:
    -> 2897 return self._engine.get_loc(key)
    2898 except KeyError:

    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: 36000

    During handling of the above exception, another exception occurred:

    KeyError Traceback (most recent call last)
    <ipython-input-8-8b8bb0b2ff6d> in <module>
    ----> 1 some_digit = X[36000] # Selecting the 36,000th image.

    Continue reading...

Compartilhe esta Página