Skip to main content

FairOdds-AUC: A fairness-scaled AUROC metric that penalizes equalized odds gaps across sensitive attributes

Project description

FairOdds-AUC

FairOdds-AUC is a fairness-scaled AUROC metric that multiplicatively penalizes equalized-odds gaps across user-specified sensitive attributes. It enables a single, tunable score that balances utility and fairness via a nonnegative temperature parameter λ.

Formula:

  • FairOdds-AUC = AUROC / (1 + λ · GEO)
  • GEO = sum over sensitive attributes of Equalized Odds differences (per Fairlearn)

When λ = 0, the score reduces to AUROC. Larger λ puts more weight on fairness, discounting models with larger equalized-odds disparities.

Installation

pip install fairodds-auc

From source (editable):

pip install -U pip
pip install -e .

Quickstart

import numpy as np
from fairodds_auc import fair_odds_auc

y_true = np.array([0, 1, 0, 1, 0, 1])
y_score = np.array([0.1, 0.9, 0.3, 0.8, 0.2, 0.7])

# any attributes you care about
race = np.array(["A", "A", "B", "B", "A", "B"]) 
sex = np.array(["F", "M", "F", "M", "F", "M"])   

sensitive_features = {"race": race, "sex": sex}

score = fair_odds_auc(
    y_true=y_true,
    y_score=y_score,
    sensitive_features=sensitive_features,
    lambda_=1.0,
    threshold=0.5,
    agg="mean",  # or 'worst_case' to match Fairlearn default
)
print(score)

API

  • fair_odds_auc(y_true, y_score, sensitive_features, lambda_=1.0, threshold=0.5, method='between_groups', agg='mean', sample_weight=None) -> float
  • equalized_odds_gap(y_true, y_pred, group, method='between_groups', agg='mean', sample_weight=None) -> float
  • generalized_equalized_odds(y_true, y_pred, sensitive_features, method='between_groups', agg='mean', sample_weight=None) -> (dict, float)

Notes:

  • EO uses hard decisions y_pred from thresholding y_score.
  • EO is computed using fairlearn.metrics.equalized_odds_difference under the hood.
  • Pass sensitive_features as a single array-like or a dict of name->array-like.

References

  • Fong et al. (2022): Bias-penalized AUC (fairAUC)
  • Pfohl et al. (2021): Balancing performance and fairness in clinical ML
  • Dehdashtian et al. (2024): U-FaTE multi-objective framework

License

MIT

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

fairodds_auc-0.2.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

fairodds_auc-0.2.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file fairodds_auc-0.2.0.tar.gz.

File metadata

  • Download URL: fairodds_auc-0.2.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for fairodds_auc-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5db38b2a9628f41fb6489c79e33f6f301ab2e4cdbb951fbd442d2a8022ce673e
MD5 f4504fbdb6fedd4d05a1bcb1873801d9
BLAKE2b-256 68b08d9ba249724be20b7e69fc660e80c2e224e7d7c2e4611811d9130e1e5fb4

See more details on using hashes here.

File details

Details for the file fairodds_auc-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: fairodds_auc-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for fairodds_auc-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3b678f9eb933ffcc1315091059a19b1f118e78ffe4d3ecc8f03fb6e4f9dd7eac
MD5 8d985e2664b895d2d86782837bde2336
BLAKE2b-256 ab86786802c6ea0f07e7cf90321c336b5459ce0c987196354918d713f8d179ca

See more details on using hashes here.

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