<jupyter_start><jupyter_text><jupyter_code>% tensorflow_version 2.x #needed in the notebook
import tensorflow as tf
from tensorflow import keras
import numpy as np
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>fashion Mnist DataSet<jupyter_code>fashion_mnist = keras.datasets.fashion_mnist
(train_images,train_labels),(test_images,test_labels) = fashion_mnist.load_data()
train_images.shape
type(train_images)<jupyter_output><empty_output><jupyter_text>60,000 images each 28 by 28 pixels meaning (784px) in total for a single image  Take a look at image of index 0 and grab one of its pixel Pixels are arranged in rows and columns 28 rows and 28 columns<jupyter_code>train_images[0,23,23]<jupyter_output><empty_output><jupyter_text>The entire Train Dataset<jupyter_code>print(train_images)
train_labels[:10]
class_names =[
              'T-shirt/top',
              'Trouser',
              'Pullover',
              'Dress',
              'Coat',
              'Sandal',
              'Shirt',
              'Sneaker',
              'Bag',
              'Ankle boot'
]
def showImage(imageIndex):
    plt.figure()
    plt.imshow(train_images[imageIndex])
    plt.colorbar()
    #plt.grid(False)
    plt.show()


showImage(100)
 showImage(6)<jupyter_output><empty_output><jupyter_text>Data preprocessing  scale down the grayscale values (0-255)  to the values between (0-1)<jupyter_code>train_images = train_images/255.0
test_images = test_images/255.0<jupyter_output><empty_output><jupyter_text>Defining Model  Architecture* layers * number  of neurons,* connections,activation functions for ( hidden and Output)layers<jupyter_code>model = keras.Sequential([
                          keras.layers.Flatten(input_shape=(28,28)),
                          keras.layers.Dense(128,activation='relu'),
                          keras.layers.Dense(10,activation='softmax')
])<jupyter_output><empty_output><jupyter_text>Compile Model Defining other parameters* optimizer* loss function* metrics for measuring the performance<jupyter_code>model.compile(
    optimizer='adam',
    loss='sparse_categorical_crossentropy',
    metrics=['accuracy']
)<jupyter_output><empty_output><jupyter_text>Actual Training<jupyter_code>model.fit(train_images,train_labels,epochs=10) # epochs is also a hyperParameter<jupyter_output>Epoch 1/10
1875/1875 [==============================] - 3s 2ms/step - loss: 0.5010 - accuracy: 0.8255
Epoch 2/10
1875/1875 [==============================] - 3s 2ms/step - loss: 0.3754 - accuracy: 0.8652
Epoch 3/10
1875/1875 [==============================] - 4s 2ms/step - loss: 0.3365 - accuracy: 0.8783
Epoch 4/10
1875/1875 [==============================] - 3s 2ms/step - loss: 0.3135 - accuracy: 0.8853
Epoch 5/10
1875/1875 [==============================] - 3s 2ms/step - loss: 0.2955 - accuracy: 0.8915
Epoch 6/10
1875/1875 [==============================] - 3s 2ms/step - loss: 0.2810 - accuracy: 0.8970
Epoch 7/10
1875/1875 [==============================] - 3s 2ms/step - loss: 0.2685 - accuracy: 0.9008
Epoch 8/10
1875/1875 [==============================] - 3s 2ms/step - loss: 0.2564 - accuracy: 0.9042
Epoch 9/10
1875/1875 [==============================] - 3s 2ms/step - loss: 0.2477 - accuracy: 0.9072
Epoch 10/10
1875/1875 [==============================] - 3s 2ms/step - loss: 0.239[...]<jupyter_text>Prediction--- Always comes BEFORE ACCUCACY TESTING<jupyter_code>print(test_images.shape) # 10,000 images each of 28 by 28 px
predictions = model.predict(test_images)

print(predictions)
# Get first prediction(at index 0)
predictions[0]<jupyter_output><empty_output><jupyter_text>Returns A list of probability distribution Probability / likelyhood of the (input) being * a:              'T-shirt/top',              'Trouser',              'Pullover',              'Dress',              'Coat',              'Sandal',              'Shirt',              'Sneaker',              'Bag',              'Ankle boot'  * info from all the 10 output neurons* Probability is spread around those neurons such that they sum up to 1 --- Gett the INDEX of the  highest  Probability * using **np.argmax()** function---<jupyter_code>print(predictions[0])
print(np.argmax(predictions[0]))<jupyter_output>9<jupyter_text>Use retuned Index to Grab its class name<jupyter_code>def ShowPredictedImage(predictionIndex):
    predictions = model.predict(test_images)
    prediction= predictions[predictionIndex] # gets a (single prediction)) from Predictions array
    print(prediction)
    print('------------------')
    predicted_class_index = np.argmax(prediction) # returns the (index) for the Predicted Class
    print(predicted_class_index)
    print('------------------')

    print(class_names[predicted_class_index]) # Gets the (Actual Class Name using the index)
    print('------------------')
    classIndex = predictionIndex
    plt.figure()
    plt.imshow(test_images[classIndex])
    plt.colorbar()
    #plt.grid(False)
    plt.show()<jupyter_output><empty_output><jupyter_text>Pick any index between (0-9)<jupyter_code>ShowPredictedImage(20)<jupyter_output>[2.4635815e-03 1.8051246e-04 9.6571988e-01 3.9753851e-07 3.0782863e-02
 1.2575573e-09 7.2532461e-04 4.9592520e-05 7.7952456e-05 7.2970070e-09]
------------------
2
------------------
Pullover
------------------<jupyter_text>Model Testing and Evaluation<jupyter_code>test_loss , test_acc = model.evaluate(test_images,test_labels,verbose=1)
print('test Accuracy of :' ,test_acc)<jupyter_output>313/313 [==============================] - 0s 1ms/step - loss: 0.3369 - accuracy: 0.8863
test Accuracy of : 0.8863000273704529<jupyter_text>88% Testing Accuracy<jupyter_code><jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18164268164268163, 'fraction_numerical': 0.07704457704457704, 'mean_word_length': 3.7690376569037656, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, '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': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '253137', 'license': 'Apache-2.0', 'n_tokens_mistral': 2181, 'n_tokens_neox': 1860, 'n_words': 398, 'path': 'Neural_Network_Tensorflow.ipynb', 'repo_name': 'BrightonOtieno/Fashion-mnist-Tensorflow-NNets', 'size': '5698'}