<jupyter_start><jupyter_text>6.1 下载mnist数据<jupyter_code>(X_train_image, y_train_label), \
(X_test_image, y_test_label) = mnist.load_data()
print('train data = ', len(X_train_image))
print('test data = ', len(X_test_image))<jupyter_output>train data =  60000
test data =  10000<jupyter_text>6.2 查看训练数据<jupyter_code>print('X_train_image: ', X_train_image.shape)
print('y_train_label: ', y_train_label.shape)
import matplotlib.pyplot as plt
def plot_image(image):
    fig = plt.gcf()  # 设置显示图形的大小
    fig.set_size_inches(2,2)
    plt.imshow(image, cmap = 'binary')  # 使用plt.imshow显示图形 传入28x28的图形
    plt.show()
plot_image(X_train_image[0])

print(y_train_label[0])<jupyter_output>5<jupyter_text>6.3 查看多项训练数据images与label<jupyter_code>import matplotlib.pyplot as plt
def plot_images_labels_prediction(images, labels, prediction, idx, num=10):
    fig = plt.gcf()
    fig.set_size_inches(12, 14)
    if num > 25:
        num = 25
    for i in range(0, num):
        ax = plt.subplot(5, 5, 1+i)
        ax.imshow(images[idx], cmap='binary')
        title = 'label=' + str(labels[idx])
        if len(prediction) > 0:
            title += ' , predict = ' + str(prediction[idx])
            
        ax.set_title(title, fontsize = 10)
        ax.set_xticks([]); ax.set_yticks([])
        idx += 1
    plt.show()
plot_images_labels_prediction(X_train_image, y_train_label, [], 0, 10)
print('X_test_image: ', X_test_image.shape)
print('y_test_label: ', y_test_label.shape)
plot_images_labels_prediction(X_test_image, y_test_label, [], 0, 10)<jupyter_output><empty_output><jupyter_text>6.4 多层感知器模型数据预处理  6.5 Features数据预处理<jupyter_code>print('X_train_image: ', X_train_image.shape)
print('y_train_label: ', y_train_label.shape)
X_Train = X_train_image.reshape(60000,784).astype('float32')
X_Test = X_test_image.reshape(10000, 784).astype('float32')
X_train_image[0]
# Normalize
X_Train_normalize = X_Train / 255
X_Test_normalize = X_Test / 255
X_Train_normalize[0]<jupyter_output><empty_output><jupyter_text>6.6 Label数据预处理<jupyter_code>y_train_label[0:5]
y_TrainOneHot = np_utils.to_categorical(y_train_label)
y_TestOneHot = np_utils.to_categorical(y_test_label)
y_TrainOneHot[0:5]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13330300272975432, 'fraction_numerical': 0.03958143767060965, 'mean_word_length': 5.544642857142857, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '51268', 'license': 'Apache-2.0', 'n_tokens_mistral': 982, 'n_tokens_neox': 949, 'n_words': 124, 'path': 'Chapter-6-Keras_Mnist_Introduce.ipynb', 'repo_name': 'Errrneist/TensorFlow_Meets_Keras', 'size': '2198'}