title: How to show an image of a certain class with predictions in a multiclass classification problem?
body: <p>I've been working on a multiclass classification problem, where I need to make a function to show an image of a certain class of the fashion MNIST dataset and make a prediction on it. For example, plot 3 images of the <code>T-shirt</code> class with their predictions. I have tried different things but no success yet. I'm missing a conditional statement and I can't figure out how  &amp; where to implement it in my function.</p>
  <p>This is what I've come up with so far:</p>
  <pre><code># Make function to plot image
  def plot_image(indx, predictions, true_labels, target_images):
    &quot;&quot;&quot;
    Picks an image, plots it and labels it with a predicted and truth label.
  
    Args:
    indx: index number to find the image and its true label.
    predictions: model predictions on test data (each array is a predicted probability of values between 0 to 1).
    true_labels: array of ground truth labels for images.
    target_images: images from the test data (in tensor form).
  
    Returns:
    A plot of an image from `target_images` with a predicted class label
    as well as the truth class label from `true_labels`.
    &quot;&quot;&quot;
    # Set target image
    target_image = target_images[indx]
    # Truth label
    true_label = true_labels[indx]
    # Predicted label
    predicted_label = np.argmax(predictions)  # find the index of max value
  
    # Show image
    plt.imshow(target_image, cmap=plt.cm.binary)
    plt.xticks([])
    plt.yticks([])
  
    # Set colors for right or wrong predictions
    if predicted_label == true_label:
      color = 'green'
    else:
      color = 'red'
  
    # Labels appear on the x-axis along with accuracy %
    plt.xlabel(&quot;{} {:2.0f}% ({})&quot;.format(class_names[predicted_label],
                                  100*np.max(predictions),
                                  class_names[true_label]),
                                  color=color)
  
  
  
  # Function to display image of a class
  def display_image(class_indx):
    # Set figure size
    plt.figure(figsize=(10,10))
  
    # Set class index
    class_indx = class_indx
  
    # Display 3 images
    for i in range(3):
      plt.subplot(1, 3, i+1)
      # plot_image function
      plot_image(indx=class_indx, predictions=y_probs[class_indx],
                 true_labels=test_labels, target_images=test_images_norm)
  </code></pre>
  <p>These are the class names <code>'T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat', 'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot'</code>. When I call the display function <code>display_image()</code> and pass the class index as an argument <code>display_image(class_indx=15)</code>, I'm getting the same image and the same prediction 3 times (<em>Notice my wrong approach, I'm passing index number instead it should be the class name</em>). I need a function that takes a <code>str</code> (the class name) and displays 3 different predictions of that class. For instance, <code>display_image('Dress')</code> should return 3 images of <code>Dress</code> class along with its 3 different predictions that my model has made, <code>Prediction#1 (65%)</code>, <code>Prediction#2 (100%)</code>, <code>Prediction#3 (87%)</code> like so. Thanks!</p>