Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago