Answered step by step
Verified Expert Solution
Link Copied!

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 15000 images for training and 2000 for test. The MNIST digits from keras datasets are already scaled to a value between 0 and 1 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
(train_images, train_labels),(test_images, test_labels)= mnist.load_data()
train_images = train_images[:15000,:,:]
train_labels = train_labels[:15000]
test_images = test_images[:2000,:,:]
test_labels = test_labels[:2000]
train_images.shape
train_images = train_images.reshape((15000,28*28))
train_images = train_images.astype("float32")/255
test_images = test_images.reshape((2000,28*28))
test_images = test_images.astype("float32")/255
Problem 1
a) create a sequential model with two dense layers. The first layer should have 512 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 25 epochs, batch size 128 and use 33% of the data for validation (validation_split=0.33). Save the history into a variable called history.
d)e) 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 four-fold 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 2, 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 train_labels and test_labels 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 test_images and test_labels for the validation data instead of doing a validation split on the training data. Use 50 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

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

Database Design And Implementation

Authors: Edward Sciore

2nd Edition

3030338355, 978-3030338350

More Books

Students also viewed these Databases questions

Question

Explain the pages in white the expert taxes

Answered: 1 week ago