- 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
- Load the MNIST dataset:
(X_train, y_train), (X_val, y_val) = mnist.load_data()
- 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))) ...