MNIST Dataset in Python - Basic Importing and Plotting

MNIST Dataset in Python - Basic Importing and Plotting

Welcome to this tutorial on the MNIST dataset. In this tutorial, we will learn what is the MNIST dataset, how to import it in Python, and how to plot it using matplotlib.

Welcome to this tutorial on the MNIST dataset. In this tutorial, we will learn what is the MNIST dataset, how to import it in Python, and how to plot it using matplotlib.

What is the MNIST dataset?

MNIST set is a large collection of *handwritten digits. *It is a very popular dataset in the field of image processing. It is often used for benchmarking machine learning algorithms.

_MNIST _is short forModified National Institute of Standards and Technology database.

MNIST contains a collection of 70,000, 28 x 28 **images of handwritten digits from 0 to 9.**

The dataset is already divided into training and testing sets. We will see this later in the tutorial.

For more information on MNIST, refer to its Wikipedia page. We are going to import the dataset from Keras.

Let’s start with loading the dataset into our python notebook.

Loading MNIST from Keras

We will first have to import the MNIST dataset from the Keras module.

We can do that using the following line of code:

from keras.datasets import mnist

Now we will load the training and testing sets into separate variables.

(train_X, train_y), (test_X, test_y) = mnist.load_data()

Let’s find out how many images are there in the training and testing sets. In other words, let’s try and find out the split ratio of the this dataset.

To learn more about split ratio, refer to this tutorial on how to slit data into training and testing sets.

To find the split ratio we are going to print the shapes of all the vectors.

print``(``'X_train: ' + str``(train_X.shape))

print``(``'Y_train: ' + str``(train_y.shape))

print``(``'X_test:  '  + str``(test_X.shape))

print``(``'Y_test:  '  + str``(test_y.shape))

Output:

X_train: (``60000``, 28``, 28``)

Y_train: (``60000``,)

X_test:  (``10000``, 28``, 28``)

Y_test:  (``10000``,)

We can see that there are 60k images in the training set and 10k images in the testing set.

The dimension of our training vector is (60000, 28, 28), this is because there are** 60,000 grayscale images with the dimension **28X28.

python advanced machine-learning

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Learn Python Tutorial from Basic to Advance

Basic programming concept in any language will help but not require to attend this tutorial

Hire Machine Learning Developers in India

We supply you with world class machine learning experts / ML Developers with years of domain experience who can add more value to your business.

Applications of machine learning in different industry domains

We supply you with world class machine learning experts / ML Developers with years of domain experience who can add more value to your business.

Hire Machine Learning Developer | Hire ML Experts in India

We supply you with world class machine learning experts / ML Developers with years of domain experience who can add more value to your business.

How To Plot A Decision Boundary For Machine Learning Algorithms in Python

How To Plot A Decision Boundary For Machine Learning Algorithms in Python, you will discover how to plot a decision surface for a classification machine learning algorithm.