INNER CODE UNIT · Python
plot_image_prediction
MITDeepLearning/introtodeeplearning · mitdeeplearning/lab2.py:14
def plot_image_prediction(i, predictions_array, true_label, img):
predictions_array, true_label, img = predictions_array[i], true_label[i], img[i]
plt.grid(False)
plt.xticks([])
plt.yticks([])
plt.imshow(np.squeeze(img), cmap=plt.cm.binary)
predicted_label = np.argmax(predictions_array)
if predicted_label == true_label:
color = "blue"
else:
color = "red"
plt.xlabel(
"{} {:2.0f}% ({})".format(
predicted_label, 100 * np.max(predictions_array), true_label
),