<jupyter_start><jupyter_text>Import Libraries<jupyter_code>import tensorflow as tf
from tensorflow import keras
tf.__version__
keras.__version__<jupyter_output><empty_output><jupyter_text>Load Dataset<jupyter_code>fashion_mnist = keras.datasets.fashion_mnist
(X_train_full, y_train_full), (X_test, y_test) = fashion_mnist.load_data()
X_train_full.shape
X_train_full.dtype
X_valid, X_train = X_train_full[:5000] / 255.0, X_train_full[5000:] / 255.0
y_valid, y_train = y_train_full[:5000], y_train_full[5000:]
class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat', 'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']
class_names
class_names[y_train[0]]<jupyter_output><empty_output><jupyter_text>Creating Model Using the Sequential API<jupyter_code>#model = keras.models.Sequential()
#model.add(keras.layers.Flatten(input_shape=[28, 28]))
#model.add(keras.layers.Dense(300, activation='relu'))
#model.add(keras.layers.Dense(100, activation='relu'))
#model.add(keras.layers.Dense(10, activation='softmax'))<jupyter_output><empty_output><jupyter_text>We can also pass a list of layers when creating Sequential model instead of adding the layers one by one.<jupyter_code>model = keras.models.Sequential([keras.layers.Flatten(input_shape=[28, 28]),
                                 keras.layers.Dense(300, activation='relu'),
                                 keras.layers.Dense(100, activation='relu'),
                                 keras.layers.Dense(10, activation='softmax') 
                                ])
model.summary()
model.layers
hidden1 = model.layers[1]
hidden1.name
model.get_layer('dense') is hidden1
weights, biases = hidden1.get_weights()
weights
weights.shape
biases
biases.shape<jupyter_output><empty_output><jupyter_text>Compiling the model<jupyter_code>model.compile(loss='sparse_categorical_crossentropy', optimizer='sgd', metrics=['accuracy'])<jupyter_output><empty_output><jupyter_text>Training And Evaluating the model<jupyter_code>history = model.fit(X_train, y_train, epochs=30, validation_data = (X_valid, y_valid))
import pandas as pd
import matplotlib.pyplot as plt


pd.DataFrame(history.history).plot(figsize=(8, 5))
plt.grid(True)
plt.gca().set_ylim(0, 1)
plt.show()
model.evaluate(X_test, y_test)<jupyter_output>10000/1 [==============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================[...]<jupyter_text>Using the model to make predictions<jupyter_code>X_new = X_test[:3]
y_proba = model.predict(X_new)
y_proba.round(2)
y_pred = model.predict_classes(X_new)
y_pred
import numpy as np
np.array(class_names)[y_pred]
y_new = y_test[:3]
y_new
np.array(class_names)[y_new]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.3739495798319328, 'fraction_numerical': 0.019327731092436976, 'mean_word_length': 8.651351351351352, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '442976', 'license': 'MIT', 'n_tokens_mistral': 1059, 'n_tokens_neox': 954, 'n_words': 152, 'path': 'SimpleImageClassifier.ipynb', 'repo_name': 'aaryangold/Deep-Learning-Models', 'size': '3570'}