Book Image

R Deep Learning Projects

Book Image

R Deep Learning Projects

Overview of this book

R is a popular programming language used by statisticians and mathematicians for statistical analysis, and is popularly used for deep learning. Deep Learning, as we all know, is one of the trending topics today, and is finding practical applications in a lot of domains. This book demonstrates end-to-end implementations of five real-world projects on popular topics in deep learning such as handwritten digit recognition, traffic light detection, fraud detection, text generation, and sentiment analysis. You'll learn how to train effective neural networks in R—including convolutional neural networks, recurrent neural networks, and LSTMs—and apply them in practical scenarios. The book also highlights how neural networks can be trained using GPU capabilities. You will use popular R libraries and packages—such as MXNetR, H2O, deepnet, and more—to implement the projects. By the end of this book, you will have a better understanding of deep learning concepts and techniques and how to use them in a practical setting.
Table of Contents (11 chapters)


In this book, we have tried to make a case for using deep learning within R. Most deep learning power-users would shun R and go for other languages, such as Python. We, however, believe that R has a solid ecosystem of packages, and visualization and manipulation tools, that can be combined with deep learning libraries to create interesting projects. R also has a huge base of users without a software engineering background (perhaps you are one of them?), and those users are increasingly interested in applications that deep learning is making possible, but they do not have time to learn Python. 

Who this book is for

This book is meant mainly for two types of readers: professionals who use R in their daily work and want to know some of the tricks and best practices that we have discovered in our projects, and anyone who wants to jump into the field of deep learning with concrete use cases in mind. This is not a tutorial in R or machine learning; it is rather a real-world showcase of how deep learning can be used in industry, with examples borrowed from our own experience.

What this book covers

Chapter 1, Handwritten Digit Recognition Using Convolutional Neural Networks, is where we start working on the first project of the book. We will begin with a recap of logistic regression and multilayer perceptron. We'll solve the problem with these two algorithms. We will then move on to the biologically inspired variants of multilayer perceptron—convolutional neural networks (CNNs). We will also cover the basics and core concepts of deep learning.

Chapter 2, Traffic Sign Recognition for Intelligent Vehicles, explains how to use CNNs for another application—traffic sign detection. We will also cover several important concepts of deep learning in this chapter and get readers familiar with other popular frameworks and libraries, such as Keras and TensorFlow. We will also introduce the dropout technique as a regularization approach and utilize data augmentation techniques to deal with a lack of training data.

Chapter 3, Fraud Detection with Autoencoders, introduces a type of deep learning model that can be used for anomaly detection. Outliers can be found within a collection of images, a text corpus, or transactional data. We will dive into applications of autoencoders and how they can be used for outlier detection in this domain. 

Chapter 4, Text Generation Using Recurrent Neural Networks, introduces different models of neural networks that try to capture the elusive properties of memory and abstraction to produce powerful models. We will apply different methods to tackle the text generation problem and suggest directions of further exploration. 

Chapter 5, Sentiment Analysis with Word Embeddings, shows how to use the popular GloVe algorithm for sentiment analysis, as well as other, less abstract tools. Although this algorithm is, strictly speaking, not a deep learning application, it belongs to the modern (as of 2018) toolkit of the data scientist, and it can be combined with other deep learning techniques.

To get the most out of this book

You should be comfortable with R and RStudio and have some knowledge of college-level mathematics (calculus and linear algebra). Working knowledge of basic machine learning algorithms for classification, regression problems, and clustering might be helpful, but it is not strictly required.

Download the example code files

You can download the example code files for this book from your account at If you purchased this book elsewhere, you can visit and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at We also have other code bundles from our rich catalog of books and videos available at Check them out!


Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Similarly, for the second sample, (a "0"), we run:"

A block of code is set as follows:

> for (i in 1:16) {
+ outputData <- as.array
+ image(outputData, xaxt='n', yaxt='n',
+ )
+ }

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

logit <- function(x){

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Once logged in, click on Create New App."


Warnings or important notes appear like this.


Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit


Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit