Skip to main content

Measure bias from data and machine learning models.

Project description

Parity

This repository contains codes that demonstrate the use of fairness metrics, bias mitigations and explainability tool.

Installation

In order for the explainability modules to work, first you have to install shap through conda like so:

foo@bar:~$ conda install -c conda-forge shap

Install using:

foo@bar:~$ pip install parity-fairness

Bias Measurement Usage

Setup the data such that the target column is a binary string target. Then find out which features are the privileged categories and which values are privileged values. Afterwards, feed them into the function called show_bias like:

from parity.fairness_metrics import show_bias

priv_category = 'Race-White'
priv_value = 'True'
target_label = 'high pay'
unencoded_target_label = 'True'
cols_to_drop = ''

show_bias(data, priv_category, priv_value, target_label, unencoded_target_label, cols_to_drop)

Bias and Fairness

A common problem with most machine learning models is bias from data. This notebook shows how to measure those biases and perform bias mitigation. A python package called aif360 can give us metrics and algorithms for bias measurement and mitigation

Metrics

  • Statistical Parity Difference
  • Equal Opportunity Difference
  • Average Absolute Odds Difference
  • Disparate Impact
  • Theil Index

Some metrics need predictions while others just the original dataset. This is why we will use 2 classes of the aif360 package : ClassificationMetric and BinaryLabelDatasetMetric.

For metrics that require predictions:

For metrics that don't require predictions:

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

parity-fairness-0.1.19.tar.gz (13.5 kB view details)

Uploaded Source

File details

Details for the file parity-fairness-0.1.19.tar.gz.

File metadata

  • Download URL: parity-fairness-0.1.19.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.3.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.6

File hashes

Hashes for parity-fairness-0.1.19.tar.gz
Algorithm Hash digest
SHA256 bc3a33ce5fedf3e42645ba9237aedf3bcdfadfdc04f11ab5804d7d0db8e5b861
MD5 75056a7d2b30b3322e01bc380bd38185
BLAKE2b-256 cc18e1c01680af2e22147ab380665852daf455d7693ea7aa532770b9f33f62aa

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