Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

need help! the output should be 3 things posted downbelow. blem 2) [Python] The MNIST dataset is divided into training and test sets. Each set

need help! the output should be 3 things posted downbelow. image text in transcribed
image text in transcribed
blem 2) [Python] The MNIST dataset is divided into training and test sets. Each set comprises eries of images ( 2828-pixel images of handwritten digits) and their respective labels (values n09, representing which digit the image corresponds to). a) Use mnist function in keras.datasets to load and split the MNIST dataset into the training and testing sets. Name the sets as xtrain, ytrain, and xtest, ytest. Print the following: The number of images in each training and testing set and the image width and height. b) Write a function that takes two inputs: 1) images of ten digits and 2) their corresponding labels and plots a figure with 10 subplots for each 09 digits. Each subplot has the number of the handwritten digit in its title. c) Create a loop to call the function in (b) and plot images from the training set to create a figure that includes all the 10 digits (09). d) Select the 0 and 8 digits from the training and testing sets and name them: xtrain_01,y_train_01 and xtest_01, ytest_ 01. e) In machine learning, we typically divide the training set into two training and validation sets to adjust the machine learning model parameters. In your code, randomly select 500 training images and their corresponding labels (from xtrain_01 and ytrain_01) as the validation set and name them \( x_{\text {_ valid_ } 01} \) and yvalid_01, respectively. Name the remaining training images and their labels as x _train_01 and ytrain_01, respectively. Note: that there are no overlaps between the two sets. f) Print the number of images in each training, validation, and testing set. g) Use the function created in part (b) to plot 10 images from the validation set. h) Convert each image in the three training, validation and testing sets to one attribute by calculating the average of all the pixel values in the center 44 grid of the image. i) Plot the attribute values of the 500 images in the validation set that you calculated in part (h). Use different colors and shapes for 0 's and 8 's. The x-axis in your figure is the image number ( 1 to 500 ), and the y-axis is the calculated attribute. Label the axes and add legends appropriately. j) Based on your observation from the plot (i.e., validation set), guess a threshold on the attribute you think would differentiate the two classes with the highest accuracy. k) Calculate the training, validation, and testing accuracies based on the selected threshold on the corresponding sets and print them. The number of images in tralning set is 11274 The number of lages in validation set is 500 The number of lages in testing set is 1954 Assignment 2 5amples of the validation 1aages. - Problem 2: MNIST dataset The number of lages in training set is 6eee The number of Inages in testing set is 160e0 The Images dinensions are 2828 selecting 10 lmages from training set The selected threshod based on the validation data Is: 50 The validation accuracy is 93.6 If you flnallied the threshold enter x i x The training accuracy is 92.08 The testling accuracy is 93.09

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions