liveBook · Manning

MNIST dataset

As explained in Deep Learning with Python, Third Edition

A standard dataset of handwritten-digit images used for machine-learning experiments and examples.

MNIST is a standard benchmark for classifying grayscale handwritten digits. It contains 60,000 training images and 10,000 test images, each a 28 × 28 image labeled with a digit from 0 through 9. Solving MNIST is a practical first check that a neural-network workflow is functioning. section 2.1

Loading and inspecting MNIST

Keras loads MNIST into four NumPy arrays: train_images, train_labels, test_images, and test_labels. The training images have shape (60000, 28, 28); test images have shape (10000, 28, 28). Each image is a rank-3 collection of 28 × 28 uint8 grayscale matrices, with pixel values from 0 to 255. The matching label is an integer digit, such as train_labels[4] = 9. section 2.1 section 2.2.5

Listing 2.1 Loading the MNIST dataset in Keras
from keras.datasets import mnist

(train_images, train_labels), (test_images, test_labels) = mnist.load_data()

Shows the compact Keras call that loads the training and test arrays used throughout the workflow. section 2.1

A typical MNIST experiment prepares the arrays before training:

  • Flatten each 28 × 28 image into 784 values and convert pixel values to float32 in the 0–1 range. section 2.1
  • Train a neural network on train_images and train_labels, then evaluate it on the separate test arrays. section 2.1
  • Interpret predictions as ten class scores; the largest score selects the predicted digit. section 2.1

How Deep Learning with Python, Third Edition covers it

How deep it goes
Explains dataset contents, tensor representation, preprocessing, prediction, and evaluation, but not dataset construction or collection details.
Examples
Uses Keras loading code, array-shape inspection, a displayed digit, preprocessing steps, predictions, and test accuracy.
What it assumes
Assumes basic Python and array familiarity while introducing Keras loading, NumPy-backed data, tensor attributes, and classification terminology.
What you can do after
Apply it via Keras to load, inspect, preprocess, train on, predict with, and evaluate a digit-classification dataset.
How it connects
Connects handwritten-digit classification with neural networks, Keras, NumPy arrays, tensors, labels, and supervised evaluation.

Also explained in

Compare how 5 books explain MNIST dataset →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with Python, Third Edition. The section links point to the parts of the book it draws on.