The following function will help you visualize the MNIST data. By passing in the index of a training example, the show_digit function will display that training image along with its corresponding label in the title:
# Visualize the data import matplotlib.pyplot as plt %matplotlib inline #Displaying a training image by its index in the MNIST set def display_digit(index): label = y_train[index].argmax(axis=0) image = X_train[index] plt.title('Training data, index: %d, Label: %d' % (index, label)) plt.imshow(image, cmap='gray_r') plt.show() # Displaying the first (index 0) training image display_digit(0)
X_train = X_train.reshape(60000, 784) X_test = X_test.reshape(10000, 784) X_train = X_train.astype('float32' ...