ML Basics with Keras in Tensorflow: Explore the data

0

Before training the model, it is important to explore the data to understand its format and distribution. This will help you to choose the right model architecture and hyperparameters.

The Fashion MNIST dataset contains 60,000 training images and 10,000 test images. Each image is a 28x28 pixel grayscale image of a piece of clothing. The labels for the training images are integers from 0 to 9, corresponding to the 10 different types of clothing.

The following code shows how to load the Fashion MNIST dataset into NumPy arrays:

import tensorflow as tf

(train_images, train_labels), (test_images, test_labels) = tf.keras.datasets.fashion_mnist.load_data()

The `train_images` and `train_labels` arrays are the training set, and the `test_images` and `test_labels` arrays are the test set. The images are stored in the `train_images` and `test_images` arrays as NumPy arrays of shape (60000, 28, 28). The labels are stored in the `train_labels` and `test_labels` arrays as NumPy arrays of shape (60000,).

To explore the format of the data, we can use the following code:

print(train_images.shape)

# (60000, 28, 28)


print(len(train_labels))

# 60000


print(train_labels)

# [9 0 0 ... 3 0 5]

The output of the code shows that the training set contains 60,000 images, each of which is a 28x28 pixel grayscale image. The labels are integers from 0 to 9, corresponding to the 10 different types of clothing.

We can also use the following code to visualize the first 25 images from the training set:

import matplotlib.pyplot as plt


for i in range(25):

  plt.subplot(5, 5, i + 1)

  plt.imshow(train_images[i], cmap='gray')

  plt.xticks([])

  plt.yticks([])


plt.show()

The output of the code is a figure with 25 subplots, each of which shows an image from the training set.

Tags

Post a Comment

0Comments
Post a Comment (0)