How to do it...

  1. Import the relevant packages and dataset, and visualize the input dataset:
from keras.datasets import mnistimport numpyfrom keras.datasets import mnistfrom keras.models import Sequentialfrom keras.layers import Densefrom keras.layers import Dropoutfrom keras.utils import np_utils(X_train, y_train), (X_test, y_test) = mnist.load_data()

In the preceding code, we are importing the relevant Keras files and are also importing the MNIST dataset (which is provided as a built-in dataset in Keras). 

  1. The MNIST dataset contains images of digits where the images are of 28 x 28 in shape. Let's plot a few images to see what they will look like in the code here:
import matplotlib.pyplot as plt%matplotlib inlineplt.subplot(221)plt.imshow(X_train[0], ...

Get Neural Networks with Keras Cookbook 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.