Skip to main content

Library for evaluating and deploying machine learning explanations.

Project description

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

Travis CI Shield Coverage Status

Pyreal

Library for evaluating and deploying machine learning explanations.

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 Python3.4, 3.5, 3.6 and 3.7

Also, although it is not strictly required, the usage of a virtualenv is highly recommended in order to avoid interfering with other software installed in the system in which Pyreal is run.

These are the minimum commands needed to create a virtualenv using python3.6 for Pyreal:

pip install virtualenv
virtualenv -p $(which python3.6) pyreal-venv

Afterwards, you have to execute this command to activate the virtualenv:

source pyreal-venv/bin/activate

Remember to execute it every time you start a new console to work on Pyreal!

Install from source

With your virtualenv activated, you can clone the repository and install it from source by running make install on the stable branch:

git clone git@github.com:DAI-Lab/pyreal.git
cd pyreal
git checkout stable
make install

Quickstart

In this short tutorial we will guide you through a series of steps that will help you getting started with Pyreal. For a more detailed version of this tutorial, see examples.titanic.titanic_tutorial.ipynb

from pyreal.explainers import LocalFeatureContribution
import pyreal.applications.titanic as titanic
from pyreal.utils.transformer import ColumnDropTransformer, MultiTypeImputer
from pyreal.utils import visualize

# First, we will load in the Titanic dataset
x_orig, y = titanic.load_titanic_data()

# Next, we load in a dictionary that provides human-readable descriptions of the feature names
#   Format: {feature_name : feature_description, ...}
feature_descriptions = titanic.load_feature_descriptions()

# Finally, we load in the trained model and corresponding fitted transformers
model = titanic.load_titanic_model()
transformers = titanic.load_titanic_transformers()

# Now, we can make and fit a LocalFeatureContribution object, which will handle all the 
#   transformations needed to get an interpretable SHAP feature contribution explanation
lfc = LocalFeatureContribution(model=model, x_orig=x_orig, m_transforms=transformers, e_transforms=transformers, 
                               contribution_transforms=transformers, 
                               feature_descriptions=feature_descriptions)
lfc.fit()

# We can now choose an input, and see the model's prediction.
input_to_explain = x_orig.iloc[0]
print("Prediction:", lfc.model_predict(input_to_explain)) # Output -> Prediction: [0]

# We see that this person is not predicted to survive. 
#   Let's see why, by using LocalFeatureContribution's .produce() function
contributions = lfc.produce(input_to_explain)

# We can visualize the most contributing features using the pyreal.utils.visualize module. 
#   We will also convert our input to the interpretable space, so we can add it's values to
#   the visualization
x_interpret = lfc.convert_data_to_interpretable(input_to_explain)
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.

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).

What's next?

For more details about Pyreal and all its possibilities and features, please check the documentation site.

History

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyreal-0.1.0.dev0.tar.gz (70.4 kB view hashes)

Uploaded Source

Built Distribution

pyreal-0.1.0.dev0-py2.py3-none-any.whl (16.5 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page