-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exp-Comparative.py
95 lines (68 loc) · 2.46 KB
/
Exp-Comparative.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
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
# %%
import experiment_utils
import pandas as pd
import pickle
from pathlib import Path
# %% [markdown]
# # COMPAS Dataset
# %%
dataset = 'compas'
fair_feature = 'race'
X = pd.read_pickle("data/"+dataset+"_"+fair_feature+"/X.pickle")
with open("data/"+dataset+"_"+fair_feature+"/y.pickle", 'rb') as f:
y = pickle.load(f)
X_ftest = pd.read_pickle("data/"+dataset+"_"+fair_feature+"/X_ftest.pickle")
with open("data/"+dataset+"_"+fair_feature+"/y_ftest.pickle", 'rb') as f:
y_ftest = pickle.load(f)
# %%
kfold_results_compas = experiment_utils.kfold_methods(X, y, X_ftest, y_ftest,
fair_feature, n_folds = 5)
# %%
results_mean_compas = kfold_results_compas.groupby('Approach').mean()
Path("results/exp_comparative").mkdir(parents=True, exist_ok=True)
results_mean_compas.to_csv('results/exp_comparative/compas.csv')
print(results_mean_compas.to_latex())
# %%
results_mean_compas
# %% [markdown]
# # German Dataset
# %%
dataset = 'german'
fair_feature = 'sex'
X = pd.read_pickle("data/"+dataset+"_"+fair_feature+"/X.pickle")
with open("data/"+dataset+"_"+fair_feature+"/y.pickle", 'rb') as f:
y = pickle.load(f)
X_ftest = pd.read_pickle("data/"+dataset+"_"+fair_feature+"/X_ftest.pickle")
with open("data/"+dataset+"_"+fair_feature+"/y_ftest.pickle", 'rb') as f:
y_ftest = pickle.load(f)
# %%
kfold_results = experiment_utils.kfold_methods(X, y, X_ftest, y_ftest,
fair_feature, n_folds = 5, remove_trivial=True)
# %%
german_results_mean = kfold_results.groupby('Approach').mean()
german_results_mean.to_csv('results/exp_comparative/german.csv')
print(german_results_mean.to_latex())
# %%
german_results_mean
# %% [markdown]
# # Adult Dataset
# %%
dataset = 'adult'
fair_feature = 'race'
X = pd.read_pickle("data/"+dataset+"_"+fair_feature+"/X.pickle")
with open("data/"+dataset+"_"+fair_feature+"/y.pickle", 'rb') as f:
y = pickle.load(f)
X_ftest = pd.read_pickle("data/"+dataset+"_"+fair_feature+"/X_ftest.pickle")
with open("data/"+dataset+"_"+fair_feature+"/y_ftest.pickle", 'rb') as f:
y_ftest = pickle.load(f)
# %%
kfold_results = experiment_utils.kfold_methods(X, y, X_ftest, y_ftest,
fair_feature, n_folds = 5)
# %%
adult_results_mean = kfold_results.groupby('Approach').mean()
# %%
adult_results_mean
# %%
adult_results_mean.to_csv('results/exp_comparative/adult.csv')
print(adult_results_mean.to_latex())
# %%