Package: alibi
Alibiis an 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.DocumentationIf you're interested in outlier detection, concept drift or adversarial instance detection, check out our sister projectalibi-detect.Anchor explanations for imagesIntegrated Gradients for textCounterfactual examplesAccumulated Local EffectsTable of ContentsInstallation and UsageSupported MethodsModel ExplanationsModel ConfidencePrototypesReferences and ExamplesCitationsInstallation and UsageAlibi can be installed from:PyPI or GitHub source (withpip)Anaconda (withconda/mamba)With pipAlibi can be installed fromPyPI:pipinstallalibiAlternatively, the development version can be installed:pipinstallgit+https://github.com/SeldonIO/alibi.gitTo take advantage of distributed computation of explanations, installalibiwithray:pipinstallalibi[ray]For SHAP support, installalibias follows:pipinstallalibi[shap]With condaTo install fromconda-forgeit is recommended to usemamba,
which can be installed to thebaseconda enviroment with:condainstallmamba-nbase-cconda-forgeFor the standard Alibi install:mambainstall-cconda-forgealibiFor distributed computing support:mambainstall-cconda-forgealibirayFor SHAP support:mambainstall-cconda-forgealibishapUsageThe alibi explanation API takes inspiration fromscikit-learn, consisting of distinct initialize,
fit and explain steps. We will use theAnchorTabularexplainer to illustrate the API:fromalibi.explainersimportAnchorTabular# initialize and fit explainer by passing a prediction function and any other required argumentsexplainer=AnchorTabular(predict_fn,feature_names=feature_names,category_map=category_map)explainer.fit(X_train)# explain an instanceexplanation=explainer.explain(x)The explanation returned is anExplanationobject with attributesmetaanddata.metais a dictionary
containing the explainer metadata and any hyperparameters anddatais a dictionary containing everything
related to the computed explanation. For example, for the Anchor algorithm the explanation can be accessed
viaexplanation.data['anchor'](orexplanation.anchor). The exact details of available fields varies
from method to method so we encourage the reader to become familiar with thetypes of methods supported.Supported MethodsThe following tables summarize the possible use cases for each method.Model ExplanationsMethodModelsExplanationsClassificationRegressionTabularTextImagesCategorical featuresTrain set requiredDistributedALEBBglobal✔✔✔Partial DependenceBB WBglobal✔✔✔✔PD VarianceBB WBglobal✔✔✔✔Permutation ImportanceBBglobal✔✔✔✔AnchorsBBlocal✔✔✔✔✔For TabularCEMBB* TF/Keraslocal✔✔✔OptionalCounterfactualsBB* TF/Keraslocal✔✔✔NoPrototype CounterfactualsBB* TF/Keraslocal✔✔✔✔OptionalCounterfactuals with RLBBlocal✔✔✔✔✔Integrated GradientsTF/Keraslocal✔✔✔✔✔✔OptionalKernel SHAPBBlocalglobal✔✔✔✔✔✔Tree SHAPWBlocalglobal✔✔✔✔OptionalSimilarity explanationsWBlocal✔✔✔✔✔✔✔Model ConfidenceThese algorithms provideinstance-specificscores measuring the model confidence for making a
particular prediction.MethodModelsClassificationRegressionTabularTextImagesCategorical FeaturesTrain set requiredTrust ScoresBB✔✔✔(1)✔(2)YesLinearity MeasureBB✔✔✔✔OptionalKey:BB- black-box (only require a prediction function)BB*- black-box but assume model is differentiableWB- requires white-box model access. There may be limitations on models supportedTF/Keras- TensorFlow models via the Keras APILocal- 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 reductionPrototypesThese algorithms provide adistilledview of the dataset and help construct a 1-KNNinterpretableclassifier.MethodClassificationRegressionTabularTextImagesCategorical FeaturesTrain set labelsProtoSelect✔✔✔✔✔OptionalReferences and ExamplesAccumulated Local Effects (ALE,Apley and Zhu, 2016)DocumentationExamples:California housing dataset,Iris datasetPartial Dependence (J.H. Friedman, 2001)DocumentationExamples:Bike rentalPartial Dependence Variance(Greenwell et al., 2018)DocumentationExamples:Friedman’s regression problemPermutation Importance(Breiman, 2001;Fisher et al., 2018)DocumentationExamples:Who's Going to Leave Next?Anchor explanations (Ribeiro et al., 2018)DocumentationExamples:income prediction,Iris dataset,movie sentiment classification,ImageNet,fashion MNISTContrastive Explanation Method (CEM,Dhurandhar et al., 2018)DocumentationExamples:MNIST,Iris datasetCounterfactual Explanations (extension ofWachter et al., 2017)DocumentationExamples:MNISTCounterfactual Explanations Guided by Prototypes (Van Looveren and Klaise, 2019)DocumentationExamples:MNIST,California housing dataset,Adult income (one-hot),Adult income (ordinal)Model-agnostic Counterfactual Explanations via RL(Samoilescu et al., 2021)DocumentationExamples:MNIST,Adult incomeIntegrated Gradients (Sundararajan et al., 2017)Documentation,Examples:MNIST example,Imagenet example,IMDB example.Kernel Shapley Additive Explanations (Lundberg et al., 2017)DocumentationExamples:SVM with continuous data,multinomial logistic regression with continous data,handling categorical variablesTree Shapley Additive Explanations (Lundberg et al., 2020)DocumentationExamples:Interventional (adult income, xgboost),Path-dependent (adult income, xgboost)Trust Scores (Jiang et al., 2018)DocumentationExamples:MNIST,Iris datasetLinearity MeasureDocumentationExamples:Iris dataset,fashion MNISTProtoSelectDocumentationExamples:Adult Census & CIFAR10Similarity explanationsDocumentationExamples:20 news groups dataset,ImageNet dataset,MNIST datasetCitationsIf 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}
}