Welcome to CFXplorer’s documentation

Contents

Links: | GitHub repository | PyPI |

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.