Alibi is a Python library aimed at machine learning model inspection and interpretation. The focus of the library is to provide high-quality implementations of black-box, white-box, local and global explanation methods for classification and regression models.
If you're interested in outlier detection, concept drift or adversarial instance detection, check out our sister project alibi-detect.
|
Anchor explanations for images |
Integrated Gradients for text |
|
Counterfactual examples |
Accumulated Local Effects |
Table of Contents
Installation and Usage
Alibi can be installed from:
- PyPI or GitHub source (with
pip) - Anaconda (with
conda/mamba)
With pip
-
Alibi can be installed from PyPI:
pip install alibi
-
Alternatively, the development version can be installed:
pip install git+https://github.com/SeldonIO/alibi.git
-
To take advantage of distributed computation of explanations, install
alibiwithray:pip install alibi[ray]
-
For SHAP support, install
alibias follows:pip install alibi[shap]
With conda
To install from conda-forge it is recommended to use mamba, which can be installed to the base conda enviroment with:
conda install mamba -n base -c conda-forge
-
For the standard Alibi install:
mamba install -c conda-forge alibi
-
For distributed computing support:
mamba install -c conda-forge alibi ray
-
For SHAP support:
mamba install -c conda-forge alibi shap
Usage
The alibi explanation API takes inspiration from scikit-learn, consisting of distinct initialize,
fit and explain steps. We will use the AnchorTabular
explainer to illustrate the API:
from alibi.explainers import AnchorTabular
# initialize and fit explainer by passing a prediction function and any other required arguments
explainer = AnchorTabular(predict_fn, feature_names=feature_names, category_map=category_map)
explainer.fit(X_train)
# explain an instance
explanation = explainer.explain(x)
The explanation returned is an Explanation object with attributes meta and data. meta is a dictionary
containing the explainer metadata and any hyperparameters and data is a dictionary containing everything
related to the computed explanation. For example, for the Anchor algorithm the explanation can be accessed
via explanation.data['anchor'] (or explanation.anchor). The exact details of available fields varies
from method to method so we encourage the reader to become familiar with the
types of methods supported.
Supported Methods
The following tables summarize the possible use cases for each method.
Model Explanations
| Method | Models | Explanations | Classification | Regression | Tabular | Text | Images | Categorical features | Train set required | Distributed |
|---|---|---|---|---|---|---|---|---|---|---|
| ALE | BB | global | ✔ | ✔ | ✔ | |||||
| Partial Dependence | BB WB | global | ✔ | ✔ | ✔ | ✔ | ||||
| PD Variance | BB WB | global | ✔ | ✔ | ✔ | ✔ | ||||
| Permutation Importance | BB | global | ✔ | ✔ | ✔ | ✔ | ||||
| Anchors | BB | local | ✔ | ✔ | ✔ | ✔ | ✔ | For Tabular | ||
| CEM | BB* TF/Keras | local | ✔ | ✔ | ✔ | Optional | ||||
| Counterfactuals | BB* TF/Keras | local | ✔ | ✔ | ✔ | No | ||||
| Prototype Counterfactuals | BB* TF/Keras | local | ✔ | ✔ | ✔ | ✔ | Optional | |||
| Counterfactuals with RL | BB | local | ✔ | ✔ | ✔ | ✔ | ✔ | |||
| Integrated Gradients | TF/Keras | local | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | Optional | |
| Kernel SHAP | BB | local global |
✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ||
| Tree SHAP | WB | local global |
✔ | ✔ | ✔ | ✔ | Optional | |||
| Similarity explanations | WB | local | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
Model Confidence
These algorithms provide instance-specific scores measuring the model confidence for making a particular prediction.
| Method | Models | Classification | Regression | Tabular | Text | Images | Categorical Features | Train set required |
|---|---|---|---|---|---|---|---|---|
| Trust Scores | BB | ✔ | ✔ | ✔(1) | ✔(2) | Yes | ||
| Linearity Measure | BB | ✔ | ✔ | ✔ | ✔ | Optional |
Key:
- BB - black-box (only require a prediction function)
- BB* - black-box but assume model is differentiable
- WB - requires white-box model access. There may be limitations on models supported
- TF/Keras - TensorFlow models via the Keras API
- Local - instance specific explanation, why was this prediction made?
- Global - explains the model with respect to a set of instances
- (1) - depending on model
- (2) - may require dimensionality reduction
Prototypes
These algorithms provide a distilled view of the dataset and help construct a 1-KNN interpretable classifier.
| Method | Classification | Regression | Tabular | Text | Images | Categorical Features | Train set labels |
|---|---|---|---|---|---|---|---|
| ProtoSelect | ✔ | ✔ | ✔ | ✔ | ✔ | Optional |
References and Examples
-
Accumulated Local Effects (ALE, Apley and Zhu, 2016)
- Documentation
- Examples: California housing dataset, Iris dataset
-
Partial Dependence (J.H. Friedman, 2001)
- Documentation
- Examples: Bike rental
-
Partial Dependence Variance(Greenwell et al., 2018)
- Documentation
- Examples: Friedman’s regression problem
-
Permutation Importance(Breiman, 2001; Fisher et al., 2018)
- Documentation
- Examples: Who's Going to Leave Next?
-
Anchor explanations (Ribeiro et al., 2018)
-
Contrastive Explanation Method (CEM, Dhurandhar et al., 2018)
- Documentation
- Examples: MNIST, Iris dataset
-
Counterfactual Explanations (extension of Wachter et al., 2017)
- Documentation
- Examples: MNIST
-
Counterfactual Explanations Guided by Prototypes (Van Looveren and Klaise, 2019)
-
Model-agnostic Counterfactual Explanations via RL(Samoilescu et al., 2021)
- Documentation
- Examples: MNIST, Adult income
-
Integrated Gradients (Sundararajan et al., 2017)
- Documentation,
- Examples: MNIST example, Imagenet example, IMDB example.
-
Kernel Shapley Additive Explanations (Lundberg et al., 2017)
-
Tree Shapley Additive Explanations (Lundberg et al., 2020)
-
Trust Scores (Jiang et al., 2018)
- Documentation
- Examples: MNIST, Iris dataset
-
Linearity Measure
- Documentation
- Examples: Iris dataset, fashion MNIST
-
ProtoSelect
- Documentation
- Examples: Adult Census & CIFAR10
-
Similarity explanations
Citations
If you use alibi in your research, please consider citing it.
BibTeX entry:
@article{JMLR:v22:21-0017,
author = {Janis Klaise and Arnaud Van Looveren and Giovanni Vacanti and Alexandru Coca},
title = {Alibi Explain: Algorithms for Explaining Machine Learning Models},
journal = {Journal of Machine Learning Research},
year = {2021},
volume = {22},
number = {181},
pages = {1-7},
url = {http://jmlr.org/papers/v22/21-0017.html}
}
Metadata
Release files for alibi 0.9.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| alibi-0.9.6.tar.gz | 469.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| alibi-0.9.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 991.2 kB
Release files / alibi-0.9.6.tar.gz
| Download URL | alibi-0.9.6.tar.gz |
|---|---|
| Size | 469.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7a5075baf62b693c4489752281c58814efca1dcd08cfe353242da9a9da9ed6c1
|
|
BLAKE2b-256 checksum How to use checksums |
f6125281c82e19aa2b2d705c45cee415860e108dd0e7f21bfaaab4df045ba3e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Release files / alibi-0.9.6-py3-none-any.whl
| Download URL | alibi-0.9.6-py3-none-any.whl |
|---|---|
| Size | 522.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
206416e297f927f6028f3ffcc286b16227a11b26ce99581f533ecf9efdc86a14
|
|
BLAKE2b-256 checksum How to use checksums |
bc00bc8caafbabf675a15f08e8cd6d86eedb5949e2cec5ec73157d71f62abd79
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Security for alibi 0.9.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.