How to do it...

  1. Import the libraries as follows:
import numpy as np import pandas as pdfrom sklearn.model_selection import train_test_splitimport matplotlib.pyplot as pltfrom keras.models import Sequentialfrom keras.layers import Densefrom keras.utils import to_categoricalfrom keras.callbacks import Callbackfrom keras.datasets import mnistSEED = 2017
  1. Load the MNIST dataset:
(X_train, y_train), (X_val, y_val) = mnist.load_data()
  1. Show an example of each label and print the count per label:
# Plot first image of each labelunique_labels = set(y_train)plt.figure(figsize=(12, 12))i = 1for label in unique_labels: image = X_train[y_train.tolist().index(label)] plt.subplot(10, 10, i) plt.axis('off') plt.title("{0}: ({1})".format(label, y_train.tolist().count(label))) ...

Get Python Deep Learning 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.