The Fairness Object

The fairness object can be used to store all relevant parameters as well as run any of the metric functions listed below. It can be instantiated in the following way.

import pandas as pd
import numpy as np
from fairness_object import Fairness as Fairness

# Example DataFrame
data = [
    {'name': 'Alice', 'age': 25, 'gender': 'female', 'hired': True},
    {'name': 'Bob', 'age': 32, 'gender': 'male', 'hired': True},
    {'name': 'Charlie', 'age': 28, 'gender': 'male', 'hired': True},
    {'name': 'Dave', 'age': 22, 'gender': 'male', 'hired': False},
    {'name': 'Eve', 'age': 19, 'gender': 'female', 'hired': False},
    {'name': 'Frank', 'age': 37, 'gender': 'male', 'hired': True},
    {'name': 'Grace', 'age': 30, 'gender': 'female', 'hired': True},
    {'name': 'Henry', 'age': 41, 'gender': 'male', 'hired': True},
    {'name': 'Ivy', 'age': 26, 'gender': 'female', 'hired': False},
    {'name': 'John', 'age': 35, 'gender': 'male', 'hired': False},
]
data_true = [
    {'gender': 'female', 'hired': True},
    {'gender': 'male', 'hired': True},
    {'gender': 'male', 'hired': True},
    {'gender': 'male', 'hired': True},
    {'gender': 'female', 'hired': True},
    {'gender': 'male', 'hired': True},
    {'gender': 'female', 'hired': True},
    {'gender': 'male', 'hired': True},
    {'gender': 'female', 'hired': False},
    {'gender': 'male', 'hired': False},
]
df = pd.DataFrame(data)
y_true = pd.DataFrame(data_true)

protected_attribute = 'gender'
privileged_group = 'male'
labels = 'hired'
positive_label = True

# Creation of Fairness Object
fo = Fairness(df, protected_attribute, privileged_group, labels, positive_label, y_true)

Any and all metric functions can then be computed by using the compute() function as shown below:

fo.compute(positive_predictive_value)
(0.999999999975, 0.99999999995)

Keep in mind that the metric functions can also be computed manually as listed in each function's Markdown.


What’s Next