-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReport_Results.py
More file actions
239 lines (192 loc) · 10.1 KB
/
Report_Results.py
File metadata and controls
239 lines (192 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
from Postprocessing import *
from utils import *
from datetime import datetime
import copy
def report_results(data):
begin = datetime.now()
print("Attempting to enforce demographic parity...")
demographic_parity_data, demographic_parity_thresholds = enforce_demographic_parity(copy.deepcopy(data), 0.02)
if demographic_parity_data is not None:
print("--------------------DEMOGRAPHIC PARITY RESULTS--------------------")
print("")
for group in demographic_parity_data.keys():
num_positive_predictions = get_num_predicted_positives(demographic_parity_data[group])
prob = num_positive_predictions / len(demographic_parity_data[group])
print("Probability of positive prediction for " + str(group) + ": " + str(prob))
print("")
for group in demographic_parity_data.keys():
accuracy = get_num_correct(demographic_parity_data[group]) / len(demographic_parity_data[group])
print("Accuracy for " + group + ": " + str(accuracy))
print("")
for group in demographic_parity_data.keys():
FPR = get_false_positive_rate(demographic_parity_data[group])
print("FPR for " + group + ": " + str(FPR))
print("")
for group in demographic_parity_data.keys():
FNR = get_false_negative_rate(demographic_parity_data[group])
print("FNR for " + group + ": " + str(FNR))
print("")
for group in demographic_parity_data.keys():
TPR = get_true_positive_rate(demographic_parity_data[group])
print("TPR for " + group + ": " + str(TPR))
print("")
for group in demographic_parity_data.keys():
TNR = get_true_negative_rate(demographic_parity_data[group])
print("TNR for " + group + ": " + str(TNR))
print("")
for group in demographic_parity_thresholds.keys():
print("Threshold for " + group + ": " + str(demographic_parity_thresholds[group]))
print("")
total_cost = apply_financials(demographic_parity_data)
print("Total cost: ")
print('${:,.0f}'.format(total_cost))
total_accuracy = get_total_accuracy(demographic_parity_data)
print("Total accuracy: " + str(total_accuracy))
print("-----------------------------------------------------------------")
print("")
print("Attempting to enforce equal opportunity...")
equal_opportunity_data, equal_opportunity_thresholds = enforce_equal_opportunity(copy.deepcopy(data), 0.01)
if equal_opportunity_data is not None:
print("--------------------EQUAL OPPORTUNITY RESULTS--------------------")
print("")
for group in equal_opportunity_data.keys():
accuracy = get_num_correct(equal_opportunity_data[group]) / len(equal_opportunity_data[group])
print("Accuracy for " + group + ": " + str(accuracy))
print("")
for group in equal_opportunity_data.keys():
FPR = get_false_positive_rate(equal_opportunity_data[group])
print("FPR for " + group + ": " + str(FPR))
print("")
for group in equal_opportunity_data.keys():
FNR = get_false_negative_rate(equal_opportunity_data[group])
print("FNR for " + group + ": " + str(FNR))
print("")
for group in equal_opportunity_data.keys():
TPR = get_true_positive_rate(equal_opportunity_data[group])
print("TPR for " + group + ": " + str(TPR))
print("")
for group in equal_opportunity_data.keys():
TNR = get_true_negative_rate(equal_opportunity_data[group])
print("TNR for " + group + ": " + str(TNR))
print("")
for group in equal_opportunity_thresholds.keys():
print("Threshold for " + group + ": " + str(equal_opportunity_thresholds[group]))
print("")
total_cost = apply_financials(equal_opportunity_data)
print("Total cost: ")
print('${:,.0f}'.format(total_cost))
total_accuracy = get_total_accuracy(equal_opportunity_data)
print("Total accuracy: " + str(total_accuracy))
print("-----------------------------------------------------------------")
print("")
print("Attempting to enforce maximum profit...")
max_profit_data, max_profit_thresholds = enforce_maximum_profit(copy.deepcopy(data))
if max_profit_data is not None:
print("--------------------MAXIMUM PROFIT RESULTS--------------------")
print("")
for group in max_profit_data.keys():
accuracy = get_num_correct(max_profit_data[group]) / len(max_profit_data[group])
print("Accuracy for " + group + ": " + str(accuracy))
print("")
for group in max_profit_data.keys():
FPR = get_false_positive_rate(max_profit_data[group])
print("FPR for " + group + ": " + str(FPR))
print("")
for group in max_profit_data.keys():
FNR = get_false_negative_rate(max_profit_data[group])
print("FNR for " + group + ": " + str(FNR))
print("")
for group in max_profit_data.keys():
TPR = get_true_positive_rate(max_profit_data[group])
print("TPR for " + group + ": " + str(TPR))
print("")
for group in max_profit_data.keys():
TNR = get_true_negative_rate(max_profit_data[group])
print("TNR for " + group + ": " + str(TNR))
print("")
for group in max_profit_thresholds.keys():
print("Threshold for " + group + ": " + str(max_profit_thresholds[group]))
print("")
total_cost = apply_financials(max_profit_data)
print("Total cost: ")
print('${:,.0f}'.format(total_cost))
total_accuracy = get_total_accuracy(max_profit_data)
print("Total accuracy: " + str(total_accuracy))
print("-----------------------------------------------------------------")
print("")
print("Attempting to enforce predictive parity...")
predictive_parity_data, predictive_parity_thresholds = enforce_predictive_parity(copy.deepcopy(data), 0.01)
if predictive_parity_data is not None:
print("--------------------PREDICTIVE PARITY RESULTS--------------------")
print("")
for group in predictive_parity_data.keys():
accuracy = get_num_correct(predictive_parity_data[group]) / len(predictive_parity_data[group])
print("Accuracy for " + group + ": " + str(accuracy))
print("")
for group in predictive_parity_data.keys():
PPV = get_positive_predictive_value(predictive_parity_data[group])
print("PPV for " + group + ": " + str(PPV))
print("")
for group in predictive_parity_data.keys():
FPR = get_false_positive_rate(predictive_parity_data[group])
print("FPR for " + group + ": " + str(FPR))
print("")
for group in predictive_parity_data.keys():
FNR = get_false_negative_rate(predictive_parity_data[group])
print("FNR for " + group + ": " + str(FNR))
print("")
for group in predictive_parity_data.keys():
TPR = get_true_positive_rate(predictive_parity_data[group])
print("TPR for " + group + ": " + str(TPR))
print("")
for group in predictive_parity_data.keys():
TNR = get_true_negative_rate(predictive_parity_data[group])
print("TNR for " + group + ": " + str(TNR))
print("")
for group in predictive_parity_thresholds.keys():
print("Threshold for " + group + ": " + str(predictive_parity_thresholds[group]))
print("")
total_cost = apply_financials(predictive_parity_data)
print("Total cost: ")
print('${:,.0f}'.format(total_cost))
total_accuracy = get_total_accuracy(predictive_parity_data)
print("Total accuracy: " + str(total_accuracy))
print("-----------------------------------------------------------------")
print("")
print("Attempting to enforce single threshold...")
single_threshold_data, single_thresholds = enforce_single_threshold(copy.deepcopy(data))
if single_threshold_data is not None:
print("--------------------SINGLE THRESHOLD RESULTS--------------------")
print("")
for group in single_threshold_data.keys():
accuracy = get_num_correct(single_threshold_data[group]) / len(single_threshold_data[group])
print("Accuracy for " + group + ": " + str(accuracy))
print("")
for group in single_threshold_data.keys():
FPR = get_false_positive_rate(single_threshold_data[group])
print("FPR for " + group + ": " + str(FPR))
print("")
for group in single_threshold_data.keys():
FNR = get_false_negative_rate(single_threshold_data[group])
print("FNR for " + group + ": " + str(FNR))
print("")
for group in single_threshold_data.keys():
TPR = get_true_positive_rate(single_threshold_data[group])
print("TPR for " + group + ": " + str(TPR))
print("")
for group in single_threshold_data.keys():
TNR = get_true_negative_rate(single_threshold_data[group])
print("TNR for " + group + ": " + str(TNR))
print("")
for group in single_thresholds.keys():
print("Threshold for " + group + ": " + str(single_thresholds[group]))
print("")
total_cost = apply_financials(single_threshold_data)
print("Total cost: ")
print('${:,.0f}'.format(total_cost))
total_accuracy = get_total_accuracy(single_threshold_data)
print("Total accuracy: " + str(total_accuracy))
print("-----------------------------------------------------------------")
end = datetime.now()
seconds = end-begin
print("Postprocessing took approximately: " + str(seconds) + " seconds")