Answered step by step
Verified Expert Solution
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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started