CFXplorer is a python package for generating counterfactual explanations for given model and feature set
Project description
Deployment & Documentation & Stats & License
CFXplorer generates optimal distance counterfactual explanations of the original data for the instances in tree‐based machine learning models.
This package is an implementation of FOCUS: Flexible Optimizable Counterfactual Explanations for Tree Ensembles (Lucic, et at. 2022).
Installation
It is recommended to use pip or conda for installation. Please make sure the latest version is installed:
pip install CFXplorer # normal install
pip install --upgrade CFXplorer # or update if needed
conda install -c conda-forge CFXplorer
Requirements
Python 3.6+
numpy>=1.19.1
tensorflow>=2.0.0
scikit-learn>=1.0.2
Usage
FOCUS counterfactual explanation generation with 3 Lines of Code:
from cfxplorer import Focus
# Initialize Focus instance with default values
focus = Focus()
# Generate counterfactual explanations for given tree model and features
pertubed = focus.generate(tree_model, X)
Examples
Comprehensive examples can be found in the examples folder.
Kaggle notebook example can be found here.
Below is demonstrated a comparison of before and after Focus is applied to feature set from the example given above.
Limitations of Focus class
Currently, Focus class can only be applied to scikit-learn DecisionTreeClassifier, RandomForestClassifier and AdaBoostClassifier.
While categorical features may be included in the feature set, it is important to note that the interpretation of changes in categorical features, such as transitioning from age 40 to 20, may not provide meaningful insights.
The input features should be scaled to the range of 0 and 1 before applying Focus. Therefore, it is necessary to transform the features prior to using Focus. However, this scaling process may introduce some additional complexity when interpreting the features after applying Focus.
Documentation
The documentation can be found here.
Contributing
If you would like to contribute to the project, please refer to;
ISSUE_TEMPLATE for raising an issue
PULL_REQUEST_TEMPLATE.md for raising a PR
License
This package is using the Apache License 2.0 license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file CFXplorer-0.1.0.tar.gz
.
File metadata
- Download URL: CFXplorer-0.1.0.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76e0d5c35542863677154e67f8a332ec74b577b9f169fe35b05e617989275346 |
|
MD5 | 4ae929d4d02a338fb832604372071d20 |
|
BLAKE2b-256 | 33903e2b5b2d135c8913885048b42a680a80d25bfd5f442809a729a3fce31fb7 |
File details
Details for the file CFXplorer-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: CFXplorer-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 907f0a612a1871319946fcde9a4e96fedeef4d2aad3d3bae49a057037ac0a5f2 |
|
MD5 | b96c3a4cfe60568adde331086e455a54 |
|
BLAKE2b-256 | 5de3bfc9b4764b4dccdf90cfa3226b3c6f9e0d777d722fbb3f09162705e5fe12 |