Skip to main content

trelawney

https://img.shields.io/pypi/v/trelawney.svg https://img.shields.io/travis/aredier/trelawney.svg Documentation Status MIT License

Trelawney is a general interpretability package that aims at providing a common api to use most of the modern interpretability methods to shed light on sklearn compatible models (support for Keras and XGBoost are tested).

Trelawney will try to provide you with two kind of explanation when possible:

  • global explanation of the model that highlights the most importance features the model uses to make its predictions globally

  • local explanation of the model that will try to shed light on why a specific model made a specific prediction

The Trelawney package is build around:

  • some model specific explainers that use the inner workings of some types of models to explain them:
    • LogRegExplainer that uses the weights of the your logistic regression to produce global and local explanations of your model

    • TreeExplainer that uses the path of your tree (single tree model only) to produce explanations of the model

  • Some model agnostic explainers that should work with all models:
    • LimeExplainer that uses the Lime package to create local explanations only (the local nature of Lime prohibits it from generating global explanations of a model

    • ShapExplainer that uses the SHAP package to create local and global explanations of your model

    • SurrogateExplainer that creates a general surogate of your model (fitted on the output of your model) using an explainable model (DecisionTreeClassifier,`LogisticRegression` for now). The explainer will then use the internals of the surrogate model to explain your black box model as well as informing you on how well the surrogate model explains the black box one

Quick Tutorial (30s to Trelawney):

Here is an example of how to use a Trelawney explainer

>>> model = LogisticRegression().fit(X, y)
>>> # creating and fiting the explainer
>>> explainer = ShapExplainer()
>>> explainer.fit(model, X, y)
>>> # explaining observation
>>> explanation =  explainer.explain_local(X_expain)
[
    {'var_1': 0.1, 'var_2': -0.07, ...},
    ...
    {'var_1': 0.23, 'var_2': -0.15, ...} ,
]
>>> explanation =  explainer.graph_local_explanation(X_expain.iloc[:1, :])
Local Explanation Graph
>>> explanation =  explainer.feature_importance(X_expain)
{'var_1': 0.5, 'var_2': 0.2, ...} ,
>>> explanation =  explainer.graph_feature_importance(X_expain)
Local Explanation Graph

FAQ

Why should I use Trelawney rather than Lime and SHAP

while you can definitally use the Lime and SHAP packages directly (they will give you more control over how to use their packages), they are very specialized packages with different APIs, graphs and vocabulary. Trelawnaey offers you a unified API, representation and vocabulary for all state of the art explanation methods so that you don’t lose time adapting to each new method but just change a class and Trelawney will adapt to you.

Comming Soon

  • Regressor Support (PR welcome)

  • Image and text Support (PR welcome)

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

0.1.0 (2019-10-02)

  • First release on PyPI.

Metadata

Release files for trelawney 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for trelawney 0.3.1
File Size Uploaded
trelawney-0.3.1.tar.gz 2.5 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for trelawney 0.3.1
File Interpreter ABI Platform
trelawney-0.3.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 2.5 MB

Release files / trelawney-0.3.1.tar.gz

Download URL trelawney-0.3.1.tar.gz
Size 2.5 MB
Tags Source
SHA-256 checksum
How to use checksums
2905b1d9c4f1c8937f7c770be25fcc6d5eb921351df498f5758658128ef40a56
BLAKE2b-256 checksum
How to use checksums
f5317b42d0027998e0dbced0fa0e0489f547b0a4b19c4522aafd6f2770190bb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.5.7

Release files / trelawney-0.3.1-py2.py3-none-any.whl

Download URL trelawney-0.3.1-py2.py3-none-any.whl
Size 14.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
2ac606e5a32c94b4a940714357a6a97166e2a7a8656d147efd3777e7a4ad0dff
BLAKE2b-256 checksum
How to use checksums
80b883190794342222158929ffe6112d70bf09911f2221f085c312c288bea877
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.5.7

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.0

1 release file

0.1.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page