Question: 9 . ( coding ) baseline Multi - Layer Perceptron model for the MNIST dataset 1 ) import numpy from keras.datasets import mnist from keras.models
coding baseline MultiLayer Perceptron model for the MNIST dataset
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 nputils
from keras.datasets import mnist
import matplotlib.pyplot as plt
# load downloaded if needed the MNIST dataset
Xtrain, YtrainXtest, Ytest mnist.loaddata
describe Xtrain, YtrainXtest, Ytest
YOUR WORK HERE pts
# flatten images to a vector for each image
numpixels Xtrain.shape Xtrain.shape
Xtrain Xtrain.reshapeXtrain.shape numpixelsastypefloat
Xtest Xtest.reshapeXtest.shape numpixelsastypefloat
# normalize inputs from to
Xtrain Xtrain
Xtest Xtest
# one hot encode outputs
Ytrain nputils.tocategoricalYtrain
Ytest nputils.tocategoricalYtest
numclasses Ytest.shape
# define baseline model
# create model
model Sequential
model.addDensenumpixels, inputdimnumpixels, activation'relu'
model.addDensenumclasses, activation'softmax'
show modelsummary
YOUR WORK HERE pts
# Compile model
model.compileloss'categoricalcrossentropy', optimizer'adam', metricsaccuracy
# Fit the model
# change epochs and batchsize later
model.fitXtrain, Ytrain, validationdataXtest, Ytest epochs batchsize verbose
# Final evaluation of the model
scores model.evaluateXtest, ytest, verbose
printBaseline Error: fscores
pts Explain the change in performance by changing these parameters: epochs and batchsize five
times
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
