- 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).
- 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], ...