datadabllp

check for gender bias

Jul 18th, 2024
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. from aif360.datasets import BinaryLabelDataset
  2. from aif360.metrics import BinaryLabelDatasetMetric
  3.  
  4. # Load your hiring data
  5. hiring_data = load_hiring_data()  # Your function to load data
  6.  
  7. # Create a BinaryLabelDataset
  8. dataset = BinaryLabelDataset(df=hiring_data,
  9.                              label_names=['hired'],
  10.                              protected_attribute_names=['gender'])
  11.  
  12. # Compute metrics
  13. metric = BinaryLabelDatasetMetric(dataset,
  14.                                   unprivileged_groups=[{'gender': 0}],
  15.                                   privileged_groups=[{'gender': 1}])
  16.  
  17. # Check for disparate impact
  18. di = metric.disparate_impact()
  19. print(f"Disparate Impact: {di}")
  20. # A value of 1.0 indicates no disparate impact
  21. # Values < 0.8 or > 1.25 may indicate bias
  22.  
  23. # Check for statistical parity difference
  24. spd = metric.statistical_parity_difference()
  25. print(f"Statistical Parity Difference: {spd}")
  26. # A value close to 0 indicates similar selection rates across groups
  27.  
Advertisement
Add Comment
Please, Sign In to add comment