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

gem 'iruby', group: :development

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 · Tweet


You might also enjoy

Scaling the Monolith

Artistic Style Transfer in Ruby

The Two Metrics You Need


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