Skip to main content

A Toolbox for the Evaluation of Explanations

Project description

teex: a toolbox for evaluating XAI explanations

PyPI Version Open GitHub Issues Documentation Status

A Python Toolbox for the Evaluation of machine learning Explanations.

This project aims to provide a simple way of evaluating individual black box explanations against ground truth. Moreover, it contains a collection of easy-to-access datasets with available g.t. explanations.

Installation

The teex package is on PyPI. To install it, simply run

pip install teex

teex is compatible with Python >= 3.6.

Usage overview

teex is divided into subpackages, one for each explanation type. Each subpackage contains two modules, focused on two distinct functionalities:

  • eval: contains evaluation methods for that particular explanation type. For every subpackage, there is one high-level functions to easily compute all the available metrics.
  • data: contains data classes 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):

from teex.featureImportance.eval import feature_importance_scores

# get individual feature importance explanations with any method
predictedExps = get_explanations(model, X)

# evaluate predicted explanations against ground truths
feature_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_scores
  • Saliency Maps: saliency_map_scores
  • Decision Rules: rule_scores
  • Word Importance: word_importance_scores

Other 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 of v1.0.0 are

  • Feature Importance
    • Cosine 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 Score
    • Recall: g.t. and prediction treated as in F1 Score
  • Saliency Maps
    • Same metrics as in feature importance. Each pixel in an image is considered to be a feature.
  • Decision Rules
    • Complete Rule Quality: Proportion of lower and upper bounds in a rule explanation whose that are eps-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 in teex, feature importance vectors are a universal representation: we 'translate' all other explanation types to feature importance vectors to allow a wider metric space.

Data

teex also 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:

from teex.saliencyMap.data import Kahikatea

X, y, exps = Kahikatea()[:]

downloads and assigns data from the Kahikatea [1] dataset:

drawing

Fig. 1 The Kahikatea dataset. Contains aerial images with the task of identifying whether there are Kahikatea trees (a species endemic to New Zealand) in the area or not. Observation on the left, ground truth explanation on the right.

Synthetic datasets can also be generated effortlessly:

from teex.saliencyMap.data import SenecaSM

X, y, exps = SenecaSM()[:]

drawing

Fig. 2 Artificial image dataset with g.t. saliency map explanations.

Tutorials and API

The full API documentation can be found on Read The Docs.

Here are some sample notebooks with examples:


Saliency maps


Feature importance vectors (TBA)


Decision rules (TBA)


Word importance vectors (TBA)

Contributing

Before contributing to teex, please take a moment to read the manual.

Acknowledgements

This work has been made possible by the University of Waikato under the scope of the TAIAO project.

drawing drawing drawing

References

[1] Y. Jia et al. (2021) Studying and Exploiting the Relationship Between Model Accuracy and Explanation Quality, ECML-PKDD 2021

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

teex-1.0.1.tar.gz (42.6 kB view details)

Uploaded Source

Built Distribution

teex-1.0.1-py3-none-any.whl (49.2 kB view details)

Uploaded Python 3

File details

Details for the file teex-1.0.1.tar.gz.

File metadata

  • Download URL: teex-1.0.1.tar.gz
  • Upload date:
  • Size: 42.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.6

File hashes

Hashes for teex-1.0.1.tar.gz
Algorithm Hash digest
SHA256 3bc0179cc9c674ebc9ac117c45df717ec319dc7a5463136f1862599607fef2f6
MD5 03e41916aae98a1c0ccf31347121a8a4
BLAKE2b-256 5e0c4e7a897c998551a4d3e0b2cb3715eb8428a427433a3bd2c72214f8a371ae

See more details on using hashes here.

File details

Details for the file teex-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: teex-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 49.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.6

File hashes

Hashes for teex-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aab171ffe6800042f71df0b4ba4d0e748986f8ad46c9835f8db447214bd1baca
MD5 f20f3596000840c54eb276f46c07e8c8
BLAKE2b-256 698c160428f0835dacf2981ba8632fb82e16abe5ddd0ce1f1407840facebc4ef

See more details on using hashes here.

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