Skip to main content

A Toolbox for the Evaluation of Explanations

Project description

teex

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. Moreover, it contains a collection of easy-to-access datasets with available ground truth 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:

  • 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.

Feature Importance

In teex, feature importance vectors are a universal representation: we can 'translate' all other explanation types to feature importance vectors.

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].

drawing

Fig. 1 SHAP values, each representing impact on model output of each feature.

Popular feature importance model-agnostic explainers are, for example, SHAP or LIME. Because weights in each method represent slighlty different things, we make the assumption that they all mean roughly the same if they are in the same range (if we want to compare methods). teex performs this mapping automatically if necessary.

from teex.featureImportance.data import SenecaFI
from teex.featureImportance.eval import feature_importance_scores
from sklearn import DecisionTreeClassifier
import shap

# generate artificial data
X, y, exps = SenecaFI(nSamples=500, nFeatures=5)[:]

# instance and train the model
model = DecisionTreeClassifier()
model.fit(X, y)

# predict individual feature importance explanations
explainer = shap.Explainer(model)
predictedSHAPs = explainer(X).values

# evaluate predicted explanations againsy ground truths (implicit range mappings)
feature_importance_scores(exps, predictedSHAPs, metrics=['fscore', 'cs', 'rec'])

Saliency Maps

A saliency map is an image that shows each pixel's unique quality. In our context, each pixel (feature) contains a score (in the ranges [-1, 1] or [0, 1] as before) that represents a likelihood or probability of belonging to a particular class. For example:

drawing

Fig. 2 Input image and saliency map for the prediction of the class "dog" overlayed on top of the original image. It tells us where the model "looks" when issuing the prediction. source

teex contains artificial and real-life datasets for saliency map explanations:

drawing

Fig. 3 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.

drawing

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

A basic usage example of teex with saliency maps simulating perfect predicted explanations:

from teex.saliencyMap.data import Kahikatea
from teex.saliencyMap.eval import saliency_map_scores

X, y, exps = Kahikatea()[:]
saliency_map_scores(exps[y == 1], exps[y == 1], metrics=['fscore', 'auc'])

Decision Rules

WIP!

Word Importance

WIP!

Tutorials and API

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

Here are some sample notebooks with examples:

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

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.0.tar.gz (41.9 kB view details)

Uploaded Source

Built Distribution

teex-1.0.0-py3-none-any.whl (48.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: teex-1.0.0.tar.gz
  • Upload date:
  • Size: 41.9 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.0.tar.gz
Algorithm Hash digest
SHA256 6b0a36b1a956d00d5045931c1f29129bb568e65cc4ec31bf8d3c938efa823d25
MD5 ae502d86a44acbe94b8955b2d1bd6606
BLAKE2b-256 1a00f0a20e4f57dca5c8cc69d554c4ea60a0efc760fe9b64b323fe85f3a10fea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: teex-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 48.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 47da3d0336f1ac218497d637dd90fb43accfedf5cc5c4f2835d6c331ad22ddcd
MD5 02b406cbe2a9c8ed4312e2efdf4ea820
BLAKE2b-256 f8b9337960dc060b65a004057503edf737ad64d4e266109b55b06181d537df00

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