Question: please fill in the bkanks below: use this code fill in the blanks of the code. Python language Classifying handwritten digits: Using the MNIST dataset,



Classifying handwritten digits: Using the MNIST dataset, we want to build a simple threshold-based classifier that classifies 2's from 3's. To do that we start, we the following steps. 1. We created a new training, validation, and test set of only the 2 and 3 digits. We randomly selected 100 images of the training set as the validation set and the remaining ones as the training set. 2. Converted each image to one attribute by calculating the average of all the pixel values in the center 5x5 grid of the image 3. We plotted the attribute values of the validation set. We used different colors and shapes for 2's and 3's. The x-axis in this figure is the image number, and they axis is the calculated attribute. Label the axes and add legends appropriately. The code is shown in the pdf file below Python Examinynb-Colaboratory.pdf Provide the correct values for blank 1: : blank 2: blank 3: blank 4: blank 5: blank 6: : blank 7: blank 8: in this code. Use numerical values as you would use in Python. Do not use spaces in your answers from keran.datasets import mint import matplotlib.pyplot na ple import numpy a np from random import randint. def img_plt images, loboto): plt.figure() #fignine=(15) for i in range(1,11) plt. subplot(2,5, i) plt.mahow(imagen 1-1,211, emap 'gray) plt.title('Label' str(labela111)) plt.how) det feat. plt feature, labels, digito) plt.figure() sample_numa-np.arange( feature.shape:01) plt.plot(sample_nume labelo-digits[011, feature[labels- digita[011,'ga', sample_nums[labels digitop111, feature[label.catdigita[11.'*') plt.xlabel('Sample #) plt.ylabel('Average of the 3x3 center grid') plt.title('Extrated feature from validation data') plt.show() det pred tun (features, threshold, digitin) y pred np.oner (features.chape) digit 0:1 yped featurethrenhold] = digital return y pred der acolun(labeln actual. labolo pced) ace-np. numlabels actuallabola pred)/lon (Labela_actunl) 100 toturnace (x_train, y_train), (x_testy_tient)mnist.load date() #selecting the testing and training not select digit[blankel, blank 21 x train dgx_train np. logical or(y train olet digit 01.Y_tro colect digito 11) ytrain dg y train np. logical or(y troelect digitor01._train select digita11) *_tent_dg x_ tent[np. logical or(y_tonolect_digito 01.y test select digito 11), 0:21 Y_tout dg utenti np. logical or(y_boot.elect_digita01.Y_cent-elect_digital print('Samples of the training imagen) img_plt train_dg0:10,1,1.8 train dg[0:101) print('Samples of the testing images) img plt(x_test_dg[0:10,:,: 1.y_test_dg[0:101) num_train_img_train dg.shape [0] train ind=np.arange(0, num_train_img) train_ind_s-np.random. permutation(train_ind) x_train dg=x_train dg[train_ind_s, :,:] Y_train_dg=y_train dg train_ind_5] Selecting the validation set *_val_dg-x_train_dg[blank3, :,:] y_val_dg=y_train dg blank4] #The rest of the training set. x_train dg=x_train dg blank5,1 y_train dg=y_train dg blank 6] print('samples of the validation images') img_plt(X_val_dg[0:10, :,:1,Y_val_dg[0:101) #computing the attributes feature_train-np.sum(x_train dg[, blank7, blank 81, axis=2) feature train=np.sum( feature_train, axis=1)/9 feature_val-np.sum(x_val_dg[:,blank7, blank81, axis=2) feature_val=np.sum ( feature_val, axis-1)/9 feature_test=np.sum(x_test_dg[:,blank7, blank8), axis=2) feature_test=np. sum(feature test, axis-1)/9 #plot the attribute values of the validation set feat plt(feature_val,y_val_dg, select_digits) Classifying handwritten digits: Using the MNIST dataset, we want to build a simple threshold-based classifier that classifies 2's from 3's. To do that we start, we the following steps. 1. We created a new training, validation, and test set of only the 2 and 3 digits. We randomly selected 100 images of the training set as the validation set and the remaining ones as the training set. 2. Converted each image to one attribute by calculating the average of all the pixel values in the center 5x5 grid of the image 3. We plotted the attribute values of the validation set. We used different colors and shapes for 2's and 3's. The x-axis in this figure is the image number, and they axis is the calculated attribute. Label the axes and add legends appropriately. The code is shown in the pdf file below Python Examinynb-Colaboratory.pdf Provide the correct values for blank 1: : blank 2: blank 3: blank 4: blank 5: blank 6: : blank 7: blank 8: in this code. Use numerical values as you would use in Python. Do not use spaces in your answers from keran.datasets import mint import matplotlib.pyplot na ple import numpy a np from random import randint. def img_plt images, loboto): plt.figure() #fignine=(15) for i in range(1,11) plt. subplot(2,5, i) plt.mahow(imagen 1-1,211, emap 'gray) plt.title('Label' str(labela111)) plt.how) det feat. plt feature, labels, digito) plt.figure() sample_numa-np.arange( feature.shape:01) plt.plot(sample_nume labelo-digits[011, feature[labels- digita[011,'ga', sample_nums[labels digitop111, feature[label.catdigita[11.'*') plt.xlabel('Sample #) plt.ylabel('Average of the 3x3 center grid') plt.title('Extrated feature from validation data') plt.show() det pred tun (features, threshold, digitin) y pred np.oner (features.chape) digit 0:1 yped featurethrenhold] = digital return y pred der acolun(labeln actual. labolo pced) ace-np. numlabels actuallabola pred)/lon (Labela_actunl) 100 toturnace (x_train, y_train), (x_testy_tient)mnist.load date() #selecting the testing and training not select digit[blankel, blank 21 x train dgx_train np. logical or(y train olet digit 01.Y_tro colect digito 11) ytrain dg y train np. logical or(y troelect digitor01._train select digita11) *_tent_dg x_ tent[np. logical or(y_tonolect_digito 01.y test select digito 11), 0:21 Y_tout dg utenti np. logical or(y_boot.elect_digita01.Y_cent-elect_digital print('Samples of the training imagen) img_plt train_dg0:10,1,1.8 train dg[0:101) print('Samples of the testing images) img plt(x_test_dg[0:10,:,: 1.y_test_dg[0:101) num_train_img_train dg.shape [0] train ind=np.arange(0, num_train_img) train_ind_s-np.random. permutation(train_ind) x_train dg=x_train dg[train_ind_s, :,:] Y_train_dg=y_train dg train_ind_5] Selecting the validation set *_val_dg-x_train_dg[blank3, :,:] y_val_dg=y_train dg blank4] #The rest of the training set. x_train dg=x_train dg blank5,1 y_train dg=y_train dg blank 6] print('samples of the validation images') img_plt(X_val_dg[0:10, :,:1,Y_val_dg[0:101) #computing the attributes feature_train-np.sum(x_train dg[, blank7, blank 81, axis=2) feature train=np.sum( feature_train, axis=1)/9 feature_val-np.sum(x_val_dg[:,blank7, blank81, axis=2) feature_val=np.sum ( feature_val, axis-1)/9 feature_test=np.sum(x_test_dg[:,blank7, blank8), axis=2) feature_test=np. sum(feature test, axis-1)/9 #plot the attribute values of the validation set feat plt(feature_val,y_val_dg, select_digits)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
