Build a shallow neural network to classify MNIST digits
In [ ]:
import numpy as np
np.random.seed(42)
In [ ]:
import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import SGD
In [ ]:
(X_train, y_train), (X_test, y_test) = mnist.load_data()
In [ ]:
X_train.shape
In [ ]:
y_train.shape
In [ ]:
y_train[0:99]
In [ ]:
X_test.shape
In [ ]:
X_test[0]
In [ ]:
y_test.shape
In [ ]:
y_test[0]
In [ ]:
X_train = X_train.reshape(60000, 784).astype('float32')
X_test = X_test.reshape(10000, 784).astype('float32')
In [ ]:
X_train /= 255
X_test /= 255
In [ ]:
X_test[0]
In [ ]:
n_classes = 10
y_train = keras.utils.to_categorical(y_train, n_classes)
y_test = keras.utils.to_categorical(y_test, n_classes)
In [ ]:
y_test[0]
In [ ]:
# add architecture here
In [ ]:
model.summary()
In [ ]:
(64*784)
In [ ]:
(64*784)+64
In [ ]:
(10*64)+10
In [ ]:
# compile model here
In [ ]:
# train model here
In [ ]:
model.evaluate(X_test, y_test)
In [ ]: