<jupyter_start><jupyter_text>[Ref](https://github.com/fchollet/deep-learning-with-python-notebooks/blob/master/2.1-a-first-look-at-a-neural-network.ipynb)<jupyter_code>import keras
keras.__version__
from keras.datasets import mnist
(train_images, train_labels), (test_images, test_labels) = mnist.load_data()
print(train_images.shape)
print(train_labels)
print(test_images.shape)
print(test_labels)
from keras import models, layers
# 这些设定很关键，后续需要详细学习理解，包括使用的激活函数
network = models.Sequential()
network.add(layers.Dense(512, activation='relu', input_shape=(28 * 28,)))
network.add(layers.Dense(10, activation='softmax'))
# 编译步骤中设定的几个参数之间的联系是什么？
network.compile(optimizer='rmsprop',
                loss='categorical_crossentropy',
                metrics=['accuracy'])
train_images = train_images.reshape((60000, 28*28))
train_images = train_images.astype('float32') / 255

test_images = test_images.reshape((10000, 28*28))
test_images = test_images.astype('float32') / 255
from keras.utils import to_categorical

train_labels = to_categorical(train_labels)
test_labels = to_categorical(test_labels)
# epochs 和 batch_size 的含义是什么呢？
network.fit(train_images, train_labels, epochs=5, batch_size=128)
test_loss, test_acc = network.evaluate(test_images, test_labels)
print('test_acc:', test_acc)
28 * 28<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12895927601809956, 'fraction_numerical': 0.03544494720965309, 'mean_word_length': 7.24223602484472, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '282584', 'license': 'MIT', 'n_tokens_mistral': 546, 'n_tokens_neox': 522, 'n_words': 70, 'path': 'Python-keras/001-keras-helloworld.ipynb', 'repo_name': 'ShixiangWang/MLnotes', 'size': '1326'}