Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i need f-k i provided a-e below! 1 2 4 5 6 import numpy as np import matplotlib.pyplot as plt from keras.datasets import mnist #

i need f-k i provided a-e below! image text in transcribed
image text in transcribed
1 2 4 5 6 import numpy as np import matplotlib.pyplot as plt from keras.datasets import mnist \# Load MNIST dataset (x_train, y_train), (x_test, \( y_{\text {_test) }} \) ) mnist.load_data O \# Print the number of images in each set and the image width and height print ("Number of images in x.train: ", x_train, shape[Q.]) 10 print("Number of images in x-test: ", x-test. shape [0]) 11 print("Inage width and heigbt:", x-train, shape[1], X_train,shape [2]) 13 \# Select and 8 digits from the training and testing sets 14x train 01=np. concatenate( [x-train[y-train =0],x train [y _train =8]]) 15 y_train 01=np. concatenate [y _train [y _train =0],y, train[y-train =8]] ) 16x-test_01 =np, concatenate [x _test [y _test =0],x,test [y test =8]]} 19 \# Divide the training set into validation and training sets 20n=500 indicesty np.random, permutation( x-train_01, shape[0]) x-valiogo1 = x-train_01[indices [':n] A Print the number of images in each set print("Number of images in x-troin 01:,", x-train o1, shape [0]) print("Number of images in x-valid 01:", x.valid 01, shape (0j) print ("Number of images in x-test_01:", x-test.01. shape[0]) plot the images in (b): Vef plot_digits(imoges, lobels): fig, axes - plt. subplots(2, 5, figsize-(10, 4)) for i, ax in enumerate (axes. filot): ox. inshom (inoges[i] cmapa 'binary') ax. set title(str(tabels[i])) plt. showo code for the loop in (c) to plot the images from the training set: :Plot the first 18 images from the training set plot_digits (x-train_e1[tig], y_troin_e1 (:10]) code for parts D and E : - Selecting bo and 8 digits trom training and test sets x train_e1 =x-troin (y _train =0)(y train =8)} - Dividing the training set into validation and trainine sets, vol findex = no. randing choice (range In the code above, x train_ 01 and \( y_{\text {_train_ }} 01 \) represent the training images and labeis of only digits 0 and 8,x test 01 and y test_ 01 represent the test images and lahalo of blem 2) [Python] The MNIST dataset is divided into training and test sets. Each set comprises ries of images (2828-pixel images of handwritten digits) and their respective labels (values n 0 - 9, 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, 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, y_test_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 x_train_01 and ytrain_01) as the validation set and name them images and their labels as xtrain_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.c., 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

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_2

Step: 3

blur-text-image_3

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

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions

Question

Explain how marketing intelligence differs from marketing research.

Answered: 1 week ago

Question

4. How has e-commerce affected business-to-business transactions?

Answered: 1 week ago