O'Reilly logo

Python Deep Learning Cookbook by Indra den Bakker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required