Skip to main content

Fairness-constrained machine learning using Seldonian algorithms with confidence bound optimizations

Project description

Fair-Seldonian

Fairness-constrained machine learning with high-confidence guarantees

PyPI Python 3.10+ Build codecov License: MIT Docs PyPI Downloads Paper


A Python framework implementing the Quasi-Seldonian Algorithm (QSA) for training ML models that provably satisfy fairness constraints. Given a behavioral constraint and a confidence level δ, the algorithm either returns a model satisfying the constraint with probability ≥ 1 − δ, or returns No Solution Found — never an unsafe model.

Built on the Seldonian algorithm framework by Thomas et al. (2019), with extensions for tighter confidence bounds through constant-aware delta allocation, union bound optimization, and decomposed candidate-safety intervals.

Quick links

Documentation parulgupta1004.github.io/fair-seldonian
Repository github.com/parulgupta1004/fair-seldonian
Paper Thomas et al., Science 366 (2019) — doi:10.1126/science.aag3311

Installation

git clone https://github.com/parulgupta1004/fair-seldonian.git
cd fair-seldonian
uv sync                          # core dependencies
uv sync --extra experiments      # + Ray for parallel experiments
uv sync --extra plots            # + matplotlib for visualization

Or with pip:

pip install fair-seldonian
pip install "fair-seldonian[experiments,plots]"

Usage

from fair_seldonian.algorithms import QSA
from fair_seldonian.models import eval_ghat
from fair_seldonian.data import get_data, data_split

data = get_data(N=10000, features=5, t_ratio=0.4,
                tp0_ratio=0.4, tp1_ratio=0.6, random_seed=42)
X_te, Y_te, T_te, X_tr, Y_tr, T_tr = data_split(
    frac=0.5, All=data, random_state=1, mTest=0.2)

theta, theta1, passed = QSA(X_tr, Y_tr, T_tr, "opt", None, None)

if passed:
    print("Upper bound:", eval_ghat(theta, theta1, X_te, Y_te, T_te, "opt"))
else:
    print("No Solution Found")

Custom configuration:

from fair_seldonian.config import SeldonianConfig
from fair_seldonian.constraints.inequalities import Inequality

config = SeldonianConfig(delta=0.01, inequality=Inequality.T_TEST, candidate_ratio=0.5)
theta, theta1, passed = QSA(X_tr, Y_tr, T_tr, "opt", None, None, config)

Algorithm variants

Mode Description
base Standard Hoeffding bound, uniform δ-splitting
mod Decomposed candidate/safety estimation error
const Constant-aware δ allocation
bound Union bound optimization for repeated variables
opt All optimizations combined
uv run python -m fair_seldonian.experiments.runner opt
uv run python -m fair_seldonian.experiments.plots

Citation

@software{fair_seldonian,
  author = {Parul Gupta},
  title  = {Fair Seldonian Framework},
  year   = {2020}
}

This work builds on:

Thomas, P.S., da Silva, B.C., Barto, A.G., Giguere, S., Brun, Y., & Brunskill, E. (2019). "Preventing undesirable behavior of intelligent machines." Science, 366(6468), 999–1004.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines, or open an issue to get started.

Contributors

Thanks to everyone who has contributed to this project!

License

MIT


Author: Parul Gupta

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fair_seldonian-2.1.1.tar.gz (38.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fair_seldonian-2.1.1-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file fair_seldonian-2.1.1.tar.gz.

File metadata

  • Download URL: fair_seldonian-2.1.1.tar.gz
  • Upload date:
  • Size: 38.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fair_seldonian-2.1.1.tar.gz
Algorithm Hash digest
SHA256 dc7c668c9f3a01f6350a3d0e5ff7ea3d5467ed8cf82503de86a048521b4be4a9
MD5 4348358cccb999fd3128cbdf9340bbc1
BLAKE2b-256 686a5f5498d9e32223c2fab482651e6f779504c8de39c1ceaffb872ff5e13d65

See more details on using hashes here.

Provenance

The following attestation bundles were made for fair_seldonian-2.1.1.tar.gz:

Publisher: publish.yml on parulgupta1004/fair-seldonian

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fair_seldonian-2.1.1-py3-none-any.whl.

File metadata

  • Download URL: fair_seldonian-2.1.1-py3-none-any.whl
  • Upload date:
  • Size: 21.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fair_seldonian-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e4f50b1d046bb44596e876b8fb8ce001918be7f3385695aa0243736a6784f757
MD5 2c047c7631127ebe5b861caa3dc00ecd
BLAKE2b-256 6241684ccef782838df1b898e0485cbd7e3126e7347875457034d2e1744c24c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for fair_seldonian-2.1.1-py3-none-any.whl:

Publisher: publish.yml on parulgupta1004/fair-seldonian

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page