Package: teex
teex: a toolbox for evaluating XAI explanationsA Pythontoolbox for theevaluation of machine learningexplanations.This project aims to provide a simple way ofevaluatingindividual black box explanations against ground truth. Moreover, it contains a collection of easy-to-access datasets with available g.t. explanations.InstallationThe teex package is onPyPI. To install it, simply runpipinstallteexteexis compatible with Python 3.8 and 3.9.Documentationteex's documentation, in-depth examples and API reference can be found onRead The Docs.Usage overviewteexis divided into subpackages, one for each explanation type. Each subpackage contains two modules, focused on two
distinct functionalities:eval: containsevaluationmethods for that particular explanation type. For every subpackage, there is one high-level
function to easily compute all the available metrics for an arbitrary number of explanations.data: containsdataclasses with available g.t. explanations of that particular
explanation type, both synthetic and real. All of them are objects that need to be instanced and, when sliced,
will return the data, the target and the ground truth explanations, respectively.Evaluation (with feature importance as an example)What are feature importance vectors?They are vectors with one entry per feature. Each entry contains a weight that
represents a feature's importance for the observation's outcome. Weights are usually in the range $[-1, 1]$.Suppose that we have a dataset with available g.t. explanations (gtExps) and a model trained with it (model):fromteex.featureImportance.evalimportfeature_importance_scores# get individual feature importance explanations with any methodpredictedExps=get_explanations(model,X)# evaluate predicted explanations against ground truthsfeature_importance_scores(gtExps,predictedExps,metrics=['fscore','cs','auc'])This basic syntax is followed by the main evaluation APIs of all 4 explanation types:Feature Importance:feature_importance_scoresSaliency Maps:saliency_map_scoresDecision Rules:rule_scoresWord Importance:word_importance_scoresOther functionalities are included in each evaluation module. More about each explanation type can be found in the example notebooks and the documentation.Metrics supported:Metrics available as ofv1.0.0areFeature ImportanceCosine Similarity: similarity between the two vectors is measured in an inner product space in terms of orientation.ROC AUC: where the ground truth is binarized in order for it to represent a class and the predicted vector entries are interpreted as classification scores or likelihood.F1 Score: where both ground truth and prediction are binarized according to a user-defined threshold.Precision: g.t. and prediction treated as in F1 ScoreRecall: g.t. and prediction treated as in F1 ScoreSaliency MapsSame metrics as in feature importance. Each pixel in an image is considered to be a feature.Decision RulesComplete Rule Quality: Proportion of lower and upper bounds in a rule explanation whose that are $\epsilon$-close to the respective lower and upper bounds (same feature) in the ground truth rule explanation amongst those that are not infinity.All metrics in feature importance, where a transformation of the rule into feature importance vectors is performed first. See doc. for details.Word Importance:All metrics in feature importance, where a vocabulary is considered the feature space and a word importance explanation may or may not contain words from the vocabulary.Note how inteex, feature importance vectors are a universal representation: we 'translate' all other explanation types
to feature importance vectors to allow a wider metric space.Datateexalso provides an easy way to get and use data with available ground truth explanations. It contains real datasets and can generate synthetic ones.
All of them are instanced as objects, and can be sliced as usual. For example:fromteex.saliencyMap.dataimportKahikateaX,y,exps=Kahikatea()[:]downloads and assigns data from the Kahikatea dataset:Fig. 1 AKahikateadataset sample.Other datasets, such asCUB-200-2011and theOxford-IIIT Pet Dataset, are available onteex, with over 19000 images and 230 distinct classes:fromteex.saliencyMap.dataimportCUB200X,y,exps=CUB200()[:]Fig. 2 ACUB-200-2011dataset sample.fromteex.saliencyMap.dataimportOxfordIIITX,y,exps=OxfordIIIT()[:]Fig. 3 AnOxford-IIIT Pet Datasetsample.Synthetic datasets can also be easily generated:fromteex.saliencyMap.dataimportSenecaSMX,y,exps=SenecaSM()[:]Fig. 4 Artificial image and its g.t. saliency map explanation.Datasets for all other explanation types are available too.Tutorials and demosSaliency mapsImproving model selection with explanation qualityRetrieving image data with g.t. saliency map explanationsEvaluating Captum saliency map explanationsFeature importance vectorsRetrieving tabular data with g.t. feature importance explanationsEvaluating LIME feature importance explanationsDecision rulesRetrieving tabular data with g.t. decision rule explanationsEvaluating decision rule explanationsWord importance vectorsRetrieving language data with g.t. word importance explanationsEvaluating word importance explanationsContributingThere is still work to do and we would really appreciate your help. Before contributing toteex, please take a moment to read themanual.AcknowledgementsThis work has been made possible by theUniversity of Waikatounder the scope of
theTAIAOproject.