# Machine Learning in R: Airplanes vs Automobiles Building a Neural Network Using Your Own Images

In this project, I am going to teach you how to build your own Neural Network from scratch and training it on your own dataset. I am going to use 12 random images from the internet as my dataset: Six of the images are cars and six are airplanes (downloaded randomly). Since the images are of different sizes, I will show you how to pre-process them (which is a key learning from this project) and get them ready for the Neural Network. We will then split the images into a training and test set and train the Neural Network to perform this classification task.

Duration (mins)

Learners

#### 5.0 / 5

Rating

We will cover the following tasks in 44 minutes:

### Introduction

In this task I am going to show you what we’re going to do in this tutorial. I will show you the random images we’re going to use as our dataset, I’ll explain how the Rhyme Interface works and finish telling you a little bit about me.

In this short task, we are going to have to do a little grunt work by creating a vector of names. This will help us in the following tasks by allowing us to pull in the images into R using a simple `for` loop.

### Images

I will show you how to upload the images into R using EBImage using a `for` loop. If you haven’t used a `for` loop before, no worries - I will explain what it is the loop is doing while we go through it. If you want to learn more about it don’t stop the video. Wait until after and do a google search - you can learn the for loop in 30 minutes.

### Resizing

The images that I pulled down from the Internet are all images of different sizes. However, our Neural Network model will expect training examples of the same exact shape. Therefore, we will need to resize the images so that they are all of the same shape. We will use a resize function in EBImage to complete this.

### Reshaping Data for Neural Network

From this task onwards, we will be performing a basic Neural Network protocol. In this lesson we will be using the array_reshape function which allows us to reshape a multi dimensional array that will allow us to input the data into the Neural Network.

### Creating Training Set

As you are probably aware when doing a Machine Learning problem or in this case a Neural Network we need to create the model using a training set. We then test our model on a testing set to see how well it performs. In our case we only have 12 images so we need to figure out how we’re going to set this up. Come on in and we’ll work through this.

### Creating Test Set

In this task, we will be build out the test set. Again, since we’re only dealing with 12 images we will only have one image of an airplane and one image of a car in our test set. This will work, but is not ideal. Generally, you will want a much bigger training and test set. The purpose of this project is to show you how to create and train a Neural Networks from scratch using a custom dataset and not one of the pre-processed datasets which come packaged with deep learning libraries.

### Creating Labels and One Hot Encoding

We need to set up our labels in this chapter. We will use categorical variables; say 0 and 1. 0 will represent absence of a class and 1 will represent presence of a class. We do this so that we can pass the images through the network and it will know whether it’s a plane or an automobile at the end of the network based on the output. The first index of the label vector represents the class Aeroplane and the second index represents the class Car.

### Neural Network Framework

We will build the Neural Network architecture in this task. Our Neural Network will have just one hidden layer. We will be using `relu` activations on the hidden layer and `softmax` activations on the output layer. The `softmax` activation is a natural choice where we want probability distribution across our classes as our output. Once you get familiar with this terminology, building Neural Networks becomes easier. It takes a couple of models though before you get there. So be patient with yourself.

### Training the Model

This is the moment of truth! In this task, we will be training our Neural Network model on the dataset. Since we have a very small dataset, it may take a few tries before the model actually catches on the relevant features of our images that help it classify the images properly.

### Testing the Model

In this task, we are testing the model’s performance. Remember that we’re using a very small test set. But when we trained the model, we saw that it did very well. So it is likely to do well on a larger test set as well. In any event, this project is to show you how to set the problem up. You can make your models as big as you want or as small as the one we are creating today. You can use much larger training and test sets as well.

### How Does Model Perform on New Images?

In this task, we’re going to test our model on images the model hasn’t seen. I happen to know that it works out pretty good. But I’ll show you how to get there. We will then do a quick overview of the journey we’ve taken and after that conclude!

## Watch Preview

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

## 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)., I work as a Data Analyst/Financial Analyst for a Metals Co. located in Seattle, WA. I have been in my current position for 5 years. I work in SQL, R, R Shiny, QGIS. Because I have traveled the roads you are on I believe I will be an asset and will add value to your programming repertoire. We will walk through multiple examples and get to know each other through the process. Don't take my word for it though. Come on in and take a Project or two. Regards, Chris Shockley

##### How is this different from YouTube, PluralSight, Udemy, etc.?
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.
##### Can I buy Rhyme sessions for my company or learning institution?
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 projects 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 help@rhyme.com
##### What kind of accessibility options does Rhyme provide?
Rhyme's visual instructions are somewhat helpful for reading impairments. The Rhyme interface has features like resolution and zoom that are slightly helpful for visual impairment. And, we are currently developing a close-caption functionality to help with hearing impairment. Most of the accessibility options of the cloud desktop's operating system or the specific application can also be used in Rhyme. However, we still have a lot of work to do. If you have suggestions for accessibility, please email us at accessibility@rhyme.com
##### Why don't you just use containers or virtual browsers?
We started with windows and linux cloud desktops because they have the most flexibility in teaching any software (desktop or web). However, web applications like Salesforce can run directly through a virtual browser. And, others like Jupyter and RStudio can run on containers and be accessed by virtual browsers. We are currently working on such features where such web applications won't need to run through cloud desktops. But, the rest of the Rhyme learning, authoring, and monitoring interfaces will remain the same.
##### I have a different question
Please email us at help@rhyme.com and we'll respond to you within one business day.

26 minutes
44 minutes
32 minutes
41 minutes
31 minutes
22 minutes
26 minutes
36 minutes