Training and test data
MNIST is a classic handwritten-digit classification dataset.
From Mark to Category
A handwritten-digit classifier starts with an image and must place that image into one of ten categories: 0 through 9. MNIST provides a concrete dataset for this task. It contains handwritten digit images together with the labels that identify the digits represented by those images.
The central pairing is image plus label: the image is the input, and the label identifies which digit category the image belongs to.
Inside One Digit Image
For this classification problem, each MNIST image is grayscale and has dimensions of 28 × 28 pixels. The visible handwritten mark is therefore represented to the neural-network example as a two-dimensional arrangement of pixel positions, with a grayscale value associated with each position. The classifier does not receive the digit as an already named category. It receives the image representation and must assign the image to one of the categories from 0 through 9.
Four Parts of the Dataset
Keras and MNIST provide four related parts for the neural-network example: training images, training labels, test images, and test labels. The images are the handwritten-digit inputs. The labels are the corresponding digit answers. The training pair supplies examples for learning, while the test pair is kept as a separate set for measuring how the classifier performs.
| Dataset part | Contains | Role |
|---|---|---|
| Training images | Handwritten digit images | Inputs used for learning |
| Training labels | Digit labels corresponding to the training images | Answers associated with the learning inputs |
| Test images | Handwritten digit images in the separate test set | Inputs used for evaluation |
| Test labels | Digit labels corresponding to the test images | Answers used to measure performance |
The four MNIST components and their roles in the neural-network example.
Following One Example
Tracing an image-label pair
Suppose one MNIST image visibly represents a handwritten 7. Trace the information from the image to the classification task.
Represent the input: The handwritten mark is represented as a grayscale image with dimensions of 28 × 28 pixels.
Keep the answer separate: The corresponding label identifies the digit category as 7. The label is associated with the image; it is not another pixel in the image.
Place the pair in a split: If the pair belongs to the training set, the image and its label form part of the data used for learning. If the pair belongs to the test set, it forms part of the separate data used to measure performance.
Classify: The classifier receives the image and must place it into one of the ten categories from 0 through 9.
A single example consists of an image representation and its corresponding digit label. The training or test role depends on which dataset split contains that pair.
What do you think happens?
A 28 × 28 grayscale image is paired with the label 3. What is the classifier expected to do with that image?
Reveal answer
Answer: Place the image into the digit category 3.
The image is the input representation, while the label is the corresponding digit answer. The classification task is to assign the image to one of the categories from 0 through 9.
Loading the Learning Problem
Keras supplies MNIST in a form that separates images from their corresponding labels and separates training data from test data. This gives the neural-network example a clear starting point: the training image data can be considered alongside the training labels, and the test image data can later be considered alongside the test labels. The data-loading step establishes the source and organization of the problem; it does not, by itself, show the complete construction of the neural network.
When reading a neural-network example, identify the four data components before focusing on the network itself. Ask which variables represent images, which represent labels, and which pair belongs to training rather than testing.
Mistakes About the Split
Treating the label as part of the image
The image and its corresponding label are separate parts of the dataset.
Fix:
Treat the image as the input representation and the label as the associated digit answer.Confusing training data with test data
MNIST is divided into training and test images, with corresponding labels.
Fix:
Keep the training image-label pair conceptually separate from the test image-label pair.Expecting the dataset-loading step to construct the whole neural network
The data source establishes the problem's inputs and labels, but the complete neural-network construction is not shown at this stage.
Fix:
First trace how the data enters the workflow; study the network elements separately afterward.
Check Your Understanding
Explain, in your own words, why a handwritten digit example needs both an image and a label. Then describe the difference between a training image-label pair and a test image-label pair.
Hints
- Mention the 28 × 28 grayscale representation.
- Explain what the label identifies.
- State which pair supports learning and which pair supports performance measurement.
A learner says, “The test label teaches the network what to do while it is learning.” Correct the statement using the roles of the four MNIST data components.
Hints
- Contrast the training pair with the test pair.
- Remember that test data is used to measure performance.
Key Takeaways
- MNIST is a classic handwritten-digit classification dataset.
- Each image is grayscale and has dimensions of 28 × 28 pixels.
- The classifier receives an image and assigns it to one of the ten categories from 0 through 9.
- Training images and training labels form the learning data; test images and test labels form the separate data used to measure performance.
- Keras supplies MNIST with the images and labels separated into training and test data.
Key Takeaways
- MNIST contains grayscale handwritten-digit images and their corresponding labels.
- Each image is represented as a 28 × 28 pixel grid.
- The classification categories are the digits 0 through 9.
- Training image-label pairs support learning, while test image-label pairs support performance measurement.
- Keras provides MNIST in a form that separates images from labels and training data from test data.