Plotting the 10 digits in subplots

We will align the images in a grid of two rows and five columns. We first set the rectangular canvas by plt.figure()For each sample image of a digit, we define the axes with the plt.subplot() function, and then call imshow() to show the arrays of color values as images. Recall that the colormap 'gray_r' plots values in grayscale from white to black with values from zero to maximum. As there is no need for x and y tick labels to show the scales, we will remove them by passing an empty list to plt.xticks() and plt.yticks() to remove the clutter. Here is the code snippet to do so:

import matplotlib.pyplot as plt

nrows, ncols = 2, 5
plt.figure(figsize=(6,3))

for i in range(ncols * nrows):
ax = plt.subplot(nrows, ncols, i + 1)
ax.imshow(digits.images[i],cmap='gray_r')
plt.xticks([])
plt.yticks([])
plt.title(digits.target[i])

As you can see from the following figure, the images are a bit blurry to human eyes. But, believe it or not, there are enough details for the algorithm to extract features and differentiate between each digit. We will observe this together along with our workflow:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.189.237