Skip to main content

A new post-processing fairness algorithm that operates on the output probabilities of a binary classifier

Project description

Downstream Fairness

We implement the algorithm presented in Geometric Repair for Fair Classification at Any Decision Threshold. The algorithm looks at the scores, labels, and sensitive attribute in a dataset, and determines a set of adjustments. The original set of adjustments allow one to adjust the prediction probabilities of a binary classifier, and perturb them (by adding the appropriate adjustment to a prediction probability), so that you can achieve demographic parity. To achieve other fairness definitions, such as equalized odds and equal opportunity, our algorithm provides a lambda value. This lambda value is multiplied to each entry of the set of adjustments, and then those can be added to predictions. Here is a good way to think about it:

prediction_probability + adjustment_value # achieves demographic parity

prediction_probability + lambda_val * adjustment_value # achieves some fairness definition attached to the lambda value

Quickstart

First, please make sure to download our package. You can either do this from this repo via:

pip install -e .

or you can install it directly via pip:

pip install downstream_fairness

To get started, we recommend just running our get_bias_mitigator, so you can get a dictionary of lambda values and an adjustment table. To go more in-depth, we recommend going through our demo notebook.

from downstream_fairness.process import get_bias_mitigator

# Gets the adjustment table and lambdas
table, lambdas = get_bias_mitigator(YOUR_DATA, 
                                    sens_col=YOUR_SENSITIVE_ATTRIBUTE_COLUMN_NAME, 
                                    score_col=YOUR_PREDICTION_PROBABILTIY_COLUMN, 
                                    label_col=YOUR_LABEL_COLUMN)
                                    
# Adjusts the prediction probabilities on the fly
adjusted_scores = get_adusted_scores(table, 
                                     DATA_YOU_WANT_ADJUSTED, 
                                     YOUR_SENSITIVE_ATTRIBUTE_COLUMN_NAME,
                                     YOUR_PREDICTION_PROBABILTIY_COLUMN,
                                     lambdas[THE_METRIC_YOU_WANT])

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

downstream_fairness-0.1.1.tar.gz (14.4 kB view hashes)

Uploaded Source

Built Distribution

downstream_fairness-0.1.1-py3-none-any.whl (14.2 kB view hashes)

Uploaded Python 3

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