The following is a small example of building a simple multilayer perceptron (covered in detail in Chapter 5) to classify handwritten digits from the MNIST set:
import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Dropout
from keras.optimizers import SGD
from keras import utils
import numpy as np
# define some hyper parameters
batch_size = 100
n_inputs = 784
n_classes = 10
n_epochs = 10
# get the data
(x_train, y_train), (x_test, y_test) = mnist.load_data()
# reshape the two dimensional 28 x 28 pixels
# sized images into a single vector of 784 pixels
x_train = x_train.reshape(60000, n_inputs)
x_test = x_test.reshape(10000, n_inputs)
# convert the input values to float32
x_train = x_train.astype(np.float32)
x_test = x_test.astype(np.float32)
# normalize the values of image vectors to fit...