images_and_predictions = list(zip(digits.images[n_samples // 2:], predicted))
for index, (image, prediction) in enumerate(images_and_predictions[:4]):
plt.subplot(2, 4, index + 5)
plt.axis("off")
plt.imshow(image, cmap=plt.cm.gray_r, interpolation="nearest")
plt.title("Prediction: %i" % prediction)
After Change
// matplotlib.pyplot.imread. Note that each image must have the same size. For these
// images, we know which digit they represent: it is given in the "target" of
// the dataset.
_, axes = plt.subplots(2, 4)
images_and_labels = list(zip(digits.images, digits.target))
for ax, (image, label) in zip(axes[0, :], images_and_labels[:4]):
ax.set_axis_off()
ax.imshow(image, cmap=plt.cm.gray_r, interpolation="nearest")