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:
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).
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
- Import
tensorflowandnumpyto your program. The first one loads the data, the second one transforms it; - Load the data in your program. You need
x_trainandy_trainonly. Skipx_testandy_testin return ofload_data(), we will create them ourselves in the next stage.
Sometimesx_trainorx_testwill be called the features array (because they contain brightnesses of the pixels, which are the images' features).y_trainory_testwill be called the target array (because they contain classes, digits which we are going to predict); - Reshape the features array to the 2D array with rows ( = number of images in the dataset) and columns ( = number of pixels in each image);
- 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