<jupyter_start><jupyter_text><jupyter_code>from tensorflow.keras.datasets.mnist import load_data
(x_train, y_train), (x_test, y_test) = load_data(path='mnist.npz')
x_train.shape, y_train.shape,  x_test.shape, y_test.shape, 
 y_train[4], x_train[4]
import matplotlib.pyplot as plt
plt.imshow(x_train[50000])
print(y_train[50000]), type(y_train[50000])
x_train = x_train.reshape(-1, 28*28)
x_train.shape
x_test = x_test.reshape(-1, 28*28)
x_test.shape
y_train[2:10], y_train.shape
import numpy as np
np.unique(y_train)<jupyter_output><empty_output><jupyter_text>apply model<jupyter_code>import tensorflow as tf
model = tf.keras.models.Sequential()

model.add(tf.keras.Input(shape=(784, ))) # input layer
model.add(tf.keras.layers.Dense(64, activation='relu')) # hidden layer
model.add(tf.keras.layers.Dense(64, activation='relu')) # hidden layer
# 3이상 softmax, binary -> sigmoid
model.add(tf.keras.layers.Dense(10, activation='softmax')) # hidden layer

# regression -> loss : mse
# binary classification -> loss : binary crossentropy
# over 3 classification -> loss : categorical crossentropy(sparse_categorical_crossentropy)

model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['acc'])
hist = model.fit(x_train, y_train, epochs=100, validation_split=0.3)<jupyter_output>Epoch 1/100
1313/1313 [==============================] - 3s 2ms/step - loss: 2.2708 - acc: 0.7812 - val_loss: 0.5673 - val_acc: 0.8536
Epoch 2/100
1313/1313 [==============================] - 3s 2ms/step - loss: 0.4569 - acc: 0.8872 - val_loss: 0.5196 - val_acc: 0.8731
Epoch 3/100
1313/1313 [==============================] - 3s 2ms/step - loss: 0.3799 - acc: 0.9041 - val_loss: 0.3895 - val_acc: 0.9213
Epoch 4/100
1313/1313 [==============================] - 3s 2ms/step - loss: 0.3389 - acc: 0.9182 - val_loss: 0.3558 - val_acc: 0.9142
Epoch 5/100
1313/1313 [==============================] - 3s 2ms/step - loss: 0.2881 - acc: 0.9286 - val_loss: 0.3294 - val_acc: 0.9268
Epoch 6/100
1313/1313 [==============================] - 3s 2ms/step - loss: 0.2780 - acc: 0.9325 - val_loss: 0.3385 - val_acc: 0.9242
Epoch 7/100
1313/1313 [==============================] - 3s 2ms/step - loss: 0.2494 - acc: 0.9392 - val_loss: 0.2845 - val_acc: 0.9327
Epoch 8/100
1313/1313 [==============================] [...]<jupyter_text>evaluation<jupyter_code>hist.history.keys()
import matplotlib.pyplot as plt
plt.plot(hist.history['loss'])
plt.plot(hist.history['val_loss'], 'b-')
plt.show()
plt.plot(hist.history['acc'])
plt.plot(hist.history['val_acc'], 'r-')
plt.show()<jupyter_output><empty_output><jupyter_text>service<jupyter_code>y_test[30]
model.predict(x_test[30,:])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.23680297397769517, 'fraction_numerical': 0.11152416356877323, 'mean_word_length': 5.579462102689487, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 20, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '587658', 'license': 'Apache-2.0', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1047, 'n_words': 191, 'path': 'mnist_classification_advanced.ipynb', 'repo_name': 'creamcheesesteak/test_deeplearning', 'size': '2690'}