Getting ready

We'll use Google Colab to train our models. Google Colab comes with TensorFlow installed, so we don't have to install it separately in our system.

We import the required libraries as follows:

import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

import tensorflow as tf
from tensorflow import keras
from sklearn.utils import resample
from sklearn.metrics import accuracy_score
from sklearn.metrics import confusion_matrix
from sklearn.metrics import classification_report
from scipy import stats

We load our data from the datasets that come with tf.keras:

# Load the fashion-mnist pre-shuffled train data and test data
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.fashion_mnist.load_data()

We check the dimensions of the train and test subsets:

# Print training set shape 
print("x_train shape:", x_train.shape, "y_train shape:", y_train.shape)

This gives us the following output:

We take note of the unique values in the target variable: 

np.unique(y_train)

We can see that there are 10 classes labelled from 0 to 9:

We can take a quick glimpse at the first few observations as follows:

fig=plt.figure(figsize=(16,8))

# number of columns for images in plot
columns=5

# number of rows for images in plot
rows=3

for i in range (1,columns*rows+1):
fig.add_subplot(rows,columns,i)
plt.title("Actual Class: {}".
format((y_train[i])),color='r',fontsize=16)
plt.imshow(x_train[i])
plt.show()

With the preceding code, we plot the first 15 images, along with the associated labels:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset