<jupyter_start><jupyter_text>데이터 로드<jupyter_code>import warnings
warnings.filterwarnings('ignore')
from keras.datasets import mnist
from keras.utils import to_categorical
(train_images, train_labels), (test_images, test_labels) = mnist.load_data()
train_images = train_images.reshape((60000, 784))
test_images = test_images.reshape((10000, 784))
train_images = train_images.astype('float32') / 255
test_images = test_images.astype('float32') / 255
train_labels = to_categorical(train_labels)
test_labels = to_categorical(test_labels)<jupyter_output><empty_output><jupyter_text>네트워크 모델 설계<jupyter_code>from keras import models
from keras import layers
# model = models.Sequential()
# model.add(layers.Dense(512, activation='relu', input_shape=(28 * 28,)))
# model.add(layers.Dense(10, activation='softmax'))
from keras.layers.advanced_activations import LeakyReLU
activation = LeakyReLU(alpha=.001)
model.add(layers.Dense(512, activation=activation, input_shape=(28 * 28,)))
model.add(layers.Dense(10, activation='softmax'))<jupyter_output><empty_output><jupyter_text>RMSProp Optimizer<jupyter_code># from keras.optimizers import RMSprop
# optimizer = RMSprop(lr=0.001)<jupyter_output><empty_output><jupyter_text>Adam Optimizer<jupyter_code>from keras.optimizers import Adam
optimizer = Adam(lr=0.01)
model.compile(optimizer=optimizer,
              loss='categorical_crossentropy',
              metrics=['accuracy'])
#None값은 우리가 batch size를 안정해줘서None 뜨는것.
model.summary()<jupyter_output>Model: "sequential_1"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
dense_3 (Dense)              (None, 512)               401920    
_________________________________________________________________
dense_4 (Dense)              (None, 10)                5130      
_________________________________________________________________
dense_5 (Dense)              (None, 512)               5632      
_________________________________________________________________
dense_6 (Dense)              (None, 512)               262656    
_________________________________________________________________
dense_7 (Dense)              (None, 10)                5130      
=================================================================
Total params: 680,468
Trainable params: 680,468
Non-trainable params: 0
________________________________________________[...]<jupyter_text>모델 훈련(training)<jupyter_code>model.fit(train_images, train_labels, epochs=5, batch_size=64)<jupyter_output>Epoch 1/5
938/938 [==============================] - 11s 11ms/step - loss: 0.9329 - accuracy: 0.6179
Epoch 2/5
938/938 [==============================] - 10s 11ms/step - loss: 0.2793 - accuracy: 0.9327
Epoch 3/5
938/938 [==============================] - 10s 11ms/step - loss: 0.2427 - accuracy: 0.9454
Epoch 4/5
938/938 [==============================] - 10s 11ms/step - loss: 0.2130 - accuracy: 0.9529
Epoch 5/5
938/938 [==============================] - 11s 11ms/step - loss: 0.2278 - accuracy: 0.9505<jupyter_text>모델 평가<jupyter_code>test_loss, test_acc = model.evaluate(test_images, test_labels)
print('test_acc:', test_acc)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18306845965770172, 'fraction_numerical': 0.06815403422982885, 'mean_word_length': 5.222433460076045, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '619374', 'license': 'Apache-2.0', 'n_tokens_mistral': 1177, 'n_tokens_neox': 1021, 'n_words': 180, 'path': 'ai/9_optimizer.ipynb', 'repo_name': 'risker93/king', 'size': '3272'}