Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Load data from mnist and reduce its size so the homework runs faster. Only use the first 1 5 0 0 0 images for training
Load data from mnist and reduce its size so the homework runs faster. Only use the first images for training and for test. The MNIST digits from keras datasets are already scaled to a value between and for the greyscale. You do not need to do any further scaling.
import matplotlib.pyplot as plt
import numpy as np
from tensorflow.keras.datasets import mnist
trainimages, trainlabelstestimages, testlabels mnist.loaddata
trainimages trainimages:::
trainlabels trainlabels:
testimages testimages:::
testlabels testlabels:
trainimages.shape
trainimages trainimages.reshape
trainimages trainimages.astypefloat
testimages testimages.reshape
testimages testimages.astypefloat
Problem
a create a sequential model with two dense layers. The first layer should have neurons. Use ReLU for the first layers activation. Pick the best size and activation for the output layer
b Compile the model using the rmsprop optimizer. Use the appropriate loss and metrics for the MNIST classification problem.
c Fit the model using epochs, batch size and use of the data for validation validationsplit Save the history into a variable called history.
de Plot out the model accuracy vs epoch for the training and validation data.
f Plot the model loss vs epoch for the training and validation data.
g Print the model summary
h Did the model overfit? Explain your reasoning. predict the digit for the first ten Part i Do fourfold cross validation on the model above and print out the validation accuracy for each fold. Also, plot the training and validation accuracy per fold
For problem we are going to make a binary classifier using the same MNIST dataset. We are going to classify digits as zero or not zero.
a Make the trainlabels and testlabels data be zero or one with one being everything that is not a zero.
b Create a model with one dense layer and one neuron. Choose the appropriate activation for binary classification.verything that is not a zero.old.test images, then compare to the actual values.
c compile the model using rmsprop for the optimizer. Choose the best loss and metrics for binary classification
d Fit the model and use the testimages and testlabels for the validation data instead of doing a validation split on the training data. Use epochs and the proper loss and metrics for a binary classification problem.
e Plot out the model accuracy vs epoch for the traning and validation data.
f Plot the model loss vs epoch for the training and validation data.
g print the model summary
h Did the model overfit? Explain your reasoning.
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