Preparing the data

The first activity is the data preparation. To start, let's import all the required libraries. As we discussed earlier, we are going to use the MNIST database for the dataset of handwritten digits:

from __future__ import print_functionfrom matplotlib import pyplot as pltimport kerasfrom keras.datasets import mnist

mnist is the dataset that contains the handwritten digits database, so we need to import that, as follows:

from keras.models import Sequential

The preceding code imports the Sequential model type from Keras. This is simply a linear stack of neural network layers:

from keras.layers import Dense, Dropout, Flatten

Now, we need to import the core layers from Keras. These are the layers that are used in almost any ...

Get Machine Learning for Mobile now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.