Skip to main content

CertIFI: Certifiably Intersectionally Fair & Interpretable models

certifi-learn finds the most biased subgroup in data or in a model's predictions, and trains interpretable classifiers (linear models and rule sets) that are certifiably fair on all intersectional subgroups, for example all combinations of sex, race and age group.

Features

  • Bias detection. Find the subgroup with the largest violation of

    • Subgroup Discrepancy / MSD,
    • Statistical Parity Subgroup Fairness (SPSF),
    • False Positive Subgroup Fairness (FPSF).

    Subgroups can be

    • conjunctions of protected attribute values (e.g. SEX = Female AND RAC1P = Black). The exact search is fast, needs no solver, and its result is proven optimal.
    • linear threshold functions of the protected attributes, found by MIO.
  • Fair training. Linear classifiers and DNFs (rule sets), trained to optimality under the constraint that every subgroup has bias at most γ. Fairness constraints are generated lazily: only the subgroups that are actually violated are added, so there's no need to enumerate the exponentially many subgroups.

  • A scikit-learn-style API that works with pandas DataFrames. Categorical features are encoded automatically.

Installation

pip install "certifi-learn[gurobi]"

Prebuilt wheels are available for Linux, macOS and Windows (Python 3.9+). To install the latest version from GitHub instead, you need a Rust toolchain:

pip install "certifi-learn[gurobi] @ git+https://github.com/Epanemu/CertIFI"

Optional dependencies (extras):

Extra Needed for
gurobi Training classifiers (Gurobi lazy-constraint callbacks) and MIO detection. Requires a Gurobi license, free for academic use.
highs MIO detection with the open-source HiGHS solver, an alternative to Gurobi
mio Pyomo only, if you bring your own solver installation
examples The folktables example

Bias detection on conjunction subgroups needs no extras.

Quickstart

Finding the most biased subgroup

from certifi_learn import find_subgroup
from certifi_learn.encoding import TabularEncoder

# protected: DataFrame of protected attributes, y: binary labels, y_pred: model predictions
enc = TabularEncoder(protected)                 # binarizes into literals like "SEX = Female"
P = enc.binary(protected, negations=False)
names = enc.binary_names(negations=False)

# bias in the data: subgroup whose share differs most between positive and negative labels
sg = find_subgroup(P, y, measure="msd")
print(f"MSD = {sg.value:.3f}, proven optimal: {sg.optimal}")
print(sg.describe(names))
# e.g., on ACS Income (examples/detect_and_train.py):
#   MSD = 0.194, proven optimal: True
#   AGEP between [17, 24.2)

# certify that no subgroup has bias above a threshold
sg = find_subgroup(P, y, measure="msd", gamma=0.25)   # None: no subgroup has MSD > 0.25

# bias of a classifier
sg = find_subgroup(P, y_pred, measure="fpsf", y_true=y)

# also allow negated literals, e.g. "NOT RAC1P = White"
sg = find_subgroup(P, y_pred, measure="spsf", negations=True)

# linear subgroups (MIO, requires a solver)
sg = find_subgroup(P, y_pred, measure="spsf", subgroups="linear", solver="highs", time_limit=300)

find_subgroup returns a DetectedSubgroup with the violation value (of the chosen measure, on the given data), the membership mask, optimal (whether the subgroup is proven to be the most biased), and describe() / contains(X_new). If you pass gamma=..., it returns a subgroup only if one violates the threshold, and None otherwise. That None certifies γ-fairness, unless a warning reports that the search was stopped by the time limit.

Training a fair classifier

from certifi_learn import FairLinearClassifier, FairDNFClassifier

clf = FairLinearClassifier(gamma=0.01, measure="fpsf", time_limit=600)
clf.fit(X, y, X_protected)          # X may include the protected attributes
y_pred = clf.predict(X_test)

print(clf.n_cuts_)                   # number of subgroups constrained during training
print(clf.describe_cut_subgroups())  # which ones

rules = FairDNFClassifier(n_terms=3, gamma=0.01, measure="fpsf").fit(X, y, X_protected)
print(rules.describe())

Common parameters:

Parameter Values
measure "fpsf", "fpsf_by_sd" (FPSF constraints, with violating subgroups found by maximizing Subgroup Discrepancy on negative samples), "spsf", "msd", or None (no fairness constraint)
subgroups "conjunction" or "linear"
subgroup_negations Also allow negated literals in conjunction subgroups (e.g. RAC1P != White), which constrains a larger set of subgroups. Default False.
gamma Fairness threshold. Every subgroup must have bias ≤ γ on the training data.
detection_backend "exact" (default) or "mio", for finding violating conjunction subgroups. Linear subgroups always use MIO.
time_limit Solver time limit in seconds. The best solution found so far is returned.

Model-specific parameters:

Model Parameter Values
FairLinearClassifier sparsity Weight of the penalty on the proportion of non-zero coefficients (default 0)
FairDNFClassifier n_terms Number of terms (rules) of the DNF (default 3)

γ-fairness is guaranteed on the training data. On new data, the bias can be somewhat higher. Audit your model on held-out data with find_subgroup.

Bias measures

For a classifier h and a subgroup S:

Measure Definition
SPSF P(S) · |P(h=1) − P(h=1 | S)|
FPSF P(S, y=0) · |P(h=1 | y=0) − P(h=1 | S, y=0)|
SD / MSD |P(S | y=1) − P(S | y=0)|, i.e. how differently S is represented among positive and negative samples. Maximized over conjunctions, this is the Maximum Subgroup Discrepancy.

certifi_learn.measures evaluates these for a given subgroup mask. certifi_learn.exact exposes the Rust search directly (msd, spsf, fpsf), with options such as sample weights, negated literals and grouped one-hot columns. See docs/subgroup_pruning_proof.tex for the algorithm and its proof of correctness.

Example

examples/detect_and_train.py runs end to end on the US Census data (ACS Income, via folktables). It finds the most biased subgroup in the data, trains an unconstrained and a fair linear model, and audits both on test data:

pip install "certifi-learn[gurobi,examples]"
python examples/detect_and_train.py

Development

pip install -e ".[gurobi,highs,test,examples]"   # builds the Rust extension
pytest

Tests that need HiGHS or a Gurobi license are skipped if those are not available.

Citation

@inproceedings{nemecek2026intersectional,
 author = {N\v{e}me\v{c}ek, Ji\v{r}\'{\i} and Kozdoba, Mark and Kryvoviaz, Illia and Pevn\'{y}, Tom\'{a}\v{s} and Mare\v{c}ek, Jakub},
 booktitle = {Advances in Neural Information Processing Systems},
 title = {Intersectional Fairness via Mixed-Integer Optimization},
 volume = {39, Main Conference},
 year = {2026}
}

License

MIT

Metadata

Release files for certifi-learn 0.2.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 certifi-learn 0.2.0
File Size Uploaded Provenance Actions
certifi_learn-0.2.0.tar.gz 67.8 kB With provenance Details for certifi_learn-0.2.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for certifi-learn 0.2.0
File Actions
certifi_learn-0.2.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for certifi_learn-0.2.0-cp39-abi3-win_amd64.whl
certifi_learn-0.2.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for certifi_learn-0.2.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
certifi_learn-0.2.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for certifi_learn-0.2.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
certifi_learn-0.2.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for certifi_learn-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
certifi_learn-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for certifi_learn-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 1.4 MB

Release files / certifi_learn-0.2.0.tar.gz

Download URL certifi_learn-0.2.0.tar.gz
Size 67.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5f8d41d5320137486f521d2f2b31279dbbfde1ee0415b7f08eb104ba2f30d706
BLAKE2b-256 checksum
How to use checksums
1bc33a351e7891bf0e5b162a28badfd687334426e1cd6b163df0b8c5599a0d06
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

Release files / certifi_learn-0.2.0-cp39-abi3-win_amd64.whl

Download URL certifi_learn-0.2.0-cp39-abi3-win_amd64.whl
Size 198.6 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
aa48e3b35c1c93c7ec8aeffcaa926af8e6b7e4f20111cd4f63aa0fbd64206ce2
BLAKE2b-256 checksum
How to use checksums
48e2bd1414048c7577e8a972734348f8707926ac6768851cb06beca206951f9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

Release files / certifi_learn-0.2.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL certifi_learn-0.2.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 301.0 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
d2b71de1c08af28992bc6975ace5f3f931866a8a9fea024c8d9d3686c2c1f43b
BLAKE2b-256 checksum
How to use checksums
731214ec7ac3f568546778702f9f2844b8fb02aa0d39963db372c9fa82aa49da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

Release files / certifi_learn-0.2.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL certifi_learn-0.2.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 300.0 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
ae175437ca867826afb388763d747d017f987e3ba6cb50387c16fffe8b9b7182
BLAKE2b-256 checksum
How to use checksums
86c848fdfe924385a73a16d33fa983a3f2e9ab6e01dda564d75c281e86bd0228
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

Release files / certifi_learn-0.2.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL certifi_learn-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
Size 284.7 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a428e460eb34defe2b03318bd7724b097d2fdd2f03744e616a81a2aa45d2feaf
BLAKE2b-256 checksum
How to use checksums
715d26fd6dc1a404a1dbe39c08815e20ccacbcf09b2814d06458fcff8907f419
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

Release files / certifi_learn-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL certifi_learn-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 293.3 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
1779df6b44a1fcb59729b1dc1ab126cbe1324699b5554396f35d5b693d32ec38
BLAKE2b-256 checksum
How to use checksums
3e2f860b02fcd0640bd96595e5f7858e5a979aea9386a8b3c82bbacdef64cea7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

Security for certifi-learn 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for certifi_learn-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

6 release files Full provenance

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