Classification of Handwritten Digits. Stage 1/5

The Keras dataset

Report a typo

Description

We start by feeding data to our program. We will use the MNIST digits dataset from Keras. Make sure to check the link above before you continue reading — it contains information on how to load the dataset.

Here is a sample of 28x28 images from the dataset:

Sample 28x28 images with numbers

To proceed, we need to figure out how a machine sees pictures. A computer senses an image as a 2D array of pixels. Each pixel has coordinates (x, y) and a value — from 0 (the darkest) to 255 (the brightest).

pixel location

In machine learning, we need to flatten (convert) an image into one dimension array. This means that a 28x28 pixels image, which is initially a 2D array, transforms into a 1D array with 28x28 = 784 elements in it.

Objectives

  1. Import tensorflow and numpy to your program. The first one loads the data, the second one transforms it;
  2. Load the data in your program. You need x_train and y_train only. Skip x_test and y_test in return of load_data(), we will create them ourselves in the next stage.
    Sometimes x_train or x_test will be called the features array (because they contain brightnesses of the pixels, which are the images' features). y_train or y_test will be called the target array (because they contain classes, digits which we are going to predict);
  3. Reshape the features array to the 2D array with nn rows (nn = number of images in the dataset) and mm columns (mm = number of pixels in each image);
  4. Print information about the dataset: target classes' names; the shape of the features array; the shape of the target array; the minimum and maximum values of the features array. Use the following format for the shapes: (the number of rows, the number of columns).

Tip: Look for the numpy .reshape() and .unique() methods in the official documentation.

The input is the MNIST dataset. The output contains flattened features array. Provide the answers in the same format and order as in the example below. The answers are given for reference only, the actual numbers may differ.

Example

Example 1: an example of the output

Classes: [1 2 3 5 6]
Features' shape: (200, 100)
Target's shape: (200,)
min: 0.0, max: 100.0
Write a program
IDE integration
Checking the IDE status
___

Create a free account to access the full topic