-
Notifications
You must be signed in to change notification settings - Fork 2
/
experiments.py
353 lines (320 loc) · 11.7 KB
/
experiments.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
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
import numpy as np
import pandas as pd
from pathlib import Path
from itertools import product
from lib.TabularDataset import dataset_params
def combinations(grid):
return list(dict(zip(grid.keys(), values)) for values in product(*grid.values()))
def get_hparams(experiment):
if experiment not in globals():
raise NotImplementedError
return globals()[experiment]().get_hparams()
def get_script_name(experiment):
if experiment not in globals():
raise NotImplementedError
return globals()[experiment].fname
#### write experiments here
class rule_depth_vary():
fname = 'run.py'
def __init__(self):
self.hparams = {
'experiment': ['rule_depth_vary_correct_replication'],
'dataset': ['adult','lsac','lsac_cat','mimic_tab_fair_ds','mimic_tab','compas_balanced'],
'blackbox_model': ['lr','nn'],
'explanation_type': ['global'],
'explanation_model': ['decision_tree'],
'n_features': [100],
'tree_depth':list(range(1,7)),
'train_grp_clf': [False],
'balance_groups':[False],
'grp_clf_attr':['all'],
'seed': [1,2,3,4,5] ,
'evaluate_val': [True],
'C':[1],
'model_type': ['sklearn']
}
def get_hparams(self):
return combinations(self.hparams)
class gam_max_iter_vary():
fname = 'run.py'
def __init__(self):
self.hparams = {
'experiment': ['gam_max_iter_vary_correct_replication'],
'dataset': ['adult','lsac','lsac_cat','mimic_tab_fair_ds','mimic_tab','compas_balanced'],
'blackbox_model': ['lr','nn'],
'explanation_type': ['global'],
'explanation_model': ['factor_gam'],#decision_tree
'n_features': [100],
'gam_max_iter':[100,200,500],
'train_grp_clf': [False],
'balance_groups':[False,True],
'seed': [1,2,3,4,5] ,
'evaluate_val': [True],
'grp_clf_attr':['all'],
'C':[1],
'model_type': ['sklearn']
}
def get_hparams(self):
return combinations(self.hparams)
class rule_balanced_gender():
fname = 'run.py'
def __init__(self):
self.hparams = {
'experiment': ['rule_balanced_correct_replication'],
'dataset': ['adult','mimic_tab'],
'blackbox_model': ['lr','nn'],
'explanation_type': ['global'],
'explanation_model':['decision_tree','balanced_tree'],
'n_features':[100],
'seed': [1,2,3,4,5],
'balance_groups':[True,False],
'balance_group_idx':[0],
'evaluate_val': [True],
'C':[1],
'tree_depth':list(range(1,7)),
'model_type': ['sklearn'],
'perturb_sigma':[1]#,5,10,15,20,25,100]
}
def get_hparams(self):
return combinations(self.hparams)
class rule_balanced_race():
fname = 'run.py'
def __init__(self):
self.hparams = {
'experiment': ['rule_balanced_correct_replication'],
'dataset': ['lsac','compas_balanced'],
'blackbox_model': ['lr','nn'],
'explanation_type': ['global'],
'explanation_model':['decision_tree','balanced_tree'],
'n_features':[100],
'seed': [1,2,3,4,5],
'balance_groups':[False,True],
'balance_group_idx':[1],
'evaluate_val': [True],
'C':[1],
'tree_depth':list(range(1,7)),
'model_type': ['sklearn'],
'perturb_sigma':[1]#,5,10,15,20,25,100]
}
def get_hparams(self):
return combinations(self.hparams)
class rule_vary_features():
fname = 'run.py'
def __init__(self):
self.hparams = {
'experiment': ['rule_vary_features_correct_replication'],
'dataset': ['mimic_tab','adult'],
'blackbox_model': ['lr','nn'],
'explanation_type': ['global'],
'explanation_model': ['factor_gam','decision_tree'],#,'decision_tree'
'n_features':[2,5,10,15,20,30,40,50,60],
'seed': [1,2,3,4,5],
'balance_groups':[False],
'evaluate_val': [True],
'tree_depth':[5],
'gam_max_iter':[100],
'model_type': ['sklearn'],
'perturb_sigma':[1]#,5,10,15,20,25,100]
}
def get_hparams(self):
return combinations(self.hparams)
class gam_balanced_gender():
fname = 'run.py'
def __init__(self):
self.hparams = {
'experiment': ['gam_balanced_correct_replication'],
'dataset': ['adult','mimic_tab'],
'blackbox_model': ['lr','nn'],
'explanation_type': ['global'],
'explanation_model':['factor_gam'],
'n_features':[100],
'seed': [1,2,3,4,5],
'balance_groups':[True],
'balance_group_idx':[0],
'evaluate_val': [True],
'C':[1],
'model_type': ['sklearn'],
'gam_max_iter':[100,200,500],
'perturb_sigma':[1]#,5,10,15,20,25,100]
}
def get_hparams(self):
return combinations(self.hparams)
class gam_balanced_race():
fname = 'run.py'
def __init__(self):
self.hparams = {
'experiment': ['gam_balanced_correct_replication'],
'dataset': ['lsac','compas_balanced'],
'blackbox_model': ['lr','nn'],
'explanation_type': ['global'],
'explanation_model':['factor_gam'],
'n_features':[100],
'seed': [1,2,3,4,5],
'balance_groups':[True],
'balance_group_idx':[1],
'evaluate_val': [True],
'C':[1],
'model_type': ['sklearn'],
'gam_max_iter':[100,200,500],
'perturb_sigma':[1]#,5,10,15,20,25,100]
}
def get_hparams(self):
return combinations(self.hparams)
# LIME
class lime_all():
fname = 'run.py'
def __init__(self):
self.hparams = {
'experiment': ['lime_all_correct_replication'],
'dataset': ['lsac_cat','adult','lsac','mimic_tab','compas_balanced'],
'blackbox_model': ['lr','nn'],
'explanation_type': ['local'],
'explanation_model':['shap_blackbox_preprocessed','lime'],
'n_features':[100],
'seed': [0,1,2,3,4,5],
'balance_groups':[False],
'grp_clf_attr':['all'],
'evaluate_val': [True],
'C':[1],
'model_type': ['sklearn'],
'perturb_sigma':[1]#,5,10,15,20,25,100]
}
def get_hparams(self):
return combinations(self.hparams)
class lime_balanced_gender():
fname = 'run.py'
def __init__(self):
self.hparams = {
'experiment': ['lime_balanced_correct_replication'],
'dataset': ['adult','mimic_tab'],
'blackbox_model': ['lr','nn'],
'explanation_type': ['local'],
'explanation_model':['shap_blackbox_preprocessed','lime'],# ['lime','shap_scaled','shap_not_transformed','shap_transformed'],
'n_features':[100],
'seed': [1,2,3,4,5],
'balance_groups':[True],
'balance_group_idx':[0],
'evaluate_val': [True],
'C':[1],
'model_type': ['sklearn'],
'perturb_sigma':[1]#,5,10,15,20,25,100]
}
def get_hparams(self):
return combinations(self.hparams)
class lime_balanced_race():
fname = 'run.py'
def __init__(self):
self.hparams = {
'experiment': ['lime_balanced_correct_replication'],
'dataset': ['lsac','recidivism','compas_balanced'],
'blackbox_model': ['lr','nn'],
'explanation_type': ['local'],
'explanation_model':['shap_blackbox_preprocessed','lime'],# ['lime','shap_scaled','shap_not_transformed','shap_transformed'],
'n_features':[100],
'seed': [1,2,3,4,5],
'balance_groups':[True],
'balance_group_idx':[1],
'evaluate_val': [True],
'C':[1],
'model_type': ['sklearn'],
'perturb_sigma':[1]#,5,10,15,20,25,100]
}
def get_hparams(self):
return combinations(self.hparams)
class lime_vary_sigma():
fname = 'run.py'
def __init__(self):
self.hparams = {
'experiment': ['lime_vary_sigma_correct_replication'],
'dataset': ['adult','lsac','compas_balanced','mimic_tab'],
'blackbox_model': ['lr','nn'],
'explanation_type': ['local'],
'explanation_model':['lime'],
'n_features':[100],
'seed': [1,2,3,4,5],
'balance_groups':[False],
'grp_clf_attr':['all'],
'evaluate_val': [True],
'C':[1],
'model_type': ['sklearn'],
'perturb_sigma':[0.001,0.01,0.1,0.5,5,10,20]
}
def get_hparams(self):
return combinations(self.hparams)
class lime_vary_features():
fname = 'run.py'
def __init__(self):
self.hparams = {
'experiment': ['lime_vary_features_correct_replication'],
'dataset': ['mimic_tab','adult'],
'blackbox_model': ['lr','nn'],
'explanation_type': ['local'],
'explanation_model': ['lime','shap_blackbox_preprocessed'],
'n_features':[2,5,10,15,20,30,40,50,60],
'seed': [1,2,3,4,5],
'balance_groups':[False],
'evaluate_val': [True],
'C':[1],
'blackbox_train_fair':[False],
'model_type': ['sklearn'],
'perturb_sigma':[1]#,5,10,15,20,25,100]
}
def get_hparams(self):
return combinations(self.hparams)
# JTT
class JTT_hyperparam_search():
fname = 'run.py'
def __init__(self):
self.hparams = {
'experiment': ['JTT'],
'dataset': ['adult', 'lsac','mimic_tab','compas_balanced'],
'blackbox_model': ['lr', 'nn'],
'explanation_type': ['local'],
'explanation_model': ['lime'],
'n_features': [100],
'seed': list(range(5)),
'model_type': ['JTT'],
'jtt_lambda': [5, 10, 50, 20, 100],
'C':[1],
'grp_clf_attr':['all'],
'balance_groups':[False],
'ignore_lime_weights': [False],
'evaluate_val': [True]
}
def get_hparams(self):
return combinations(self.hparams)
class JTT_mimic_hyperparam_search():
fname = 'run.py'
def __init__(self):
self.hparams = {
'experiment': ['JTT_mimic_lr'],
'dataset': ['mimic_tab'],
'blackbox_model': ['lr','nn'],
'explanation_type': ['local'],
'explanation_model': ['lime'],
'n_features': [100],
'seed': list(range(5)),
'model_type': ['JTT'],
'jtt_lambda': [5, 10, 50, 20, 100],
'jtt_thres':[0.5,0.6],
'C':[1,2,3],
'grp_clf_attr':['all'],
'balance_groups':[False],
'ignore_lime_weights': [False],
'evaluate_val': [True]
}
def get_hparams(self):
return combinations(self.hparams)
## Distances between subgroups
class DatasetDists():
fname = 'get_dataset_distances.py'
def __init__(self):
base_hparams = {
'experiment': ['dist'],
'dataset': list(dataset_params.keys()),
'dist_method': ['clf', 'mmd', 'wass', 'pca_mmd', 'pca_wass'],
'fairness_type': ['dp', 'eo_p', 'eo_n']
}
self.hparams_grid = combinations(base_hparams)
def get_hparams(self):
return self.hparams_grid