官术网_书友最值得收藏!

Visualizing the training data

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')
X_test = X_test.astype('float32')
X_train /= 255
X_test /= 255
print("Train the matrix shape", X_train.shape)
print("Test the matrix shape", X_test.shape)

#One Hot encoding of labels.
from keras.utils.np_utils import to_categorical
print(y_train.shape)
y_train = to_categorical(y_train, 10)
y_test = to_categorical(y_test, 10)
print(y_train.shape)
主站蜘蛛池模板: 潍坊市| 沅陵县| 义马市| 承德市| 玛曲县| 永州市| 牟定县| 富源县| 孙吴县| 易门县| 开江县| 湄潭县| 昌平区| 天峻县| 铜川市| 灵寿县| 兴国县| 赤城县| 绵竹市| 竹北市| 土默特右旗| 苏尼特右旗| 韩城市| 大英县| 伽师县| 辽阳县| 郁南县| 永福县| 顺昌县| 乌兰浩特市| 鄂尔多斯市| 景宁| 师宗县| 双城市| 增城市| 花莲市| 青海省| 阿拉善左旗| 彩票| 贵港市| 绥棱县|