mariamSoub commited on
Commit
4104189
·
verified ·
1 Parent(s): 51bc233

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -19
app.py CHANGED
@@ -486,38 +486,39 @@ def analyze_response(user_response):
486
 
487
  # Calculate fairness metrics if enough samples
488
  fairness_metrics = ""
489
- if len(ALL_Y_TRUE) > 1:
490
- dpd = demographic_parity_difference(
491
- ALL_Y_TRUE, ALL_Y_PRED, sensitive_features=ALL_GROUPS
492
- )
493
- dpr = demographic_parity_ratio(
494
- ALL_Y_TRUE, ALL_Y_PRED, sensitive_features=ALL_GROUPS
495
- )
496
- if np.isnan(dpr) or dpr == 0:
497
- dpr = 0.01
 
498
 
499
- eod = equalized_odds_difference(
500
- ALL_Y_TRUE, ALL_Y_PRED, sensitive_features=ALL_GROUPS
501
- )
502
 
503
 
504
- explanation = explain_fairness_metrics(dpd, dpr, eod)
505
 
506
 
507
- fairness_metrics = f"""
508
  === FAIRNESS METRICS ===
509
  DPD: {dpd:.2f}
510
  DPR: {dpr:.2f}
511
  EOD: {eod:.2f}
512
  Samples collected: {len(ALL_Y_TRUE)}
513
 
514
- {overall}
515
 
516
  --- What this means ---
517
- {explanation}
518
- """
519
- else:
520
- fairness_metrics = "Not enough samples for fairness metrics."
521
 
522
  # Mitigation
523
 
 
486
 
487
  # Calculate fairness metrics if enough samples
488
  fairness_metrics = ""
489
+
490
+ if len(ALL_Y_TRUE) > 1:
491
+ dpd = demographic_parity_difference(
492
+ ALL_Y_TRUE, ALL_Y_PRED, sensitive_features=ALL_GROUPS
493
+ )
494
+ dpr = demographic_parity_ratio(
495
+ ALL_Y_TRUE, ALL_Y_PRED, sensitive_features=ALL_GROUPS
496
+ )
497
+ if np.isnan(dpr) or dpr == 0:
498
+ dpr = 0.01
499
 
500
+ eod = equalized_odds_difference(
501
+ ALL_Y_TRUE, ALL_Y_PRED, sensitive_features=ALL_GROUPS
502
+ )
503
 
504
 
505
+ explanation = explain_fairness_metrics(dpd, dpr, eod)
506
 
507
 
508
+ fairness_metrics = f"""
509
  === FAIRNESS METRICS ===
510
  DPD: {dpd:.2f}
511
  DPR: {dpr:.2f}
512
  EOD: {eod:.2f}
513
  Samples collected: {len(ALL_Y_TRUE)}
514
 
515
+ {overall}
516
 
517
  --- What this means ---
518
+ {explanation}
519
+ """
520
+ else:
521
+ fairness_metrics = "Not enough samples for fairness metrics."
522
 
523
  # Mitigation
524