Question: 9 . ( coding ) baseline Multi - Layer Perceptron model for the MNIST dataset 1 ) import numpy from keras.datasets import mnist from keras.models

9.(coding) baseline Multi-Layer Perceptron model for the MNIST dataset
1)
import numpy
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Dropout
from keras.utils import np_utils
from keras.datasets import mnist
import matplotlib.pyplot as plt
# load (downloaded if needed) the MNIST dataset
3
(X_train, Y_train),(X_test, Y_test)= mnist.load_data()
describe (X_train, Y_train),(X_test, Y_test)
YOUR WORK HERE (2 pts)
# flatten 28*28 images to a 784 vector for each image
num_pixels = X_train.shape[1]* X_train.shape[2]
X_train = X_train.reshape(X_train.shape[0], num_pixels).astype('float32')
X_test = X_test.reshape(X_test.shape[0], num_pixels).astype('float32')
# normalize inputs from 0-255 to 0-1
X_train = X_train /255.
X_test = X_test /255.
# one hot encode outputs
Y_train = np_utils.to_categorical(Y_train)
Y_test = np_utils.to_categorical(Y_test)
num_classes = Y_test.shape[1]
# define baseline model
# create model
model = Sequential()
model.add(Dense(num_pixels, input_dim=num_pixels, activation='relu'))
model.add(Dense(num_classes, activation='softmax'))
show model_summary
YOUR WORK HERE (2 pts)
# Compile model
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
# Fit the model
# change epochs and batch_size later
model.fit(X_train, Y_train, validation_data=(X_test, Y_test), epochs=10, batch_size=200, verbose=2)
# Final evaluation of the model
scores = model.evaluate(X_test, y_test, verbose=0)
print("Baseline Error: %.2f%%"%(100-scores[1]*100))
2)[4 pts] Explain the change in performance by changing these parameters: epochs and batch_size (five
times)
3)[4 pts] Add a few additional hidden layers in the network and explain the changes in performance.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!