Skip to main content

Explaining Machine Learning Classifiers in Python

Project description

PyXAI - Python eXplainable AI

What is PyXAI ?

PyXAI (Python eXplainable AI) is a Python library (version 3.6 or later) allowing to bring explanations of various forms suited to (regression or classification) tree-based ML models (Decision Trees, Random Forests, Boosted Trees, ...). In contrast to many approaches to XAI (SHAP, Lime, ...), PyXAI algorithms are model-specific. Furthermore, PyXAI algorithms guarantee certain properties about the explanations generated, that can be of several types:

  • Abductive explanations for an instance $X$ are intended to explain why $X$ has been classified in the way it has been classified by the ML model (thus, addressing the “Why?” question). For the regression tasks, abductive explanations for $X$ are intended to explain why the regression value on $X$ is in a given interval.
  • Contrastive explanations for $X$ is to explain why $X$ has not been classified by the ML model as the user expected it (thus, addressing the “Why not?” question).

New features in version 1.0.0:

  • Regression for Boosted Trees with XGBoost or LightGBM
  • Adding Theories (knowledge about the dataset)
  • Easier model import (automatic detection of model types)
  • PyXAI's Graphical User Interface (GUI): displaying, loading and saving explanations.
  • Supports multiple image formats for imaging datasets
  • Supports data pre-processing (tool for preparing and cleansing a dataset)
  • Unit Tests with the unittest module
pyxai
PyXAI's main steps for producing explanations.
pyxai pyxai
PyXAI's Graphical User Interface (GUI) for visualizing explanations.

What is the difference between PyXAI and other methods ?

The most popular approaches (SHAP, Lime, ...) to XAI are model-agnostic, but do not offer any guarantees of rigor. A number of works have highlighted several misconceptions about informal approaches to XAI (see the related papers). Contrastingly, PyXAI algorithms rely on logic-based, model-precise approaches for computing explanations. Although formal explainability has a number of drawbacks, particularly in terms of the computational complexity of logical reasoning needed to derive explanations, steady progress has been made since its inception.

Which models can be explained with PyXAI ?

Models are the resulting objects of an experimental ML protocol through a chosen cross-validation method (for example, the result of a training phase on a classifier). Importantly, in PyXAI, there is a complete separation between the learning phase and the explaining phase: you produce/load/save models, and you find explanations for some instances given such models. Currently, with PyXAI, you can use methods to find explanations suited to different ML models for classification or regression tasks:

In addition to finding explanations, PyXAI also provides methods that perform operations (production, saving, loading) on models and instances. Currently, these methods are available for three ML libraries:

  • Scikit-learn: a software machine learning library
  • XGBoost: an optimized distributed gradient boosting library
  • LightGBM: a gradient boosting framework that uses tree based learning algorithms

It is possible to also leverage PyXAI to find explanations suited to models learned using other libraries.

What does this website offer ?

In this website, you can find all what you need to know about PyXAI, with more than 10 Jupyter Notebooks, including:

  • The installation guide and the quick start
  • About obtaining models:
  • About obtaining explanations:
    • The concepts of the PyXAI explainer module: Concepts
    • How to use a time limit? Time Limit
    • The PyXAI library offers the possibility to process user preferences (prefer some explanations to others or exclude some features): Preferences
    • Theories are knowledge about the dataset. PyXAI offers the possibility of encoding a theory when calculating explanations in order to avoid calculating impossible explanations: Theories
    • How to compute explanations for classification tasks? Explaining Classification
    • How to compute explanations for regression tasks? Explaining Regression
  • How to use the PyXAI's Graphical User Interface (GUI) for visualizing explanations?

How to use PyXAI ?

Here is an example (it comes from the Quick Start page):

PyXAI in action

from pyxai import Learning, Explainer

learner = Learning.Scikitlearn("tests/iris.csv", learner_type=Learning.CLASSIFICATION)
model = learner.evaluate(method=Learning.HOLD_OUT, output=Learning.DT)
instance, prediction = learner.get_instances(model, n=1, correct=True, predictions=[0])

explainer = Explainer.initialize(model, instance)
print("instance:", instance)
print("binary representation:", explainer.binary_representation)

sufficient_reason = explainer.sufficient_reason(n=1)
print("sufficient_reason:", sufficient_reason)
print("to_features:", explainer.to_features(sufficient_reason))

instance, prediction = learner.get_instances(model, n=1, correct=False)
explainer.set_instance(instance)
contrastive_reason = explainer.contrastive_reason()
print("contrastive reason", contrastive_reason)
print("to_features:", explainer.to_features(contrastive_reason, contrastive=True))

explainer.show()
pyxai

As illustrated by this example, with a few lines of code, PyXAI allows you to train a model, extract instances, and get explanations about the classifications made.



Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

pyxai-1.0.2-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.9 MB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pyxai-1.0.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.9 MB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pyxai-1.0.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.9 MB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pyxai-1.0.2-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.9 MB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pyxai-1.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.6 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

pyxai-1.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.6 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pyxai-1.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.6 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pyxai-1.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.6 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pyxai-1.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.6 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pyxai-1.0.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.6 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

pyxai-1.0.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.6 MB view details)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

File details

Details for the file pyxai-1.0.2-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyxai-1.0.2-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5e05aecbe66cd6a89b2e7a56b1a587016e064008e65b9a2183ec410155c4862f
MD5 6fa2c73873cd7c549cb8d9fb7ef092b9
BLAKE2b-256 779e6e0143a4938d22572c977b88eaa8688b6869f1af4839cab947045d441f9a

See more details on using hashes here.

File details

Details for the file pyxai-1.0.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyxai-1.0.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 529f676af07bdc97c47fd962a97a0b6cff955adebc29f8f837fe7cffad709f2a
MD5 37583bdc453758e3088d30ee0c9968ef
BLAKE2b-256 b58755f6704566a7968689b21946998c2fbe226d4acd08c6100c52e507aa01ef

See more details on using hashes here.

File details

Details for the file pyxai-1.0.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyxai-1.0.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7b5bf32ee6b97ca6e9ee39c12c0c40b403831dba492a4c2200d09d4a45616802
MD5 59e09a23c55eb241e2415d7142c7917c
BLAKE2b-256 01b6819439edcea6fd3d7753d2cb087fcd23dd69e97a7a693a9b491cef2e1a29

See more details on using hashes here.

File details

Details for the file pyxai-1.0.2-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyxai-1.0.2-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1a9d57e1b3b87932dc6e8a20f2426558b17103ae7bee34ccf469ad145a3d83b1
MD5 6734a7c26d9ad7a95fd186940d0e2e80
BLAKE2b-256 681798109943935a4f4e87b552b4da7db15d0e596e9053988d90170c608600e4

See more details on using hashes here.

File details

Details for the file pyxai-1.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyxai-1.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6e3dcff02f88841cf80026ea2543adb702f817946eb3d532efc3587e21cf4b1c
MD5 93e2c1d6a2a4e31e88a8f2aed3048e64
BLAKE2b-256 0a419098fc740f33e9080999c6971aec1bd7d9d920012c37c4d64045c970ced7

See more details on using hashes here.

File details

Details for the file pyxai-1.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyxai-1.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8ae0d29e2de0fff777f8585b4a390aef33fb14d6f1e372f1e85c41e9ca8b7aa8
MD5 d479dd088f9eb414d9f29d85c9bed1c7
BLAKE2b-256 80f0d5725dfdd67a21c1bbc31b581761302b2a3bf58e067ffffdd5dabade9ef6

See more details on using hashes here.

File details

Details for the file pyxai-1.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyxai-1.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1982c0d2ae41775cbbc441daa4cd901d196e4655e0f4bf02446cd85e4bc5bb64
MD5 bf8a1f3aa8ff13414a4d8ee3fc6b266b
BLAKE2b-256 60596d515ab47cc276668396c0ef2c761e59af35ab9985b8af41d881b4b3fad7

See more details on using hashes here.

File details

Details for the file pyxai-1.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyxai-1.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 089a1396634eeb3717878f92382fae43649b00d2fce6922121c61e40a92f1495
MD5 e726f8252c4d12ec76d91dcc2836d7b8
BLAKE2b-256 9319ec228383957617352c4734a9a1dd7f4843264a4794cc0de2b1a5a4f849dc

See more details on using hashes here.

File details

Details for the file pyxai-1.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyxai-1.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8d8751db2b1c873d4b0abeeec853f64765f55a91904661a71d129be67e29ec4f
MD5 14d5f95fd6db261c49f7d3a4a06e85d4
BLAKE2b-256 bf29493b4027fcbdb9a07f5d0e2da254eebce208b7bc4d0b9862154c08fee01c

See more details on using hashes here.

File details

Details for the file pyxai-1.0.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyxai-1.0.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5262b2aa8332e5e305e6b3d131e35a7e1b82ba5cf8679fd4abef81b409a49925
MD5 37f9d8a9ffc68f3f5c58c3fb68a2ad6a
BLAKE2b-256 2f7e12466556ea5f2a5b2dcfd21ba5103a2748351afe69fed0a7897317519d97

See more details on using hashes here.

File details

Details for the file pyxai-1.0.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyxai-1.0.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 62bad686aa0447e17eb83a4b24810f8594e8a20eff7f0cb0efa13492f59c7194
MD5 52961a9d9ae59605cd71b87c3d8f03ae
BLAKE2b-256 7097832ca0a2cf0e21e5a31cbae013bfae06869016de1e5faf48241cadd68376

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