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

File metadata

File hashes

Hashes for pyxai_experimental-1.1.1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 357473a52f410ca07b2509e2a620203b567d49403af270abd348ceacb2b4c915
MD5 0a81e419cf9f757d4851be59779762f1
BLAKE2b-256 7a1d2edb677ede339d43665483ec4d9fc30e3f1cfce428d5f9bf870f4deb9924

See more details on using hashes here.

File details

Details for the file pyxai_experimental-1.1.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyxai_experimental-1.1.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 115857e3cbf51498f9a29936605399cfd0461781698fda75abcc6c8238ea43c5
MD5 4ca50bc55c028a6ac73ad10fe385cf65
BLAKE2b-256 fe541c14b89664fea69e79af76f2595dfd37f24f96b785e7b8aa0f8e1da7fdd8

See more details on using hashes here.

File details

Details for the file pyxai_experimental-1.1.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyxai_experimental-1.1.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b3363cbff29fb5d8f0480aa9223fdb16553b7e3e065a798c58d51d59cc049d0c
MD5 c6156e9cf2ada4d39bc7ea5e9ffca945
BLAKE2b-256 bd32c120e0cd71b1b778c17d02233767cb5182ae75d759bf9333c2fef1e7a66e

See more details on using hashes here.

File details

Details for the file pyxai_experimental-1.1.1-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyxai_experimental-1.1.1-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ca4eb028e010c3b1b5ee59a0b03e0cfd9737b2a537243d4bec94b8438076682c
MD5 e497a2d279f72187f8cb6c49285ab9ec
BLAKE2b-256 abbb1e0c1d27b7c243d774523d1b15e169c8602bb3428fb3dcf22b49751dc9ac

See more details on using hashes here.

File details

Details for the file pyxai_experimental-1.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyxai_experimental-1.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 29b2a56d1108dd6a86f352c552e664f66c7a8a8542b94168fd468f6d6dfca3b6
MD5 cbc950f68f279a754927b31a98241e0f
BLAKE2b-256 49f40eb277fe350393a282ba62ee50a303086ad3585c5f7e95e3e537b1022d90

See more details on using hashes here.

File details

Details for the file pyxai_experimental-1.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyxai_experimental-1.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 361eb4a990d887440502976f3dbb0bf00c5b8f91b4a2dd3a8aeda40fbc268316
MD5 6fbe39580832615dc0bb7bb15711d0bd
BLAKE2b-256 d94beb42a5ec9c87103f148c94bf525d67ef70f644e4b4345b5fb3817be73fb5

See more details on using hashes here.

File details

Details for the file pyxai_experimental-1.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyxai_experimental-1.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 318a7040f6accc635f9f744488742ca7eccede7ca425ec3084524d64fe1b1d10
MD5 4e17c924b2d33b4d83a454ec32805e8a
BLAKE2b-256 c6220a6a8114fa93bcd957567981307aea1c935b0068ef46420c73587ccf3c25

See more details on using hashes here.

File details

Details for the file pyxai_experimental-1.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyxai_experimental-1.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8977e3e9d3957b06c69164acabdc158e1c36ceff71ad38aec062f57285301c7b
MD5 7615d01e695a53d3e864f3068f9bdedc
BLAKE2b-256 f45a5fd0fb37d21e470350be52b6f194814bd62436b159c07a600965af1ceaa2

See more details on using hashes here.

File details

Details for the file pyxai_experimental-1.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyxai_experimental-1.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4eb93b1b79e141c0fa9405657dbaba9e004b82efd2413aa02375a16ec4bb2c1d
MD5 c80340d09e289ddb13c7c182efd9eaa6
BLAKE2b-256 bb31d50081316b3ecd114a71c085d12c8c31c12319fbfc70db9f659e57bf8d40

See more details on using hashes here.

File details

Details for the file pyxai_experimental-1.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyxai_experimental-1.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7b8dd79a8396317b856b87c21310d63b43a25444b5f55cbca04594d71368d1ad
MD5 a78391ff04d4ffda32035d25523b3538
BLAKE2b-256 8c9a214d2752e1f8ee83f6cab246c7407b681e76056423e48eed58c7ef37a1b8

See more details on using hashes here.

File details

Details for the file pyxai_experimental-1.1.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyxai_experimental-1.1.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 014bf0fa9d4e8c7c520ea93adc2729cf2538313f5d9d6bb605e44d6fb4058dc3
MD5 c71412f03ce4af5dd834accb6ba47b16
BLAKE2b-256 8aaa3d528766258977e9483acbf0fde0fb3b827344c45d41e9f7d135a8bc6c59

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