Registrations Closing Soon for DevOps Certification Training by CloudxLab | Registrations Closing in

  Enroll Now

Visualizing the Data

With reference to the class labels and the class names as given in the official documantation of Keras, let us store all them in a list class_names as follows.


  • plt.imshow(X, cmap="binary") displays X data as an image. cmap is used to map scalar data to colors. cmap=binary maps the image color to black and white format while displaying the image.

  • plt.axis('off') is used to turn off the axes for subplots( you could remove this line and observe the difference for yourself).

  • plt.subplot(a,b) is used to create a figure and a set of subplots with a rows and b columns.

  • plt.subplots_adjust() is used to tune the subplot layout.

  • Write the following code to store the class names of the data set.

    class_names = ["T-shirt/top", "Trouser", "Pullover", "Dress", "Coat",
           "Sandal", "Shirt", "Sneaker", "Bag", "Ankle boot"]
  • Plot an image using Matplotlib's plt.imshow() function, with a 'binary' color map:

    print("Class label is:", y_train[0])
    print("Class name is:", class_names[y_train[0]])
    plt.imshow(X_train[0], cmap="binary")
  • Let's take a look at a sample of the images in the dataset.

    n_rows = 4
    n_cols = 10
    plt.figure(figsize=(15, 6))
    for row in range(n_rows):
        for col in range(n_cols):
            index = n_cols * row + col
            plt.subplot(n_rows, n_cols, index + 1)
            plt.title(class_names[y_train[index]], fontsize=12)
    plt.subplots_adjust(wspace=0.2, hspace=0.5)

No hints are availble for this assesment

Answer is not availble for this assesment

Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...