Measure and mitigate what accuracy does not tell you about a model.
Documentation · Getting started · API reference · Gallery · Notebooks · holisticai.com
An open-source library for assessing and improving the safety aspects of AI systems. It answers five questions a validation accuracy cannot: does the model treat groups differently, can its decisions be accounted for, does it hold up under shift and attack, what does it leak about its training data, and is it actually effective. Each answer is a metric you can compute in a few lines against a scikit-learn-shaped model — and for bias, a mitigator you can drop into the pipeline that produced it.
pip install holisticaiThe base install carries scikit-learn, pandas, numpy and pyarrow — enough for every metric that needs nothing more. The heavier machinery is opt-in:
| Extra | Install | Adds |
|---|---|---|
| datasets | pip install holisticai[datasets] |
The dataset loaders, plus matplotlib and seaborn for every plot |
| bias | pip install holisticai[bias] |
The 28 bias mitigators — JAX, optax, flax and pygad |
| explainability | pip install holisticai[explainability] |
LIME and SHAP feature-importance backends |
| security | pip install holisticai[security] |
JAX and jaxopt for the privacy attacks |
| all | pip install holisticai[all] |
Everything above |
Needs Python 3.9 or newer. On macOS, the solvers behind some bias mitigators want a C toolchain first:
brew install cbc pkg-config cmake
python -m pip install cylpTrain anything with a fit/predict interface, then hand the predictions and
the group membership to a metrics report:
from holisticai.bias.metrics import classification_bias_metrics
from holisticai.bias.plots import bias_metrics_report
from holisticai.datasets import load_dataset
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import StandardScaler
# load a bundled dataset, split by a protected attribute
dataset = load_dataset("law_school", protected_attribute="race")
split = dataset.train_test_split(test_size=0.3)
train, test = split["train"], split["test"]
# train an ordinary model — the library makes no demands on it
scaler = StandardScaler()
model = LogisticRegression(random_state=42, max_iter=500)
model.fit(scaler.fit_transform(train["X"]), train["y"])
y_pred = model.predict(scaler.transform(test["X"]))
# every relevant bias metric, with a fair reference value for each
metrics = classification_bias_metrics(
group_a=test["group_a"],
group_b=test["group_b"],
y_true=test["y"],
y_pred=y_pred,
)
bias_metrics_report(model_type="binary_classification", table_metrics=metrics)holisticai.pipeline.Pipeline is scikit-learn's pipeline with a slot for a
mitigator. Group membership reaches it through bm__ prefixed arguments, so the
rest of your training code is unchanged:
from holisticai.bias.mitigation import Reweighing
from holisticai.pipeline import Pipeline
pipeline = Pipeline(
steps=[
("scaler", StandardScaler()),
("bm_preprocessing", Reweighing()),
("estimator", LogisticRegression()),
]
)
pipeline.fit(train["X"], train["y"], bm__group_a=train["group_a"], bm__group_b=train["group_b"])
y_pred = pipeline.predict(test["X"], bm__group_a=test["group_a"], bm__group_b=test["group_b"])Swap bm_preprocessing for bm_inprocessing or bm_postprocessing to mitigate
at a different stage. All 28 mitigators are listed under
bias mitigation.
| Vertical | What it answers | What it ships |
|---|---|---|
| Bias | Does the model treat groups differently? | 65 metrics across binary classification, multiclass, regression, clustering and recommendation · 28 mitigators, pre-, in- and post-processing · 20 plots |
| Explainability | Can its decisions be accounted for? | 32 metrics over global and local feature importance, surrogate models and decision trees · LIME and SHAP backends |
| Robustness | Does it hold up under shift and attack? | Adversarial accuracy, empirical robustness and accuracy-degradation profiles · 4 attackers — HopSkipJump, ZooAttack and two regression poisoners |
| Security | What does it leak about its training data? | 10 metrics — k-anonymity, l-diversity, SHAPr, privacy risk score, attribute-inference and data-minimization · anonymization mitigation |
| Efficacy | Is it actually effective? | Batch metric reports for classification, multiclass, regression and clustering |
Every metric is a plain function over arrays, and every batch report returns a pandas DataFrame — nothing here asks you to restructure your project around it.
load_dataset returns a Dataset already split into X, y, group_a and
group_b for a protected attribute you name, so an example is one line rather
than a preprocessing script. Files are pulled from
holistic-ai/holisticai-datasets
on first use and cached under ~/holisticai_data (HOLISTIC_AI_DATA moves it):
adult · law_school · student · student_multiclass · us_crime ·
us_crime_multiclass · german_credit · census_kdd · bank_marketing ·
compas_two_year_recid · compas_is_recid · diabetes · clinical_records ·
acsincome · acspublic · lastfm · mw_small · mw_medium
| Verticals | 5 — bias, explainability, robustness, security, efficacy |
| Metrics | 65 bias · 32 explainability · 10 security · 7 efficacy · 4 robustness |
| Mitigation | 28 bias mitigators · 1 anonymization mitigator · 4 attackers |
| Datasets | 18, fetched and cached on first use, split by protected attribute in one call |
| Base install | scikit-learn, pandas, numpy, pyarrow — the rest is opt-in |
| Python | 3.9+, tested on 3.9 in CI |
| Licence | Apache 2.0 |
tutorials/ holds runnable notebooks per vertical — measuring and
mitigating bias by task, measuring robustness and dataset shift, privacy
measurement and mitigation, explainability demos, efficacy, trade-off analysis
and MLflow integration. The same material, rendered, is the
example gallery.
git clone https://github.com/holistic-ai/holisticai
cd holisticai
pip install hatchTwo commands, both of which CI runs on every pull request. Get them passing before opening one:
hatch fmt --check # ruff lint and format, configured by ruff_default.toml
hatch run testing:run # pytest over tests/Docs are Sphinx with the pydata theme:
hatch run sphinx:build # builds docs/source into docs/buildCONTRIBUTING.md covers setting up an environment and what
makes a change easy to accept. Questions and ideas are welcome in
issues or on
Slack.
Apache License 2.0 — see LICENSE.
