ML Basics with Keras in Tensorflow: Download and explore the dataset

0

In this article, we will learn how to download and explore a dataset using Keras in Tensorflow. Keras is a high-level API for building neural networks, and Tensorflow is a powerful open-source software library for numerical computation using data flow graphs.

Downloading the dataset

The first step is to download the dataset. We can do this using the `tf.keras.datasets` module. The `mnist` dataset is a popular dataset for image classification, and it contains 70,000 images of handwritten digits.

from tensorflow.keras.datasets import mnist


(x_train, y_train), (x_test, y_test) = mnist.load_data()

The `x_train` and `y_train` variables contain the training data, and the `x_test` and `y_test` variables contain the test data. The training data contains 60,000 images, and the test data contains 10,000 images.

Exploring the dataset

Now that we have downloaded the dataset, we can explore it. The `x_train` and `x_test` variables are NumPy arrays, and each element in the array is a 28x28 image. The `y_train` and `y_test` variables are NumPy arrays, and each element in the array is a label, which is a number from 0 to 9.

We can use the `matplotlib` library to visualize the images in the dataset.

import matplotlib.pyplot as plt


for i in range(10):

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

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

  plt.title(y_train[i])

  plt.show()

This code will create a figure with 10 subplots. Each subplot will show an image from the training dataset, and the label for the image will be displayed in the title.

Tags

Post a Comment

0Comments
Post a Comment (0)