Site icon R-bloggers

xai2cloud: Convert a predictive model into an XAI cloud service

[This article was first published on Stories by Przemyslaw Biecek on Medium, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

TL;DR

The xai2cloud package allows for simple deployment of an R model as a cloud service. Any predictive model from the local R console can be converted into a REST service available remotely in the DigitalOcean cloud. GET and POST methods are created automatically for elementary XAI methods such as Break Down and Ceteris Paribus. There will be more in the future.

Longer version

For years, I have been suffering from the fact that R objects created in the R console cannot be easily governed, managed nor shared between computers. To work around this problem, from 2013 we are developing the archivist package together with Marcin Kosiński. It allows storing objects along with meta-data in a SQL database. Thanks to this you can easily search for objects created in the past.

But storing inactive copies of objects is not enough! How much better would it be to take a model we just trained in the console, and turn it into an independent component living autonomously in the cloud. It would be so easy to share a remote access to the predict function. Moreover, together with the model, the service should automatically create hooks for XAI methods.

Now you can do this easily with the xai2cloud package. See an example swagger for the Titanic Random Forest model. And here is a short technical introduction prepared by the maintainer.

Author: Adam Rydelek

The new R package, xai2cloud, makes cloud deployment of your model easy. Recently we can observe an increase in demand for interpretable models. Machine Learning has been widely used in many fields for some time now but the trends are changing. Nowadays an accurate black box is no longer enough.

The xai2cloud package turns the explainer (adapter for any model created by the DALEX package) into a RESTful API. It is built on top of the excellent plumber package.

The future is in the cloud

We use the DigitalOcean as Cloud Computing Service. It offers easy to use, easy to configure, and reasonably priced deployment for small and medium-sized projects.

The explainer is enriched with GET and POST services generating simple visualizations for model explanations.

xai2cloud creates a REST API running on the web which can be used in various ways. You can utilize the built-in Swagger as an easy to use, interactive interface containing all the crucial information about your model.

To use this package you need to first configure the cloud environment (just once). Then you can add models to the configured droplet.

Set up the environment

Setting up a whole new web application for your models has never been that easy. All you need to do in order to deploy a nearly unlimited number of explainers is to follow the four steps below:

  1. Create a new DigitalOcean account with $100 free starting credit (of course, you can also use another cloud provider).
  2. Create and deploy an SSH key to your DigitalOcean’s account.
  3. Install required R packages (full list).
  4. Setup your new droplet using just one R function.
library(“xai2cloud”)
do_setup(model_package = c(“packages that shall be preinstalled in the droplet”))

Deploy the model

Now you are all set to share your first model/explainer using xai2cloud. The first step is to create a model and an explainer for it. For example purposes the chunk below builds a random forest model on the titanic_imputed dataset from DALEX.

  1. Create a model
library(“ranger”)
model <- ranger(survived~., data = titanic_imputed, classification = TRUE)

2. Create an explainer

library(“DALEX”)
explainer <- explain(model, data = titanic_imputed, y = titanic_imputed$survived)

3. Check your newly created droplet’s ID

library(“analogsea”)
droplets()

4. Deploy a web application using xai2cloud.

library(“xai2cloud”)
deploy_explainer(explainer, model_package = “randomForest”,
droplet=190624613, port=8080)

That’s it. Your explainer is now available at your droplet’s IP address.

Learn more

To leave a comment for the author, please follow the link and comment on their blog: Stories by Przemyslaw Biecek on Medium.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.