<jupyter_start><jupyter_text>Fashion Mnist<jupyter_code>import tensorflow as tf
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np<jupyter_output><empty_output><jupyter_text>Improt TensorFlow Library, pandas and matplotlib<jupyter_code>fashion_mnist = tf.keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
print(len(train_images), len(test_images))
train_images = train_images/255
test_images = test_images/255<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 [==============================] - 0s 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
60000 10000<jupyter_text>Import fashion mnist data and seperate it into training and testing datsetsdividing each pixel by 255 since it's gray sacle and diving it by 255 means reducing the size to the range of 0-1<jupyter_code>model = tf.keras.models.Sequential([
  tf.keras.layers.Flatten(),
  tf.keras.layers.Dense(300, activation='relu'),
  tf.keras.layers.Dense(100, activation='relu'),
  tf.keras.layers.Dense(10, activation='softmax')
])

model.compile(loss=tf.keras.losses.sparse_categorical_crossentropy, optimizer='sgd', metrics='accuracy')<jupyter_output><empty_output><jupyter_text>Create layers for the model and compiling it<jupyter_code>history = model.fit(train_images, train_labels, epochs=30, validation_data=(test_images,test_labels))<jupyter_output>Epoch 1/30
1875/1875 [==============================] - 4s 2ms/step - loss: 0.6942 - accuracy: 0.7702 - val_loss: 0.5513 - val_accuracy: 0.8075
Epoch 2/30
1875/1875 [==============================] - 4s 2ms/step - loss: 0.4797 - accuracy: 0.8318 - val_loss: 0.4768 - val_accuracy: 0.8337
Epoch 3/30
1875/1875 [==============================] - 4s 2ms/step - loss: 0.4349 - accuracy: 0.8464 - val_loss: 0.4667 - val_accuracy: 0.8391
Epoch 4/30
1875/1875 [==============================] - 3s 2ms/step - loss: 0.4067 - accuracy: 0.8579 - val_loss: 0.4397 - val_accuracy: 0.8438
Epoch 5/30
1875/1875 [==============================] - 4s 2ms/step - loss: 0.3880 - accuracy: 0.8639 - val_loss: 0.4233 - val_accuracy: 0.8479
Epoch 6/30
1875/1875 [==============================] - 3s 2ms/step - loss: 0.3724 - accuracy: 0.8680 - val_loss: 0.4110 - val_accuracy: 0.8539
Epoch 7/30
1875/1875 [==============================] - 3s 2ms/step - loss: 0.3601 - accuracy: 0.8720 - val_loss: 0.3936 - val_accuracy:[...]<jupyter_text>Training the Model with validation data<jupyter_code>pd.DataFrame(history.history).plot(figsize=(8,5))
plt.grid(True)
plt.gca().set_ylim(0, 1)
plt.show()

model.evaluate(test_images, test_labels)<jupyter_output><empty_output><jupyter_text>Plotting The data with loss, accuracy, val_loss and val_accuracy<jupyter_code>class_names = ["T-shirt/top", "Trouser", "Pullover", "Dress", "Coat", "Sandal", "Shirt",
               "Sneaker", "Bag", "Ankle boot"]
testing = test_images[:3]
prediction = model.predict_classes(testing)
prediction.round(2)
np.array(class_names)[prediction]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21722222222222223, 'fraction_numerical': 0.09166666666666666, 'mean_word_length': 5.938342967244702, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '603009', 'license': 'Apache-2.0', 'n_tokens_mistral': 1508, 'n_tokens_neox': 1264, 'n_words': 243, 'path': 'Hands-on-ML/Code/Chapter 10/fashion_mnist.ipynb', 'repo_name': 'Ace5584/Machine-Learning-Notes', 'size': '3600'}