Skip to content

sibyl-dev/pyreal

Repository files navigation

“DAI-Lab” An open source project from Data to AI Lab at MIT.

PyPI Shield PyPI - Python Version PyPI - Downloads Build Action Status Static Badge

Pyreal

An easier approach to understanding your model's predictions.

Important Links
📖 Documentation Quickstarts and user guides
📝 API Reference Full library API
🍎 Tutorials Notebooks with example usage
📜 License This repository is published under the MIT License
💻 Project Homepage Check out the Sibyl project website for more information

Overview

Pyreal gives you easy-to-understand explanations of your machine learning models in a low-code manner. Pyreal wraps full ML pipelines in a RealApp object that makes it easy to use, understand, and interact with your ML model — regardless of your ML expertise.

Install

Requirements

Pyreal has been developed and tested on Python 3.9, 3.10, and 3.11 The library uses Poetry for package management.

Install from PyPI

We recommend using pip in order to install Pyreal:

pip install pyreal

This will pull and install the latest stable release from PyPI.

Install from source

If you do not have poetry installed, please head to poetry installation guide and install poetry according to the instructions.
Run the following command to make sure poetry is activated. You may need to close and reopen the terminal.

poetry --version

Finally, you can clone this repository and install it from source by running poetry install, with the optional examples extras if you'd like to run our tutorial scripts.

git clone https://github.com/sibyl-dev/pyreal.git
cd pyreal
poetry install

Install for Development

If you want to contribute to the project, a few more steps are required to make the project ready for development.

Please head to the Contributing Guide for more details about this process.

Quickstart

In this short tutorial we will guide you through some steps to get your started with Pyreal. We will use a RealApp object to get predictions and explanations on whether a passenger on the Titanic would have survived.

For a more detailed version of this tutorial, see our documentation.

Load in the demo data and application

import pyreal.sample_applications.titanic as titanic

real_app = titanic.load_app()
sample_data = titanic.load_data(n_rows=300)

Predict and produce explanation

predictions = real_app.predict(sample_data)

explanation = real_app.produce_feature_contributions(sample_data)

Visualize explanation for one passenger

passenger_id = 1
feature_bar_plot(explanation[passenger_id], prediction=predictions[passenger_id], show=False)

The output will be a bar plot showing the most contributing features, by absolute value.

Quickstart

We can see here that the input passenger's predicted chance of survival was greatly reduced because of their sex (male) and ticket class (3rd class).

Migrating your application to Pyreal

To create a RealApp object for your own application, see our migration tutorial.

For basic applications built on sklearn pipelines, you may be able to simply use:

from pyreal import RealApp

pipeline = # YOUR SKLEARN PIPELINE
X_train, y_train = # YOUR TRAINING DATA

real_app = RealApp.from_sklearn(pipeline, X_train=X_train, y_train=y_train)

Next Steps

For more information on using Pyreal for your use case, head over to the full documentation site.