Skip to main content

A Python package to check for algorithmic bias.

Project description

This package provides functions to test one's ML models bias.

BiasBuster package

The metrics are calculated by a slicing analysis. Four fairness metrics are supported: ABROCA, Equal Opportunity, Predictive Equality and Predictive Parity.

ABROCA: met, if both groups have equal Absolute Between ROC Area Equal Opportunity: met, if both groups have equal FNR Predictive Equality: met, if both groups have equal FPR Predictive Parity: met, if both groups have the same PPV

Installation

This package can be installed using pip. An installation with pip automatically downloads the latest version from PyPI:

pip install BiasBuster as bb

Example & Usage

Import the metric you'd like to use.

from abroca import abroca
from predictive_equality import predictive_equality
from predictive_parity import predictive_parity
from equal_opportunity import equal_opportunity

df = load_your_dataset

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
clf = DecisionTreeClassifier(criterion="entropy", splitter="best")
clf = clf.fit(X_train, y_train)

X_test_advantaged = X_test[X_test['group'] == 1]
y_test_advantaged = y_test[y_test['group'] == 1]

X_test_disadv = X_test[X_test['group'] == 0]
y_test_disadv =y_test[y_test['group'] == 0]


abroca = abroca.calculate_abroca(clf,X_test_advantaged,y_test_advantaged, X_test_disadv, y_test_disadv)
pe = predictive_equality.predictive_equality(clf,X_test_advantaged,y_test_advantaged, X_test_disadv, y_test_disadv)
pp = predictive_parity.calculate_predictive_parity(clf,X_test_advantaged,y_test_advantaged, X_test_disadv, y_test_disadv)
eo =equal_opportunity.calculate_equal_opportunity(clf,X_test_advantaged,y_test_advantaged, X_test_disadv, y_test_disadv)

print(abroca)

-0.005211848509902417

Interpretation

The threshold to delineate biased from unbiased depends on the underlying data. However, typical thresholds lie between 0.01 and 0.05.

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

BiasBuster-0.0.2.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

BiasBuster-0.0.2-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file BiasBuster-0.0.2.tar.gz.

File metadata

  • Download URL: BiasBuster-0.0.2.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.2

File hashes

Hashes for BiasBuster-0.0.2.tar.gz
Algorithm Hash digest
SHA256 034a16c014bb544989b7d352882d474e6b37fcbc4892f5b78e9a411f899654ff
MD5 ca78761bc34409015b9d79c7ceeee280
BLAKE2b-256 99ab6f2cfceacd5fe8ed31460b455b6d52d3c84e496f5394fe119389819abb83

See more details on using hashes here.

File details

Details for the file BiasBuster-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: BiasBuster-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.2

File hashes

Hashes for BiasBuster-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ce5a860f677d3cc081a30d539bf497e83e252781effde5dafd4cdd8cbae10a75
MD5 c5f622bebb66c8174368a9bc08d54bd4
BLAKE2b-256 80ce2b7ad1d3041398d80c7bba845f32517f3250b7221e28334d267b08bed6b3

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