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

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.3.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.3-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: BiasBuster-0.0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 4214cc29f8b1c81d1faf45c0d49aceea1cb78fd9d5b7063aeb804c363d7ab65c
MD5 216acd8aa74513366e0a0b948464470f
BLAKE2b-256 3be99c58eb4e0501418f952a20872b331297d8ece523af5f8d00d52111166e28

See more details on using hashes here.

File details

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

File metadata

  • Download URL: BiasBuster-0.0.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d4a5cda610804ee12424011946607f0939291011612ccbfbbc1dccd4b79be334
MD5 4fc93e959ccd2c02cacb5cbd462d180b
BLAKE2b-256 0afb8a9dd79546483fa9e6387c0749cfc11ca6ce4bc099d134504faa87ab94bb

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