Purpose: We are about to discuss neural networks and deep learning. These are advanced structures which are built on specialized libraries. While {tidymodels} supports some of the most basic neural network architecture, we’ll be much better off if we work in something which has been built for the purpose of constructing and utilizing deep learning networks. In this notebook, you’ll install {keras} and {tensorflow}. The functionality from {tensorflow} was built in python, so we’ll need python installed as well.

Setup

Follow the instructions to install Keras and Tensorflow here. Note, the instructions seemed to be somewhat finicky. Here is what has worked for me.

  1. Install TensorFlow with install.packages("tensorflow")
  2. Run library(reticulate) – install the {reticulate} package if you don’t have it already. This will allow you to run Python and R together in a single notebook and pass objects between environments.
  3. Open your terminal using the terminal tab in the bottom-left pane of RStudio and type python and run the command by hitting Enter/Return.
  1. In your Console, run virtualenv_create("r-reticulate", python = path_to_python). This will create a python virtual environment and package container in your working directory.
  2. Install the {keras} package and then load the {keras} library.
  3. Install TensorFlow, SciPy, and several TensorFlow data sets using install_keras(method = "virtualenv", envname = "r-reticulate", version = "cpu").
  4. Completely shut down and reopen RStudio. You might try clicking on Session and Restart R, but this only sometimes worked for me.
  5. Reopen RStudio and your R Markdown notebook.
  6. In the notebook, load the {tensorflow} and {reticulate} libraries.
  7. Type and run use_virtualenv("r-reticulate").
  8. Run tf$constant("Hello TensorFlow!")

Summary

You now have TensorFlow installed. This is a state of the art software for training and utilizing deep learning networks which was developed at Google.