Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
R Deep Learning Cookbook

You're reading from   R Deep Learning Cookbook Solve complex neural net problems with TensorFlow, H2O and MXNet

Arrow left icon
Product type Paperback
Published in Aug 2017
Publisher Packt
ISBN-13 9781787121089
Length 288 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Achyutuni Sri Krishna Rao Achyutuni Sri Krishna Rao
Author Profile Icon Achyutuni Sri Krishna Rao
Achyutuni Sri Krishna Rao
PKS Prakash PKS Prakash
Author Profile Icon PKS Prakash
PKS Prakash
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Getting Started FREE CHAPTER 2. Deep Learning with R 3. Convolution Neural Network 4. Data Representation Using Autoencoders 5. Generative Models in Deep Learning 6. Recurrent Neural Networks 7. Reinforcement Learning 8. Application of Deep Learning in Text Mining 9. Application of Deep Learning to Signal processing 10. Transfer Learning

Installing TensorFlow in R

This section will cover another very popular open source machine learning package, TensorFlow, which is very effective in building deep learning models.

Getting ready

TensorFlow is another open source library developed by the Google Brain Team to build numerical computation models using data flow graphs. The core of TensorFlow was developed in C++ with the wrapper in Python. The tensorflow package in R gives you access to the TensorFlow API composed of Python modules to execute computation models. TensorFlow supports both CPU- and GPU-based computations.

The tensorflow package in R calls the Python tensorflow API for execution, which is essential to install the tensorflow package in both R and Python to make R work. The following are the dependencies for tensorflow:

  • Python 2.7 / 3.x
  • R (>3.2)
  • devtools package in R for installing TensorFlow from GitHub
  • TensorFlow in Python
  • pip

How to do it...

  1. Once all the mentioned dependencies are installed, tensorflow can be installed from devtools directly using the install_github command as follows:
devtools::install_github("rstudio/tensorflow")
  1. Before loading tensorflow in R, you need to set up the path for Python as the system environment variable. This can be done directly from the R environment, as shown in the following command:
Sys.setenv(TENSORFLOW_PYTHON="/usr/bin/python")
library(tensorflow)

If the Python tensorflow module is not installed, R will give the following error:

Error raised by R if tensorflow in Python is not installed

tensorflow in Python can be installed using pip:

pip install tensorflow # Python 2.7 with no GPU support
pip3 install tensorflow # Python 3.x with no GPU support
pip install tensorflow-gpu # Python 2.7 with GPU support
pip3 install tensorflow-gpu # Python 3.x with GPU support

How it works...

TensorFlow follows directed graph philosophy to set up computational models where mathematical operations are represented as nodes with each node supporting multiple input and output while the edges represent the communication of data between nodes. There are also edges known as control dependencies in TensorFlow that do not represent the data flow; rather the provide information related to control dependence such as node for the control dependence must finish processing before the destination node of control dependence starts executing.

An example TensorFlow graph for logistic regression scoring is shown in the following diagram:

TensorFlow graph for logistic regression

The preceding figure illustrates the TensorFlow graph to score logistic regression with optimized weights:

The MatMul node performs matrix multiplication between input feature matrix X and optimized weight β. The constant C is then added to the output from the MatMul node. The output from Add is then transformed using the Sigmoid function to output Pr(y=1|X).

See also

You have been reading a chapter from
R Deep Learning Cookbook
Published in: Aug 2017
Publisher: Packt
ISBN-13: 9781787121089
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image