Library for evaluating and deploying human readable machine learning explanations.
Project description
An open source project from Data to AI Lab at MIT.
Pyreal
Library for evaluating and deploying machine learning explanations.
- License: MIT
- Documentation: https://pyreal.gitbook.io/pyreal
- API Documentation: https://sibyl-ml.dev/pyreal/api_reference/index.html
- Homepage: https://sibyl-ml.dev/
Overview
Pyreal wraps the complete machine learning explainability pipeline into Explainer objects. Explainer objects handle all the transforming logic, in order to provide a human-interpretable explanation from any original data form.
Install
Requirements
Pyreal has been developed and tested on Python 3.8, 3.9, and 3.10 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
:
git clone git@github.com:DAI-Lab/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 a series of steps that will help you getting started with Pyreal. We will get an explanation for a prediction on whether a passenger on the Titanic would have survived.
For a more detailed version of this tutorial, see
examples.titanic.titanic_lfc.ipynb
Load in demo dataset, pre-fit model, and transformers
>>> import pyreal.applications.titanic as titanic
>>> from pyreal.transformers import ColumnDropTransformer, MultiTypeImputer
# Load in data
>>> x_train_orig, y = titanic.load_titanic_data()
# Load in feature descriptions -> dict(feature_name: feature_description, ...)
>>> feature_descriptions = titanic.load_feature_descriptions()
# Load in model
>>> model = titanic.load_titanic_model()
# Load in list of transformers
>>> transformers = titanic.load_titanic_transformers()
# Create and fit LocalFeatureContribution Explainer object
>>> from pyreal.explainers import LocalFeatureContribution
>>> lfc = LocalFeatureContribution(model=model, x_train_orig=x_train_orig,
... transformers=transformers,
... feature_descriptions=feature_descriptions,
... fit_on_init=True)
# Make predictions on an input
>>> input_to_explain = x_train_orig.iloc[0]
>>> prediction = lfc.model_predict(input_to_explain) # Prediction: [0]
# Explain an input
>>> contributions = lfc.produce(input_to_explain)
# Visualize the explanation
>>> from pyreal.utils import visualize
>>> x_interpret = lfc.convert_data_to_interpretable(input_to_explain)
Plot a bar plot of top contributing features, by absolute value
visualize.plot_top_contributors(contributions, select_by="absolute", values=x_interpret)
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).
Terminology
Pyreal introduces specific terms and naming schemes to refer to different feature spaces and transformations. The Terminology User Guide provides an introduction to these terms.
What's next?
For more details about Pyreal and all its possibilities and features, please check the documentation site.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pyreal-0.3.2.tar.gz
.
File metadata
- Download URL: pyreal-0.3.2.tar.gz
- Upload date:
- Size: 423.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c5fa6f7804a6a03ad2ba2b6248ec1af252fbc57b18acaf2e2e73df51a8751a2 |
|
MD5 | 8ea3106783d5cfd5326448c6229e94c4 |
|
BLAKE2b-256 | 765b5bf938a4cce8f2c683543517c7cece799d10595d7d75c1b890343dbbc9b9 |
File details
Details for the file pyreal-0.3.2-py3-none-any.whl
.
File metadata
- Download URL: pyreal-0.3.2-py3-none-any.whl
- Upload date:
- Size: 487.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fc66e3f2813f0c506e1ece7262c53c34d854f10ffbd333beaff928a06333ed3 |
|
MD5 | 6119bb6b5f3b8dbcf7bdee17e205fb46 |
|
BLAKE2b-256 | 9c0523076f26b41ae16fab2e2349e3b097d3c0f8cd453634f38ff9a12992d003 |