Skip to main content

PyXAI - Python eXplainable AI

PyXAI

Documentation: http://www.cril.univ-artois.fr/pyxai/

Git: https://github.com/crillab/pyxai

PyXAI is a Python library (version 3.6 or later) allowing to bring explanations of various forms from classifiers resulting of machine learning techniques (Decision Tree, Random Forest, Boosted Tree).

More precisely, several types of explanations for the classification task of a given instance X can be computed:

  • Abductive explanations for 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).
  • 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).

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

  • Scikit-learn: a software machine learning library
  • XGBoost: an optimized distributed gradient boosting library

Note that it is quite possible to find explanations of models coming from other libraries.

As an illustration, below, you can find an example of use:

from pyxai import Learning, Explainer, Tools

learner = Learning.Scikitlearn("../dataset/iris.csv")
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("implicant:", 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))

Installation

Installation from PyPi

The Python Package Index (PyPi) is the easiest way of installing PyXAI.

Note that you need first Python 3 (version 3.6, or later) to be installed. You can do it, for example, from python.org

Installing PyXAI (Linux)

Check if 'python3-pip' is installed. If it is not the case, execute:

sudo apt install python3-pip

Or check if you have the last installed version:

python3 -m pip install --upgrade pip

Then, install PyXAI with the command 'pip3':

python3 -m pip install pyxai

Installing PyXAI (Mac OS)

PyXAI is currently compatible with Mac OS but without PyPi, see the installation (alternative) by Cloning from GitHub section for more details.

Installing PyXAI (Windows)

PyXAI is currently not compatible with windows (work in progress).

Updating the Version of PyXAI (for PyPi)

For updating your version of PyXAI, simply execute:

For linux/Mac:

python3 -m pip install -U pyxai

Installation (alternative) by Cloning from GitHub

An alternative to PyPi is to clone the code from GitHub.

Here is an illustration for linux. We assume that Python 3 is installed, and consequently 'pip3' is also installed. In a console, type:

git clone https://gitlab.univ-artois.fr/expekctation/software/PyLearningExplanation.git

You may need to update the environment variable 'PYTHONPATH', by typing for example:

export PYTHONPATH="${PYTHONPATH}:${PWD}/.."

Get the last version of pip:

python3 -m pip install --upgrade pip

There are a few packages that PyXAI depends on that must be installed:

python3 -m pip install numpy
python3 -m pip install wheel
python3 -m pip install pandas
python3 -m pip install termcolor
python3 -m pip install shap
python3 -m pip install wordfreq
python3 -m pip install python-sat[pblib,aiger]
python3 -m pip install xgboost
python3 -m pip install lxml
python3 -m pip install pycsp3
python3 -m pip install matplotlib

To compile the c++ code (python C extensions):

python3 setup.py install --user

Of course, for this step, you need a C++ compiler.

Unfortunately, the compiled C extensions are not take into account in a virtual environment, therefore you must type (we consider here that the virtual environment is in the 'env' directory and you are in the 'PyXAI' directory):

cp build/lib.linux-x86_64-3.6/c_explainer.cpython-36m-x86_64-linux-gnu.so env/lib/python3.6/site-packages/.

This last command depend of your python version (here: 3.6).

Finally, you can test an example:

python3 examples/DT/BuilderOrchids.py 

Virtual Environment

Create and activate a new virtual environment:

sudo apt-get install python3.6-venv
python3.6 -m venv env
source env/bin/activate

Update pip:

python3.6 -m pip install -U pip

With this new version of pip, it is possible that you have to clear the pip cache:

python3 -m pip cache purge

Now you can do the "Installation from PyPi" or the "Installation (alternative) by Cloning from GitHub".

Note that if you want install dependencies without internet connection, you can build a requirement.txt file:

python3.6 -m pip freeze > requirements.txt 
python3.6 -m pip download -r requirements.txt -d requirements-download/
pip install -r requirements.txt --find-links=requirements-download --no-index

For deactivating the environment:

deactivate

Release files for pyxai 0.8.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for pyxai 0.8.4
File
pyxai-0.8.4-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl PyPy 3.9 PyPy 3.9 7.3 Linux glibc 2.17+ x86-64 Details
pyxai-0.8.4-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl PyPy 3.8 PyPy 3.8 7.3 Linux glibc 2.17+ x86-64 Details
pyxai-0.8.4-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl PyPy 3.7 PyPy 3.7 7.3 Linux glibc 2.17+ x86-64 Details
pyxai-0.8.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
pyxai-0.8.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
pyxai-0.8.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details
pyxai-0.8.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details
pyxai-0.8.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64 Details
pyxai-0.8.4-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.17+ x86-64 Details

Total release size: 2.9 MB

Release files / pyxai-0.8.4-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pyxai-0.8.4-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 135.7 kB
Tags Linux glibc 2.17+ x86-64 PyPy 3.9 PyPy 3.9 7.3
SHA-256 checksum
How to use checksums
30e64ce300852bf6d7eb52f572e44046dac7af0d55ba9f855341e9c3f2fee6a0
BLAKE2b-256 checksum
How to use checksums
d7cfe11fbce0517595efe09fcdcf142135d29917466cf149a62415d30dd6e97e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.6.9

Release files / pyxai-0.8.4-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pyxai-0.8.4-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 135.9 kB
Tags Linux glibc 2.17+ x86-64 PyPy 3.8 PyPy 3.8 7.3
SHA-256 checksum
How to use checksums
5ee8444694a10d9829b3aa04d3f1049dd092c82b4ec37b69236621d9b4fcf6de
BLAKE2b-256 checksum
How to use checksums
d88d32740f51924a3e05dcc9b42b2e54dc6fca15c327e3b63f6b38fa824a583d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.6.9

Release files / pyxai-0.8.4-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pyxai-0.8.4-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 136.9 kB
Tags Linux glibc 2.17+ x86-64 PyPy 3.7 PyPy 3.7 7.3
SHA-256 checksum
How to use checksums
3cb313a095a033dd9ad5fdfd55f82c757005f8031079ed7bc8894676da75267c
BLAKE2b-256 checksum
How to use checksums
1a5d2354c85063676fa240c0fbb23bb735aef8cdccb742256a66fb5f8aec93da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.6.9

Release files / pyxai-0.8.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pyxai-0.8.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 424.6 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
cfbefc1e52a1cbbadd6973ae1f1404f94da090caacf35efd30f131b8136ccf37
BLAKE2b-256 checksum
How to use checksums
2c82df528881fddff820c2db0e42911222e11a1723a451a651a9591dd200e412
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.6.9

Release files / pyxai-0.8.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pyxai-0.8.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 423.9 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
d310d37b6e69eecb52d88ea7d8c61d8ad928d23909ba4f25161518481cbe0d11
BLAKE2b-256 checksum
How to use checksums
7f8bb454c2c88277e9e796e022f231ee7458f4e2b111e7a73c4b56f04c81fa77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.6.9

Release files / pyxai-0.8.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pyxai-0.8.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 423.4 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
d0fd16ffcbc26df3f017af5b82a9eeaf3a96400366b3265d895b4b533f4df4eb
BLAKE2b-256 checksum
How to use checksums
2cd1c4d380c2cfe45b341289450b3426287890445ee9b099b33fd5d16b11125d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.6.9

Release files / pyxai-0.8.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pyxai-0.8.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 422.4 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
ab7a823575c8f53f6c54455a776fa6fd78f962a15ae6f0a611bf509a8feda2d1
BLAKE2b-256 checksum
How to use checksums
d49a38862d97f6ff87d8f4b93740f6f9b57a866419c1f9507973d5aa6db0fd74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.6.9

Release files / pyxai-0.8.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pyxai-0.8.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 422.1 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
1dee6848015cceb4127bf8b714350c0c88f634563cd7289e88135b0d16cbd58d
BLAKE2b-256 checksum
How to use checksums
b1d9a8263f00878e9ebdae0472107d2b9807b7a100284ed66861c1954c7ee9ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.6.9

Release files / pyxai-0.8.4-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pyxai-0.8.4-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 419.7 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
34cceb44478710108a4384641c3af099ef2f360f589d556bef3931c3027939de
BLAKE2b-256 checksum
How to use checksums
c41be6d3356be68f334fbf9bed53119fb424b3fa06574ba5dd3e7691b0d96034
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.6.9
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page