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.3-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.3-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.3-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.3-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.3-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.3-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.3-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.3-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.3-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.3-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.3-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.3-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyxai-1.0.3-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 500741472aa5124c54dcf3f1a65f8da257bf50d6710c00ebef9de648db9927e1
MD5 52c70d2a50310308eda6e43b4eda2c38
BLAKE2b-256 4170820f42fb2d51985635ab20b7f81cc730d210de943d6eddb656ac73bc7bc3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyxai-1.0.3-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a80bfad5d6b163743d1ab471b500444a1ac2b9d0691b80213783858a38135618
MD5 58920c7aa68f43fd0432b597780a65c2
BLAKE2b-256 f63be8e83b72470aa1292858ac39de6ec8a829b8f69477914077a2b33f46ba06

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyxai-1.0.3-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 df599a44345299b46a94e279429cef9d4cb1dd9a8c1cf245f0f11496ecdb12d1
MD5 7268fc8410efce5662fadcf9c544ae57
BLAKE2b-256 939aedfa9ec6056f915e8a8fa31b7e83bca904b412e532f1c2336b812e4a5da3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyxai-1.0.3-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4a5ac68ad34047c112bcc52257b63407fa1f5c1ee631c1edd21be03d366d454c
MD5 51435a36d2e73edd5adc294f9195e178
BLAKE2b-256 d05672b7a05ea6eb55dcf1a5af4fc179c3b30eec24c6653783eec32db2849410

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyxai-1.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 05f01dce1541c62d8ca160ebe5944cbc59735bdbc201e120990ab4f924c7e869
MD5 2a725d32ceffa70d66351236fcdcc53b
BLAKE2b-256 56231bb5fb8e75fe1458c2af6f3913c07d9103bf1fe7cd21b9d2cdb6e1a8f0ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyxai-1.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f31532f9ded4b2fc47d43083455286ebed33bf54d3f90125f491a775296c4004
MD5 e57df151ff2d11c2d35850365873d9f4
BLAKE2b-256 6d26f2901c3f310ec81903270c3976bf779c88ec6426a61c97b0d0358ab2b971

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyxai-1.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a717a8872029811c45324b51ef93334858b0eac5a6fa3bb380910ce90730f9ce
MD5 d491e3c10205695240fb3d7205f2e4d1
BLAKE2b-256 f4e8a75f5e7d711dd596f4594e0e4d0538a69deb47556a94aaacc13bc25b4e3e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyxai-1.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 291262223e903c9a36406b16bbf6d0b191b449e8324856afa1cd469375cc844e
MD5 6537f1f59555aff472d01f082a4eb61a
BLAKE2b-256 722e83b019ae130791b0a948eb0bd1373de3b51791bb7161d8fcf46fbf2af229

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyxai-1.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fe11e9c41cef4d975d9c625bbe2a0c3a55929a8a61077d88923d1b0d92eb3620
MD5 109d5837a315b333bf32fdddecce69b0
BLAKE2b-256 2afed5d8bb81616b4c39bb9922929e9b2c9795176269b260399bfc32865f30c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyxai-1.0.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e10f83b5a9f8a93196c902f8363c6fe26557633e40f774dc597266d0d788562f
MD5 e5f8b5daabbbd4c4f746f5718c8bcb48
BLAKE2b-256 4d59aa0f9c70dfd2c4a12249acbb43ff04cd9b28eefa6b7695b328259935ffb3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyxai-1.0.3-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ffccd25fd37964dd2ac35e16141ab8dfab0d06dc60fb40626d0804273780d35b
MD5 8aebccf069da5cd16e69e66d46f40e43
BLAKE2b-256 d4808acf71a2a8fbfd251e9b8ac511845be22efba6e29c8a048bd70e8fa1b056

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