Skip to main content

Achieve error-rate parity between protected groups for any predictor

Project description

error-parity

Tests status PyPI status Documentation status PyPI version OSI license Python compatibility

Work presented as an oral at ICLR 2024, titled "Unprocessing Seven Years of Algorithmic Fairness".

Fast postprocessing of any score-based predictor to meet fairness criteria.

The error-parity package can achieve strict or relaxed fairness constraint fulfillment, which can be useful to compare ML models at equal fairness levels.

Package documentation available here.

Installing

Install package from PyPI:

pip install error-parity

Or, for development, you can clone the repo and install from local sources:

git clone https://github.com/socialfoundations/error-parity.git
pip install ./error-parity

Getting started

See detailed example notebooks under the examples folder.

from error_parity import RelaxedThresholdOptimizer

# Given any trained model that outputs real-valued scores
fair_clf = RelaxedThresholdOptimizer(
    predictor=lambda X: model.predict_proba(X)[:, -1],   # for sklearn API
    # predictor=model,            # use this for a callable model
    constraint="equalized_odds",  # other constraints are available
    tolerance=0.05,               # fairness constraint tolerance
)

# Fit the fairness adjustment on some data
# This will find the optimal _fair classifier_
fair_clf.fit(X=X, y=y, group=group)

# Now you can use `fair_clf` as any other classifier
# You have to provide group information to compute fair predictions
y_pred_test = fair_clf(X=X_test, group=group_test)

How it works

Given a callable score-based predictor (i.e., y_pred = predictor(X)), and some (X, Y, S) data to fit, RelaxedThresholdOptimizer will:

  1. Compute group-specific ROC curves and their convex hulls;
  2. Compute the r-relaxed optimal solution for the chosen fairness criterion (using cvxpy);
  3. Find the set of group-specific binary classifiers that match the optimal solution found.
    • each group-specific classifier is made up of (possibly randomized) group-specific thresholds over the given predictor;
    • if a group's ROC point is in the interior of its ROC curve, partial randomization of its predictions may be necessary.

Features and implementation road-map

We welcome community contributions for cvxpy implementations of other fairness constraints.

Currently implemented fairness constraints:

  • equality of odds (Hardt et al., 2016);
    • i.e., equal group-specific TPR and FPR;
    • use constraint="equalized_odds";
  • equal opportunity;
    • i.e., equal group-specific TPR;
    • use constraint="true_positive_rate_parity";
  • predictive equality;
    • i.e., equal group-specific FPR;
    • use constraint="false_positive_rate_parity";
  • demographic parity;
    • i.e., equal group-specific predicted prevalence;
    • use constraint="demographic_parity";

Citing

@inproceedings{
  cruz2024unprocessing,
  title={Unprocessing Seven Years of Algorithmic Fairness},
  author={Andr{\'e} Cruz and Moritz Hardt},
  booktitle={The Twelfth International Conference on Learning Representations},
  year={2024},
  url={https://openreview.net/forum?id=jr03SfWsBS}
}

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

error-parity-0.3.9.tar.gz (37.3 kB view details)

Uploaded Source

Built Distribution

error_parity-0.3.9-py3-none-any.whl (40.6 kB view details)

Uploaded Python 3

File details

Details for the file error-parity-0.3.9.tar.gz.

File metadata

  • Download URL: error-parity-0.3.9.tar.gz
  • Upload date:
  • Size: 37.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for error-parity-0.3.9.tar.gz
Algorithm Hash digest
SHA256 4197dc92ce0dbd0cf3d2f556252a6f10f50812650873d8ec2816bd299a148c95
MD5 2db65ae1bac426b6d6f9d6d944ac9e5a
BLAKE2b-256 32d6ebb5b99a62633441b0b4548ff1f91167a76a04565aaf7ba8a0fe3fce4d45

See more details on using hashes here.

File details

Details for the file error_parity-0.3.9-py3-none-any.whl.

File metadata

  • Download URL: error_parity-0.3.9-py3-none-any.whl
  • Upload date:
  • Size: 40.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for error_parity-0.3.9-py3-none-any.whl
Algorithm Hash digest
SHA256 a61970e4f096e4f15d0ef076ba6100f33995391c5696fe7fbc739455773f3240
MD5 dd54be54d06a54377cb9759177608f65
BLAKE2b-256 437c409e4bedc892e7f08d0b2bad13e4e504e4d0077db48439cd266b4d00d7cd

See more details on using hashes here.

Supported by

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