In this section, we will use the concepts we learned about in this chapter to build a deeper neural network to classify handwritten digits:
- We will start with a new notebook and then load the required dependencies:
import numpy as np
np.random.seed(42) import keras from keras.datasets import mnist from keras.models import Sequential
from keras.layers import Dense from keras.layers import Dropout # new! from keras.layers.normalization
# new! import BatchNormalization # new! from keras import regularizers # new! from keras.optimizers import SGD
- We will now load and pre-process the data:
(X_train,y_train),(X_test,y_test)= mnist.load_data() X_train= X_train.reshape(60000,784). astype('float32')
X_test= X_test.reshape(10000,784).astype('float32')
X_train/=255 X_test/=255 n_classes=10 y_train=keras.utils.to_categorical(y_train,n_classes...