How to do it...

Let's see how to build autoencoders to reconstruct handwritten digit images:

  1. The full code for this recipe is given in the AutoencMnist.py file that has already been provided to you. Let's look at how it's built. Create a new Python file, and import the following package:
from keras.datasets import mnist
  1. To import the MNIST dataset, the following code must be used:
(XTrain, YTrain), (XTest, YTest) = mnist.load_data()print('XTrain shape = ',XTrain.shape)print('XTest shape = ',XTest.shape)print('YTrain shape = ',YTrain.shape)print('YTest shape = ',YTest.shape)
  1. After importing the dataset, we have printed the shape of the data, and the following results are returned:
XTrain shape = (60000, 28, 28)XTest shape = (10000, 28, ...

Get Python Machine Learning Cookbook - Second Edition 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.