Constrained, threshold-aware counterfactual explanations for tree ensembles (XGBoost, LightGBM, CatBoost, sklearn) on a bundled Rust genetic engine.
Project description
treecf
Constrained, threshold-aware counterfactual explanations for tree ensembles.
treecf answers the question: "what is the minimal, feasible change to this instance such
that the model's raw output lands in a target interval?" — for XGBoost, LightGBM, CatBoost
and scikit-learn tree ensembles.
Status: pre-release (v0.1). See the documentation for concepts and tutorials.
Why another counterfactual package?
- Tree-native and fast. Models are parsed into a shared tree IR; the constrained
genetic search runs on a bundled Rust core 44–58× faster than the equivalent numpy
implementation (see the "Backends and proofs" docs page; the pure-Python engine remains
available as
backend="python"), and every result is float-verified against the IR before it is returned. - Decision thresholds are first-class. Targets are intervals on the raw model output — custom probability cutoffs, regression targets, and whole rating-grade ladders in one call.
- Real-world constraints. Declarative layer for immutability, directionality, ranges,
one-hot consistency, and arbitrary linear inter-feature constraints such as
max_dpd_30d <= max_dpd_12m— compiled once, enforced by every backend. - Missing values are values. NaN can be a legitimate counterfactual state, with per-feature opt-in and explicit transition costs.
- Constraint mining. Candidate invariants are mined from data and presented for human review — never auto-applied.
Installation
pip install treecf # bundled Rust engine; numpy is the only Python dep
pip install "treecf[xgboost]" # model parsers as extras; JSON dumps work without them
pip install "treecf[viz]" # matplotlib plots
Quick look
from treecf import Explainer, Target, constraint, Freeze
exp = Explainer(
model="model.json", # native object or dump file
background=X_train_sample,
constraints=[
constraint("max_dpd_30d <= max_dpd_12m"),
Freeze("age_of_bureau_file"),
],
)
res = exp.explain(x, target=Target.probability(range=(0.0, 0.04)), seed=0)
License
MIT
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 Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file treecf-0.0.1.tar.gz.
File metadata
- Download URL: treecf-0.0.1.tar.gz
- Upload date:
- Size: 66.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24ba3e913c723867a9b0122330a70e5815df2269e904661384851601f1fff64e
|
|
| MD5 |
96c4ef8f5964c8d7d9426a7af928c118
|
|
| BLAKE2b-256 |
bc34fe2b56aaf88a70ddbe7cb8808c7b746dbbbc0eba4722675ff7971091ee04
|
Provenance
The following attestation bundles were made for treecf-0.0.1.tar.gz:
Publisher:
release.yml on wlazlod/treecf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
treecf-0.0.1.tar.gz -
Subject digest:
24ba3e913c723867a9b0122330a70e5815df2269e904661384851601f1fff64e - Sigstore transparency entry: 2158091002
- Sigstore integration time:
-
Permalink:
wlazlod/treecf@61fbd5898a6b19bcde0c0dd9a9aa767b08780f6b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/wlazlod
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@61fbd5898a6b19bcde0c0dd9a9aa767b08780f6b -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file treecf-0.0.1-cp311-abi3-win_amd64.whl.
File metadata
- Download URL: treecf-0.0.1-cp311-abi3-win_amd64.whl
- Upload date:
- Size: 323.8 kB
- Tags: CPython 3.11+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e95fb9f1a2d1ac82ad4f3586405bd87421934d138ddf566698cf7ae2b3378a07
|
|
| MD5 |
d58911fae24ab0790cbf70d549f48549
|
|
| BLAKE2b-256 |
a9a630540343f4b9288bb738ca6b9a5376e938fa69f1d34935514693d3f7abc4
|
Provenance
The following attestation bundles were made for treecf-0.0.1-cp311-abi3-win_amd64.whl:
Publisher:
release.yml on wlazlod/treecf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
treecf-0.0.1-cp311-abi3-win_amd64.whl -
Subject digest:
e95fb9f1a2d1ac82ad4f3586405bd87421934d138ddf566698cf7ae2b3378a07 - Sigstore transparency entry: 2158091061
- Sigstore integration time:
-
Permalink:
wlazlod/treecf@61fbd5898a6b19bcde0c0dd9a9aa767b08780f6b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/wlazlod
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@61fbd5898a6b19bcde0c0dd9a9aa767b08780f6b -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file treecf-0.0.1-cp311-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: treecf-0.0.1-cp311-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 653.2 kB
- Tags: CPython 3.11+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ccc480b553d644be2c6fd1bc7fd707baa78a5b2cde207804959283c369218d88
|
|
| MD5 |
a043a3b1e42f658cc4383b725921a71a
|
|
| BLAKE2b-256 |
109c867d0dfb6af5e49ed78a7dfb2a91b48ec4a56bb5c0698ca098b914243818
|
Provenance
The following attestation bundles were made for treecf-0.0.1-cp311-abi3-musllinux_1_2_x86_64.whl:
Publisher:
release.yml on wlazlod/treecf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
treecf-0.0.1-cp311-abi3-musllinux_1_2_x86_64.whl -
Subject digest:
ccc480b553d644be2c6fd1bc7fd707baa78a5b2cde207804959283c369218d88 - Sigstore transparency entry: 2158091088
- Sigstore integration time:
-
Permalink:
wlazlod/treecf@61fbd5898a6b19bcde0c0dd9a9aa767b08780f6b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/wlazlod
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@61fbd5898a6b19bcde0c0dd9a9aa767b08780f6b -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file treecf-0.0.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: treecf-0.0.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 441.8 kB
- Tags: CPython 3.11+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ce3634bd1dfa6754e8c0d3af3d970838a8b6d53d108d26a70b378923bc7c2c8
|
|
| MD5 |
c2a0c6b9145cbbd5e18fbc316de88165
|
|
| BLAKE2b-256 |
a3d5d0ef280a3b0a99adb1025e4fbdfcedefa7091bacb3cbac5708b13d255b5b
|
Provenance
The following attestation bundles were made for treecf-0.0.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on wlazlod/treecf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
treecf-0.0.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
2ce3634bd1dfa6754e8c0d3af3d970838a8b6d53d108d26a70b378923bc7c2c8 - Sigstore transparency entry: 2158091154
- Sigstore integration time:
-
Permalink:
wlazlod/treecf@61fbd5898a6b19bcde0c0dd9a9aa767b08780f6b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/wlazlod
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@61fbd5898a6b19bcde0c0dd9a9aa767b08780f6b -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file treecf-0.0.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: treecf-0.0.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 431.7 kB
- Tags: CPython 3.11+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32fd1d7c69d39a3bced5b40bd30508465d97b0dbec52e1a7433bdd03e4eca593
|
|
| MD5 |
a655a6fbbcb02d167af4f4f1d8c41841
|
|
| BLAKE2b-256 |
2ed471203a05a56e4c257ffdff030d79e37d93a59fa747ca58858fe5d09dde46
|
Provenance
The following attestation bundles were made for treecf-0.0.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
release.yml on wlazlod/treecf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
treecf-0.0.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
32fd1d7c69d39a3bced5b40bd30508465d97b0dbec52e1a7433bdd03e4eca593 - Sigstore transparency entry: 2158091131
- Sigstore integration time:
-
Permalink:
wlazlod/treecf@61fbd5898a6b19bcde0c0dd9a9aa767b08780f6b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/wlazlod
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@61fbd5898a6b19bcde0c0dd9a9aa767b08780f6b -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file treecf-0.0.1-cp311-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: treecf-0.0.1-cp311-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 401.3 kB
- Tags: CPython 3.11+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d65a783d7e2bed8f213185e17578d12e0cbb4ad4bc7bff747318243010f08d8
|
|
| MD5 |
285ac78ecd93f66cc2971caffad35b1f
|
|
| BLAKE2b-256 |
8930b9a9940a8e81543bdc1ede25d3f5af981b2ef0964a827d55225d05dc3001
|
Provenance
The following attestation bundles were made for treecf-0.0.1-cp311-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on wlazlod/treecf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
treecf-0.0.1-cp311-abi3-macosx_11_0_arm64.whl -
Subject digest:
2d65a783d7e2bed8f213185e17578d12e0cbb4ad4bc7bff747318243010f08d8 - Sigstore transparency entry: 2158091014
- Sigstore integration time:
-
Permalink:
wlazlod/treecf@61fbd5898a6b19bcde0c0dd9a9aa767b08780f6b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/wlazlod
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@61fbd5898a6b19bcde0c0dd9a9aa767b08780f6b -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file treecf-0.0.1-cp311-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: treecf-0.0.1-cp311-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 410.2 kB
- Tags: CPython 3.11+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3a074445ae16e87d537bb918e8e09239cf191b349b4262cf5e9bb7e55a0d66f
|
|
| MD5 |
0537a919a5787eb39bc213686ddd3e51
|
|
| BLAKE2b-256 |
6a73c88245c664d41c7093fa5ced6c4becd99f62288bce85f8150b63a4e73f9a
|
Provenance
The following attestation bundles were made for treecf-0.0.1-cp311-abi3-macosx_10_12_x86_64.whl:
Publisher:
release.yml on wlazlod/treecf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
treecf-0.0.1-cp311-abi3-macosx_10_12_x86_64.whl -
Subject digest:
e3a074445ae16e87d537bb918e8e09239cf191b349b4262cf5e9bb7e55a0d66f - Sigstore transparency entry: 2158091032
- Sigstore integration time:
-
Permalink:
wlazlod/treecf@61fbd5898a6b19bcde0c0dd9a9aa767b08780f6b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/wlazlod
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@61fbd5898a6b19bcde0c0dd9a9aa767b08780f6b -
Trigger Event:
workflow_dispatch
-
Statement type: