-
Notifications
You must be signed in to change notification settings - Fork 3
/
benchmark_adult.py
71 lines (61 loc) · 3.08 KB
/
benchmark_adult.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
from data.adult.process_data import save_rules, save_rules_with_pretrain
from plot import enumplot
from laundryML import LaundryML
import numpy as np
from sklearn.externals.joblib import Parallel, delayed
import time
import os
# experiments paramaters
params = {
'original_dataset_path' : './original/adult.csv',
'experiment_name' : 'global',
'data_prefix' : 'adult',
'test_prefix' : '',
'res_folder' : 'res_rf',
'k' : 10,
'opt' : '-c 2 -p 1',
'rho' : 0.0,
'beta' : 0.0,
'metric' : 1,
'maj_pos' : 1,
'min_pos' : 2,
'sensitve_attr' : 'gender:Female',
'non_sensitve_attr' : 'gender:Male',
'decision_attr' : 'income',
'betas' :[0.0, 0.1, 0.2, 0.5, 0.7, 0.9],
'metrics' : [1,2,3,4],
'lambdas' : [0.005, 0.01],
'pretrain' : True,
'bbox' : '_rfModel.dump'
}
def create_rules(data_prefix, original_dataset_path):
os.chdir('./data/%s' % data_prefix)
save_rules(original_dataset_path)
os.chdir('../..')
def create_rules_with_pretrain(data_prefix, original_dataset_path, model):
os.chdir('./data/%s' % data_prefix)
save_rules_with_pretrain(original_dataset_path, model)
os.chdir('../..')
def bench(experiment_name=params['experiment_name'], data_prefix=params['data_prefix'], test_prefix=params['test_prefix'], res_folder=params['res_folder'], k=params['k'], opt=params['opt'], rho=params['rho'], beta=params['beta'], metric=params['metric'], maj_pos=params['maj_pos'], min_pos=params['min_pos'], sensitve_attr=params['sensitve_attr'], non_sensitve_attr=params['non_sensitve_attr'], decision_attr=params['decision_attr']):
exp_prefix= experiment_name + '/lambda=' + str(rho) + '__' + 'beta='+ str(beta) + '__' + 'metric='+ str(metric)
print("-"*30, exp_prefix)
os.makedirs('./%s/%s/%s' %(res_folder, data_prefix, exp_prefix), exist_ok=True)
lml = LaundryML(data_prefix, test_prefix, exp_prefix, res_folder, k, opt, rho, beta, metric, maj_pos, min_pos, sensitve_attr, non_sensitve_attr, decision_attr)
lml.run()
if params['pretrain']:
create_rules_with_pretrain(data_prefix=params['data_prefix'], original_dataset_path=params['original_dataset_path'], model=params['bbox'])
else:
create_rules(data_prefix=params['data_prefix'], original_dataset_path=params['original_dataset_path'])
time.sleep(35)
# searching for rationalization models
for _metric in params['metrics']:
for _lambdak in params['lambdas']:
Parallel(n_jobs=-1)(delayed(bench)(beta=_beta, rho=_lambdak, metric=_metric) for _beta in params['betas'])
# plotting results
for _metric in params['metrics']:
for _lambdak in params['lambdas']:
for _beta in params['betas']:
exp_prefix= params['experiment_name'] + '/lambda=' + str(_lambdak) + '__' + 'beta='+ str(_beta) + '__' + 'metric='+ str(_metric)
print("="*30, exp_prefix)
enumplot(params['res_folder'], params['data_prefix'], exp_prefix)
#get_audit(data_prefix, exp_prefix)