An open source project from Data to AI Lab at MIT.
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 |
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.
See our tutorial series for an example of using Pyreal for house-price prediction:
- Part 1: Learn about feature engineering and modelling
- Part 2: Learn how to use Pyreal to use and understand ML models
Pyreal has been developed and tested on Python 3.9, 3.10, and 3.11 The library uses Poetry for package management.
We recommend using pip in order to install Pyreal:
pip install pyreal
This will pull and install the latest stable release from PyPI.
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
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.
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.
import pyreal.sample_applications.titanic as titanic
real_app = titanic.load_app()
sample_data = titanic.load_data(n_rows=300)
predictions = real_app.predict(sample_data)
explanation = real_app.produce_feature_contributions(sample_data)
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.
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).
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)
For more information on using Pyreal for your use case, head over to the full documentation site.