<jupyter_start><jupyter_text>Imports<jupyter_code>import numpy as np
import datetime
import tensorflow as tf
from tensorflow.keras.datasets import fashion_mnist<jupyter_output><empty_output><jupyter_text>Preprocessing  Load dataset<jupyter_code>(X_train, y_train), (X_test, y_test) = fashion_mnist.load_data()<jupyter_output>Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz
32768/29515 [=================================] - 0s 0us/step
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-images-idx3-ubyte.gz
26427392/26421880 [==============================] - 1s 0us/step
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-labels-idx1-ubyte.gz
8192/5148 [===============================================] - 0s 0us/step
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-images-idx3-ubyte.gz
4423680/4422102 [==============================] - 0s 0us/step<jupyter_text>Data normalization<jupyter_code>X_train = X_train / 255.0
X_test = X_test / 255.0<jupyter_output><empty_output><jupyter_text>Reshaping<jupyter_code>X_train = X_train.reshape(-1, 28*28)
X_train.shape
X_test = X_test.reshape(-1, 28*28)
X_test.shape<jupyter_output><empty_output><jupyter_text>Learning  Building MLP<jupyter_code>model = tf.keras.models.Sequential()
model.add(tf.keras.Input(shape=784, ))
model.add(tf.keras.layers.Dense(units=128, activation='relu'))
model.add(tf.keras.layers.Dropout(0.2))
model.add(tf.keras.layers.Dense(units=10, activation='softmax'))

model.compile(optimizer='sgd', loss='sparse_categorical_crossentropy', metrics=['sparse_categorical_accuracy'])

model.summary()<jupyter_output>Model: "sequential"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
dense (Dense)                (None, 128)               100480    
_________________________________________________________________
dropout (Dropout)            (None, 128)               0         
_________________________________________________________________
dense_1 (Dense)              (None, 10)                1290      
=================================================================
Total params: 101,770
Trainable params: 101,770
Non-trainable params: 0
_________________________________________________________________<jupyter_text>Train<jupyter_code>history = model.fit(X_train, y_train, batch_size=100, validation_split=0.1, epochs=20)<jupyter_output>Epoch 1/20
540/540 [==============================] - 2s 4ms/step - loss: 1.1182 - sparse_categorical_accuracy: 0.6424 - val_loss: 0.7459 - val_sparse_categorical_accuracy: 0.7520
Epoch 2/20
540/540 [==============================] - 2s 3ms/step - loss: 0.7460 - sparse_categorical_accuracy: 0.7494 - val_loss: 0.6289 - val_sparse_categorical_accuracy: 0.7867
Epoch 3/20
540/540 [==============================] - 2s 3ms/step - loss: 0.6515 - sparse_categorical_accuracy: 0.7811 - val_loss: 0.5768 - val_sparse_categorical_accuracy: 0.8023
Epoch 4/20
540/540 [==============================] - 2s 3ms/step - loss: 0.6035 - sparse_categorical_accuracy: 0.7978 - val_loss: 0.5412 - val_sparse_categorical_accuracy: 0.8178
Epoch 5/20
540/540 [==============================] - 2s 3ms/step - loss: 0.5700 - sparse_categorical_accuracy: 0.8078 - val_loss: 0.5166 - val_sparse_categorical_accuracy: 0.8205
Epoch 6/20
540/540 [==============================] - 2s 3ms/step - loss: 0.5456 - sparse_categorica[...]<jupyter_text>Evaluation<jupyter_code>test_loss, test_accuracy = model.evaluate(X_train, y_train, batch_size=100)
test_loss, test_accuracy = model.evaluate(X_test, y_test, batch_size=100)
import matplotlib.pyplot as plt

plt.plot(history.history['sparse_categorical_accuracy'])
plt.plot(history.history['val_sparse_categorical_accuracy'])
plt.title('model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21521739130434783, 'fraction_numerical': 0.0746376811594203, 'mean_word_length': 6.066552901023891, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '450937', 'license': 'MIT', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1348, 'n_words': 205, 'path': 'L09_regularization/code/Regularization Dropout MLP Keras.ipynb', 'repo_name': 'dalcimar/RC18EE---Intro-to-Deep-Learning', 'size': '4140'}