Skip to main content

Achieve error-rate parity between protected groups for any predictor

Project description

error-parity

Tests status PyPI status PyPI version OSI license Python compatibility

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.

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/AndreFCruz/error-parity.git
pip install ./error-parity

Getting started

from error_parity import RelaxedEqualOdds

# Given any trained model that outputs real-valued scores
fair_clf = RelaxedEqualOdds(
    predictor=lambda X: model.predict_proba(X)[:, -1],   # for sklearn API
    # predictor=model,  # use this for a callable model
    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, RelaxedEqualOdds 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.

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;

Road-map:

  • equal opportunity;
    • i.e., equal group-specific TPR;
  • demographic parity;
    • i.e., equal group-specific predicted prevalence;

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.1.0.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

error_parity-0.1.0-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: error-parity-0.1.0.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for error-parity-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5cce57285b12ee5d236760ed90b3184400fbfd027a804ef79edc324f21ce1f9a
MD5 36301f3833e8b9f999a22e84200d69ac
BLAKE2b-256 af27d372c228365fe9a48fa993c461e96bee44bd55a9be1c1d44e1c82a78f70c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for error_parity-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b4238807e54d1dd9a5f923c3854242ccedf14e5890ea4044fe6a42c15b2ab20f
MD5 74b9af23722e50d8d3fa7591678f2367
BLAKE2b-256 28b14f9a7b80c9f28c21b3b1d23aa8d864ac49fac9da36b33c35c9422c45150c

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