<jupyter_start><jupyter_text>Checking the data<jupyter_code>train_data.shape
train_labels[:10]
train_labels.shape
label_index = [         "T-shirt/top",     # index 0
                        "Trouser",         # index 1
                        "Pullover",        # index 2 
                        "Dress",           # index 3 
                        "Coat",            # index 4
                        "Sandal",          # index 5
                        "Shirt",           # index 6 
                        "Sneaker",         # index 7 
                        "Bag",             # index 8 
                        "Ankle boot"]      #index 9]  
import matplotlib.pyplot as plt
%matplotlib inline

fig = plt.figure()
for i in range(9):
  plt.subplot(3,3,i+1)
  plt.tight_layout()
  plt.imshow(train_data[i], interpolation='none')
  plt.title("Label: {}".format(label_index[train_labels[i]]))
  plt.xticks([])
  plt.yticks([])
plt.savefig('Labels example')<jupyter_output><empty_output><jupyter_text>Preparing the data for processing<jupyter_code>x_train = train_data.reshape(train_data.shape[0],28,28,1) # reshaping the data to create a third dimension for colour
x_test = test_data.reshape(test_data.shape[0],28,28,1)
y_train =keras.utils.to_categorical(train_labels, 10) #one hot encoding label data
y_test =keras.utils.to_categorical(test_labels, 10)
import numpy as np
x_train = x_train.astype('float32')/np.max(train_data) #normalizing data
x_test = x_test.astype('float32')/np.max(train_data)
from keras import models,layers
model = models.Sequential()
model.add(layers.Conv2D(32,(3,3),activation='relu',input_shape=(28,28,1)))
model.add(layers.Dropout(0.2))
model.add(layers.MaxPooling2D((2,2)))
model.add(layers.Conv2D(64,(3,3),activation='relu'))
model.add(layers.Dropout(0.3))
model.add(layers.MaxPooling2D((2,2)))
model.add(layers.Conv2D(64,(3,3),activation='relu'))

model.add(layers.Flatten())
model.add(layers.Dense(128,activation='relu'))
model.add(layers.Dense(10,activation='softmax'))
model.summary()
model.compile(optimizer='rmsprop',
              metrics= ['accuracy'] ,
              loss = 'categorical_crossentropy' )
history = model.fit(x_train,y_train,
                     epochs=10, 
                    batch_size = 512,
                   validation_data=(x_test,y_test),
                   verbose=0)
val_loss = history.history['val_loss']
train_loss = history.history['loss']
epochs = np.arange(1,11)
plt.plot(epochs,val_loss,'r',label='Validation loss')
plt.plot(epochs,train_loss,'bo',label='Training loss')
plt.xlabel('Epochs')
plt.ylabel('Loss')
plt.legend()
val_acc = history.history['val_accuracy']
train_acc = history.history['accuracy']
epochs = np.arange(1,11)
plt.plot(epochs,val_acc,'m',label='Validation accuracy')
plt.plot(epochs,train_acc,'cD',label='Training accuracy')
plt.xlabel('Epochs')
plt.ylabel('Accuracy')
plt.legend()
plt.savefig('Accuracy graph')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14805990469707284, 'fraction_numerical': 0.02825051055139551, 'mean_word_length': 3.2532561505065125, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '498848', 'license': 'MIT', 'n_tokens_mistral': 1076, 'n_tokens_neox': 1001, 'n_words': 154, 'path': 'CNNs on Fashion mnist.ipynb', 'repo_name': 'Shafiq-Kyazze/Simple-Image-Classification-using-Neural-Networks', 'size': '2938'}