<jupyter_start><jupyter_text>**Deep Neural Network fashion_mnist dataset Train with two Dense layers****Import TensorFlow**<jupyter_code>import tensorflow as tf
print("You are using TensorFlow version", tf.version)
if len(tf.config.list_physical_devices('GPU')) > 0:
  print("You have a GPU enabled.")
else:
  print("Enable a GPU before running this notebook.")<jupyter_output>You are using TensorFlow version <module 'tensorflow._api.v2.version' from 'C:\\Users\\lggoo\\anaconda3\\lib\\site-packages\\tensorflow\\_api\\v2\\version\\__init__.py'>
Enable a GPU before running this notebook.<jupyter_text>**import keras**<jupyter_code># Using Keras TensorFlow API to define neural network
from tensorflow import keras
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>**import the Fashion MNIST**<jupyter_code>dataset = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = dataset.load_data()<jupyter_output>Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz
32768/29515 [=================================] - 0s 3us/step
40960/29515 [=========================================] - 0s 2us/step
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-images-idx3-ubyte.gz
26427392/26421880 [==============================] - 10s 0us/step
26435584/26421880 [==============================] - 10s 0us/step
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-labels-idx1-ubyte.gz
16384/5148 [===============================================================================================] - 0s 0s/step
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-images-idx3-ubyte.gz
4423680/4422102 [==============================] - 2s 0us/step
4431872/4422102 [==============================] - 2s 0us/step<jupyter_text>**Print the train test images**<jupyter_code>print(train_images.shape)
print(test_images.shape)<jupyter_output>(10000, 28, 28)<jupyter_text>**Print train labels**<jupyter_code>print(train_labels)
train_images = train_images / 255.0
test_images = test_images / 255.0<jupyter_output><empty_output><jupyter_text>**Plot the images**<jupyter_code>plt.figure(figsize=(10,10))
for i in range (25):
    plt.subplot(5,5,i+1)
    plt.xticks([])
    plt.yticks([])
    plt.grid(False)
    plt.imshow(train_images[i], cmap=plt.cm.binary)
    plt.xlabel(train_labels[i])
plt.show()<jupyter_output><empty_output><jupyter_text>**Create the layers**<jupyter_code>#A linear model
model = keras.Sequential([
    keras.layers.Flatten(input_shape=(28, 28)),
    keras.layers.Dense(128, activation='relu'),
    keras.layers.Dense(128, activation='relu'),
    keras.layers.Dense(10, activation='softmax')
])<jupyter_output><empty_output><jupyter_text>**Compile the model**<jupyter_code>model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'] )
EPOCHS=10
model.fit(train_images, train_labels, epochs=EPOCHS)<jupyter_output>Epoch 1/10
1875/1875 [==============================] - 4s 1ms/step - loss: 0.4852 - accuracy: 0.8255
Epoch 2/10
1875/1875 [==============================] - 2s 1ms/step - loss: 0.3588 - accuracy: 0.8681
Epoch 3/10
1875/1875 [==============================] - 2s 1ms/step - loss: 0.3263 - accuracy: 0.8796
Epoch 4/10
1875/1875 [==============================] - 3s 1ms/step - loss: 0.3052 - accuracy: 0.8871
Epoch 5/10
1875/1875 [==============================] - 2s 1ms/step - loss: 0.2883 - accuracy: 0.8923
Epoch 6/10
1875/1875 [==============================] - 2s 1ms/step - loss: 0.2717 - accuracy: 0.8975
Epoch 7/10
1875/1875 [==============================] - 2s 1ms/step - loss: 0.2587 - accuracy: 0.9025
Epoch 8/10
1875/1875 [==============================] - 2s 1ms/step - loss: 0.2476 - accuracy: 0.9062
Epoch 9/10
1875/1875 [==============================] - 2s 1ms/step - loss: 0.2370 - accuracy: 0.9106
Epoch 10/10
1875/1875 [==============================] - 2s 1ms/step - loss: 0.230[...]<jupyter_text>**Add plots to observe overfitting, create plots to observe overfittings**<jupyter_code>history = model.fit(train_images, train_labels,
                    validation_data=(test_images, test_labels),
                    epochs=EPOCHS)

acc = history.history['accuracy']
val_acc = history.history['val_accuracy']

loss = history.history['loss']
val_loss = history.history ['val_loss']

epochs_range =range(EPOCHS)

plt.figure(figsize=(8,8))
plt.subplot(1,2,1)
plt.plot(epochs_range, acc, label = 'Training Accuracy')
plt.plot(epochs_range, val_acc, label = 'Validation Accuracy')
plt.legend(loc = 'lower right')
plt.title('Training and Validation Accuracy')

plt.subplot(1, 2, 2)
plt.plot(epochs_range, loss, label = 'Training Loss')
plt.plot(epochs_range, val_loss, label = 'Validation Loss')
plt.legend(loc = 'upper right')
plt.title('Training and Validation Loss')
plt.show()
test_loss, test_acc = model.evaluate(test_images, test_labels)
print('\nTest accuracy:', test_acc)
predictions = model.predict(test_images)
print(predictions[0])
print(tf.argmax(predictions[0]))<jupyter_output>tf.Tensor(9, shape=(), dtype=int64)
{'fraction_non_alphanumeric': 0.24120795107033638, 'fraction_numerical': 0.07549694189602446, 'mean_word_length': 5.876478318002628, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 34, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '430209', 'license': 'MIT', 'n_tokens_mistral': 2088, 'n_tokens_neox': 1771, 'n_words': 331, 'path': 'fashionMNISTds2DenseLayers.ipynb', 'repo_name': 'LouMaine/Machine-Learning-Deep-Neural-TwoDenseLayers', 'size': '5232'}