Skip to main content

CFXplorer

Deployment & Documentation & Stats & License

PyPI version Documentation status Downloads Code Coverage Circle CI Maintainability pre-commit 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.

Before and After FOCUS was applied to the features from above example.

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;

License

This package is using the Apache License 2.0 license.

Metadata

Release files for CFXplorer 0.1.0

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

Source distribution (sdist)

Source distribution for CFXplorer 0.1.0
File Size Uploaded
CFXplorer-0.1.0.tar.gz 15.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for CFXplorer 0.1.0
File Interpreter ABI Platform
CFXplorer-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 32.3 kB

Release files / CFXplorer-0.1.0.tar.gz

Download URL CFXplorer-0.1.0.tar.gz
Size 15.6 kB
Tags Source
SHA-256 checksum
How to use checksums
76e0d5c35542863677154e67f8a332ec74b577b9f169fe35b05e617989275346
BLAKE2b-256 checksum
How to use checksums
33903e2b5b2d135c8913885048b42a680a80d25bfd5f442809a729a3fce31fb7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / CFXplorer-0.1.0-py3-none-any.whl

Download URL CFXplorer-0.1.0-py3-none-any.whl
Size 16.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
907f0a612a1871319946fcde9a4e96fedeef4d2aad3d3bae49a057037ac0a5f2
BLAKE2b-256 checksum
How to use checksums
5de3bfc9b4764b4dccdf90cfa3226b3c6f9e0d777d722fbb3f09162705e5fe12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17
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