Machine Learning in R: Neural Network Using Keras on MNIST Dataset

In this project, you will learn how to create and train a Neural Networks to build a classifier that can recognise and classify images of hand-written digits in one of the 10 classes (for digits 0 to 9) from the very popular MNIST dataset! This is the same underlying technology used in modern Object Recognition applications including Face Recognition and Identification.

Join for $4.99
Machine Learning in R: Neural Network Using Keras on MNIST Dataset

Duration (mins)


5.0 / 5


Task List

We will cover the following tasks in 31 minutes:


In this introductory task, we will discuss Neural Networks. I’ll give you a quick history of Machine Learning. I’ll introduce you to the Rhyme Interface, and finally share a little bit about myself.


In this task, we will start by looking at a visual representation of a Tensor. A Tensor is a lot like a multi-dimensional array. We will then move on to create 60,000 Tensors, each with a shape corresponding to our image size in order to create our dataset. We will do this by using the array_reshape function in Keras.

One Hot Encoding

ML algorithms generally need categorical data in what are called “One Hot” encodings. In this encoding, numeric class representations are converted to label vectors whose dimension correspond to the total number of classes given in the dataset. In this task, I will show you how to encode our labels in such a way with a simple function.

Building the Model

In this task we are going to build the architecture for the model. We will be using ReLU (Rectified Linear Unit) activation function, which is one of the most used activation functions right now in Deep Learning, on our hidden layers. We will use the Softmax function as the final layer activations of our neural network-based classifier, which is also very popular when it comes to classifiers. Let’s see how this is done!

Loss Optimizer and Model Run

We need to use a loss optimizer so we can spot when the model starts over-fitting to the training data. We will be using a categorical cross-entropy loss function as our loss function - this is representative of the mistakes the model makes in predicting labels over the training data. Cross-entropy loss increases as the predicted probability diverges from the actual label. As the model trains, an optimization algorithm will gradually adjust values of the model’s internal parameters to try and decrease this loss value, thereby making better predictions.

Test Data and Summary

In this task we will see how the model performs on data it hasn’t seen or hasn’t been trained on. After we test the model, I will run through everything we have learned in this project and we can get on with our next project.

Watch Preview

Preview the instructions that you will follow along in a hands-on session in your browser.

Chris Shockley

About the Host (Chris Shockley)

I am an R enthusiast, hiker, and amateur astronomer. My favorite hike is located in Mt. Rainier National Park, my favorite Deep Sky Object is Alberio, and my favorite R package is dplyr (since I use it everyday). I have a dog named Coog (Lllasa Apso), and I love talking about Coog (as you'll find out soon). I work as a Data Analyst/Financial Analyst for a Metals Co. located in Seattle, WA. I have been in my current position for 4 years. I work primarily in R for Analytics and R Shiny for Deployment. I have built numerous apps over the past few years. My hope is that I can help you in learning R. Yes, the Rhyme Interface will help you. But. You also must take what you learn and practice, practice, practice. So... Let's get after it. See you soon.

Frequently Asked Questions

In Rhyme, all projects are completely hands-on. You don't just passively watch someone else. You use the software directly while following the host's (Chris Shockley) instructions. Using the software is the only way to achieve mastery. With the "Live Guide" option, you can ask for help and get immediate response.
Nothing! Just join through your web browser. Your host (Chris Shockley) has already installed all required software and configured all data.
You can go to, sign up for free, and follow this visual guide How to use Rhyme to create your own sessions. If you have custom needs or company-specific environment, please email us at
Absolutely. We offer Rhyme for workgroups as well larger departments and companies. Universities, academies, and bootcamps can also buy Rhyme for their settings. You can select sessions and trainings that are mission critical for you and, as well, author your own that reflect your own needs and tech environments. Please email us at
Please email us at and we'll respond to you within one business day.

Ready to join this 31 minutes session?