Spaces:
Running
Running
Zekun Wu
commited on
Commit
•
0c08540
1
Parent(s):
c00508a
update
Browse files- util/evaluation.py +8 -0
util/evaluation.py
CHANGED
@@ -16,6 +16,12 @@ def calculate_impact_ratio(selection_rates):
|
|
16 |
impact_ratios = {category: rate / most_selected_rate for category, rate in selection_rates.items()}
|
17 |
return impact_ratios
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
def calculate_four_fifths_rule(impact_ratios):
|
20 |
"""Calculate whether each category meets the four-fifths rule."""
|
21 |
adverse_impact = {category: (ratio < 0.8) for category, ratio in impact_ratios.items()}
|
@@ -84,6 +90,7 @@ def statistical_tests(data):
|
|
84 |
'Neutral': data['Neutral_Rank'].mean()
|
85 |
}
|
86 |
impact_ratios = calculate_impact_ratio(selection_rates)
|
|
|
87 |
adverse_impact = calculate_four_fifths_rule(impact_ratios)
|
88 |
|
89 |
# Friedman test
|
@@ -107,6 +114,7 @@ def statistical_tests(data):
|
|
107 |
**pairwise_results,
|
108 |
"Levene's Test for Equality of Variances": levene_results,
|
109 |
"Pairwise Comparisons of Variances": pairwise_variances,
|
|
|
110 |
"Impact Ratios": impact_ratios,
|
111 |
"Adverse Impact (Four-Fifths Rule)": adverse_impact,
|
112 |
}
|
|
|
16 |
impact_ratios = {category: rate / most_selected_rate for category, rate in selection_rates.items()}
|
17 |
return impact_ratios
|
18 |
|
19 |
+
def statistical_parity_difference(selection_rates):
|
20 |
+
"""Calculate statistical parity difference."""
|
21 |
+
most_selected_rate = max(selection_rates.values())
|
22 |
+
spd = {category: rate - most_selected_rate for category, rate in selection_rates.items()}
|
23 |
+
return spd
|
24 |
+
|
25 |
def calculate_four_fifths_rule(impact_ratios):
|
26 |
"""Calculate whether each category meets the four-fifths rule."""
|
27 |
adverse_impact = {category: (ratio < 0.8) for category, ratio in impact_ratios.items()}
|
|
|
90 |
'Neutral': data['Neutral_Rank'].mean()
|
91 |
}
|
92 |
impact_ratios = calculate_impact_ratio(selection_rates)
|
93 |
+
spd_result = statistical_parity_difference(selection_rates)
|
94 |
adverse_impact = calculate_four_fifths_rule(impact_ratios)
|
95 |
|
96 |
# Friedman test
|
|
|
114 |
**pairwise_results,
|
115 |
"Levene's Test for Equality of Variances": levene_results,
|
116 |
"Pairwise Comparisons of Variances": pairwise_variances,
|
117 |
+
"Statistical Parity Difference": spd_result,
|
118 |
"Impact Ratios": impact_ratios,
|
119 |
"Adverse Impact (Four-Fifths Rule)": adverse_impact,
|
120 |
}
|