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).
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
- Python 3.6+
- numpy>=1.19.1
- tensorflow>=2.0.0
- scikit-learn>=1.0.2
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)
- 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.
- Currently, Focus class can only be applied to scikit-learn
DecisionTreeClassifier
,RandomForestClassifier
andAdaBoostClassifier
. - 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.
The documentation can be found here.
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
This package is using the Apache License 2.0 license.