Metadata-Version: 2.4
Name: MitigateYourBias
Version: 0.1.0
Summary: Find bias in model decisions, reduce it, and write the EU AI Act evidence report
Author-email: Ilias Driouich <ilias.driouich@amadeus.com>, Hongliu Cao <hongliu.cao@amadeus.com>
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/AmadeusITGroup/MitigateYourBias
Project-URL: Repository, https://github.com/AmadeusITGroup/MitigateYourBias
Project-URL: Bug Tracker, https://github.com/AmadeusITGroup/MitigateYourBias/issues
Project-URL: Changelog, https://github.com/AmadeusITGroup/MitigateYourBias/blob/main/CHANGELOG.md
Keywords: fairness,bias-detection,bias-mitigation,responsible-ai,eu-ai-act,ai-compliance,machine-learning,streamlit,trustworthy-ai
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.23
Requires-Dist: pandas>=1.5
Requires-Dist: scikit-learn>=1.2
Requires-Dist: streamlit>=1.35
Requires-Dist: openai>=1.70.0
Requires-Dist: python-dotenv>=1.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: black>=22.0.0; extra == "dev"
Requires-Dist: ruff>=0.1.0; extra == "dev"
Requires-Dist: build>=1.0.0; extra == "dev"
Requires-Dist: twine>=5.0.0; extra == "dev"
Dynamic: license-file

# MitigateYourBias

[![PyPI](https://img.shields.io/pypi/v/MitigateYourBias)](https://pypi.org/project/MitigateYourBias/) [![CI](https://github.com/AmadeusITGroup/MitigateYourBias/actions/workflows/ci.yml/badge.svg)](https://github.com/AmadeusITGroup/MitigateYourBias/actions/workflows/ci.yml) [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE) [![Python](https://img.shields.io/pypi/pyversions/MitigateYourBias)](https://pypi.org/project/MitigateYourBias/)

Find bias in model decisions, reduce it, and get a short evidence report for the EU AI Act.

## Objective

Fairness libraries tell you a number. Auditors ask for a document. We built this to close that gap: point it at a table of decisions and a few protected columns, and it measures the gaps, applies a simple fix, and writes down what changed and which AI Act article each result speaks to.

## Install

```bash
pip install MitigateYourBias
```

Python 3.10 or newer.

## Try it in 30 seconds

```bash
mitigate-your-bias demo      # hiring example, prints before and after, writes ./mitigate_report/
mitigate-your-bias app       # opens the Streamlit app at http://localhost:8501
```

The demo output looks like this:

```
Fairness criterion : demographic_parity
Mitigation         : reweighing (preprocessing), Kamiran & Calders 2012, KAIS
Accuracy           : 0.76 -> 0.7545 (change -0.0055)
  * demographic_parity_difference     0.1615 -> 0.1036  (change -0.0579)
    disparate_impact_ratio            0.4848 -> 0.6085  (change +0.1237)
```

The gap shrinks a lot, and it is still slightly above the 0.1 limit. We left that in on purpose. A mitigation helps, it does not promise a pass.

## What you get

Four commands: `demo` runs a built-in example (`hiring_screening` or `travel_assistant`), `run` does the same on your own CSV, `app` starts the Streamlit app, and `explain` writes a plain-language summary of a report.

For your own data: `mitigate-your-bias run --input decisions.csv --label y_true --sensitive sex,age_group`. Add `--pred y_pred` if the CSV already has your model's predictions. Otherwise it trains a small logistic regression on the numeric columns.

The app has four tabs. Demo runs an example. Your data loads a CSV and shows outcome rates per group. Mitigate applies the fix to that data. Evidence and explain shows the report, lets you download it, and can summarise it in plain words.

It does not train your production model, handle images or text, or tell you whether your system is legal. It checks group fairness on tabular decisions, and it picks one method per run: reweighing for demographic parity, per-group thresholds for equal opportunity.

## Optional: plain-language explanations

`explain` and `--explain` use an Azure OpenAI deployment of gpt-4.1-mini. Copy `.env.example` to `.env` and set `AZURE_OPENAI_API_KEY`, `AZURE_OPENAI_ENDPOINT`, `AZURE_OPENAI_API_VERSION` and `MODEL_DEPLOYMENT_NAME`. Only the metrics are sent, never the rows of your data. Without these settings the tool prints a short note and carries on.

## EU AI Act, in one paragraph

Article 10 asks providers of high-risk systems to examine their data for bias and to deal with it. Article 15 asks for accurate, dependable systems, including consistent performance across groups. The evidence report lists each metric with its definition, threshold, result and the article it supports, plus the fairness criterion chosen and why, the before and after values, a data hash and a timestamp. It supports your compliance work and is not legal advice.

## Development

```bash
git clone git@github.com:AmadeusITGroup/MitigateYourBias.git
cd MitigateYourBias
pip install -e ".[dev]"
pytest -q
```

## License and authors

Apache-2.0, see [LICENSE](LICENSE). Written by Ilias Driouich and Hongliu Cao at Amadeus.
