Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from aif360.datasets import BinaryLabelDataset
- from aif360.metrics import BinaryLabelDatasetMetric
- # Load your hiring data
- hiring_data = load_hiring_data() # Your function to load data
- # Create a BinaryLabelDataset
- dataset = BinaryLabelDataset(df=hiring_data,
- label_names=['hired'],
- protected_attribute_names=['gender'])
- # Compute metrics
- metric = BinaryLabelDatasetMetric(dataset,
- unprivileged_groups=[{'gender': 0}],
- privileged_groups=[{'gender': 1}])
- # Check for disparate impact
- di = metric.disparate_impact()
- print(f"Disparate Impact: {di}")
- # A value of 1.0 indicates no disparate impact
- # Values < 0.8 or > 1.25 may indicate bias
- # Check for statistical parity difference
- spd = metric.statistical_parity_difference()
- print(f"Statistical Parity Difference: {spd}")
- # A value close to 0 indicates similar selection rates across groups
Advertisement
Add Comment
Please, Sign In to add comment