<jupyter_start><jupyter_text>https://www.youtube.com/watch?v=wu9IH1Xvdd4 The ‘Fashion-MNIST’ data set contains 60K gray-scaled images of labeled fashion categories from Zalando articles. It is also used to benchmark machine learning algorithms for image classification.https://www.kaggle.com/zalando-research/fashionmnist/notebooks<jupyter_code>import tensorflow as tf
from tensorflow import keras
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
data = keras.datasets.fashion_mnist
# loading and looking at data
(train_images, train_labels), (test_images, test_labels) = data.load_data()
print(train_labels.shape)
print(test_labels.shape)
# initialize the label names
class_names = ["top", "trouser", "pullover", "dress", "coat",
	"sandal", "shirt", "sneaker", "bag", "ankle boot"]
# explore data
plt.imshow(train_images[7], cmap=plt.cm.binary) #BN 28x28
print(train_images[7])
# shrink data down within 0 and 1
train_images = train_images/255.0
test_images = test_images/255.0
print(train_images[7])
# flattening the data -> remove 28 interior arrays representing rows of pixels
# so we get a list of 28*28 = 784 values that will be the input of NN
# 784 input neurons
# output will be composed by 10 neurons representing all the 0-9 different labels
# hidden layer suggested is about 20% of the input size
model = keras.Sequential([
    keras.layers.Flatten(input_shape=(28,28)),
    keras.layers.Dense(128, activation='relu'),
    keras.layers.Dense(10, activation='softmax')                       
])
# softmax will pick values for each neuron and sum up to 1
# activated output neuron will be the one with the higher probability
model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics = ['accuracy'])
model.fit(train_images, train_labels,
          epochs = 5) # NN will see the same images 5 times
test_loss, test_acc = model.evaluate(test_images, test_labels)
print(f'Tested Accuracy: {test_acc}, Test Loss: {test_loss}')
model.fit(train_images, train_labels,
          epochs = 10)
test_loss, test_acc = model.evaluate(test_images, test_labels)
print(f'Tested Accuracy: {test_acc}, Test Loss: {test_loss}')
preds = model.predict(test_images)
print(preds)
# we get as output a list of 10 different values for each image tested
print(preds[0])
print(class_names[np.argmax(preds[0])])
# show the preds
for i in range(5):
    plt.grid(False)
    plt.imshow(test_images[i], cmap=plt.cm.binary)
    plt.xlabel('Actual: '+ str(class_names[test_labels[i]]))
    plt.title('Prediction: ' + class_names[np.argmax(preds[i])])
    plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10900832702498107, 'fraction_numerical': 0.022331566994700985, 'mean_word_length': 4.966139954853273, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '564772', 'license': 'MIT', 'n_tokens_mistral': 910, 'n_tokens_neox': 848, 'n_words': 253, 'path': 'FashionMNIST.ipynb', 'repo_name': 'giuliaciardi/TensorFlow', 'size': '2642'}