MLflow with R

Javier Luraschi

November 2018

Overview

  • What is MLflow?
  • MLflow with R

What is MLflow?

Background

Spark Summit from Andrej Karpathy at Tesla

The toolchain for the (software) 2.0 tack does not exist.

Challenge

Different models need to be run across many runtimes each producing many results.

Solution

MLflow can run models across runtimes tracking their results.

MLflow

“Helps teams manage their machine learning lifecycle.”

  • Tracking
    : Track experiments to record and compare params and results.
  • Projects
    : Reuse and reproduce code to share or transfer to production.
  • Models
    : Manage and deploy models from across libraries and platforms.

MLflow with R

Principles

  • Parity with Python API.
  • Designed for the R user.

Installing

Install Anaconda or miniconda.

Tracking

Tracking - Implicit

Implicit MLflow run:

Run terminates when the R session finishes or by running:

Useful when sourcing files.

Tracking - Explicit

Explicit MLflow run:

Tracking - Sources

Or adding the following to tracking.R in RStudio 1.2:

Or any other command:

Tracking - UI

Projects

Projects - Snapshots

Create dependencies snapshot:

Then restore snapshot:

Projects - Consuming R from R

Elasticnet model (alpha=0.2, lambda=0.5):
  RMSE: 0.827574750159859
  MAE: 0.632070002076146
  R2: 0.227227498131926

Projects - Consuming Python from R

Elasticnet model (alpha=0.200000, l1_ratio=0.100000):
  RMSE: 0.7836984021909766
  MAE: 0.6142020452688988
  R2: 0.20673590971167466

Projects - Consuming R from Bash

Or from bash:

Elasticnet model (alpha=0.5, lambda=0.5):
  RMSE: 0.828684594922867
  MAE: 0.627503954965052
  R2: 0.19208126758775

Models

R Models - Saving from R

Generic functions can be serialized with carrier::crate:

Models - Predictions from R

       1 
23.04527

Models - Serving from R

Models - Predict form Bash

Or from bash,

Keras Models - Saving

However, mlflow_save_model() can be extended by packages:

Keras Models - Prediction

           [,1]
[1,] 0.02378437

Keras Models - Serving

[{"cyl":1,"disp":1,"hp":1,"drat":1,"wt":1,"qsec":1,"vs":1,"am":1,"gear":1,"carb":-1}] 
{"predictions": [[0.0238]]}

Models - Prediction in Spark

# Source: spark<?> [?? x 1]
   result
 *  <dbl>
 1   22.6
 2   22.1
 3   26.3
 4   21.2
 5   17.7

Thanks!

Resources

mlflow.org

github.com/mlflow/mlflow

rpubs.com/jluraschi/mlflow-rbayarea

@javierluraschi