Jupyter + Rails

Jupyter notebooks are a great alternative to the Rails console for doing exploratory data analysis and building predictive models. Here’s how to get setup:

First, install Jupyter. With Homebrew, use:

brew install jupyterlab

Add to your Gemfile

group :development do
  gem 'iruby', require: false
  gem 'ffi-rzmq', require: false
end

Run

bundle install
bundle exec iruby register --force

Start Jupyter

jupyter notebook

Create a notebook and add to the top

require "./config/environment"

If not at Rails root, use Dir.chdir("path/to/root") { require "./config/environment" }

And science away

User.last

If you use Git, add to .gitignore

.ipynb_checkpoints

If you use Nyaplot, use the master branch to fix an issue with empty charts.

gem 'nyaplot', github: 'domitry/nyaplot'

Published June 19, 2018


You might also enjoy

TensorFlow Object Detection in Ruby

Score Almost Any Machine Learning Model in Ruby

Emotion Recognition in Ruby


All code examples are public domain.
Use them however you’d like (licensed under CC0).