forked from iosifidisvasileios/AdaFair
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Costs_EQOP.py
60 lines (44 loc) · 1.72 KB
/
Costs_EQOP.py
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
import matplotlib
import numpy
from AdaFairEQOP import AdaFairEQOP
from my_useful_functions import plot_costs_per_round_eqop
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import sys
sys.path.insert(0, 'DataPreprocessing')
from load_kdd import load_kdd
# from load_german import load_german
from load_compas_data import load_compas
from load_adult import load_adult
from load_bank import load_bank
def run_eval(dataset):
if dataset == "compass-gender":
X, y, sa_index, p_Group, x_control = load_compas("sex")
elif dataset == "compass-race":
X, y, sa_index, p_Group, x_control = load_compas("race")
elif dataset == "adult-gender":
X, y, sa_index, p_Group, x_control = load_adult("sex")
elif dataset == "bank":
X, y, sa_index, p_Group, x_control = load_bank()
elif dataset == "kdd":
X, y, sa_index, p_Group, x_control = load_kdd()
else:
exit(1)
base_learners = 200
no_cumul = train_classifier(X, y, sa_index, p_Group, 0, base_learners)
cumul = train_classifier(X, y, sa_index, p_Group, 1, base_learners)
plot_costs_per_round_eqop("Images/Costs/" + dataset, no_cumul, cumul)
def train_classifier(X_train, y_train, sa_index, p_Group, mode, base_learners):
if mode == 0:
classifier = AdaFairEQOP(n_estimators=base_learners, saIndex=sa_index, saValue=p_Group, CSB='CSB1', cumul=False)
elif mode == 1:
classifier = AdaFairEQOP(n_estimators=base_learners, saIndex=sa_index, saValue=p_Group, CSB='CSB1', cumul=True)
classifier.fit(X_train, y_train)
return classifier.costs
def main(dataset):
run_eval(dataset)
if __name__ == '__main__':
main("compass-gender")
main("adult-gender")
main("bank")
main("kdd")