-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimportance.py
More file actions
72 lines (67 loc) · 1.68 KB
/
Copy pathimportance.py
File metadata and controls
72 lines (67 loc) · 1.68 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
import argparse
import logging
from experiments import AnalysisExperiment
from items.datasets import Communities, Adult, Census
log = logging.getLogger("lightning_fabric")
log.propagate = False
log.setLevel(logging.ERROR)
# list all the valid datasets
datasets = dict(
communities=Communities(),
adult=Adult(),
census=Census()
)
# build argument parser
parser = argparse.ArgumentParser(description='Leverages HGR to compute the importance of features')
parser.add_argument(
'-f',
'--folder',
type=str,
default='results',
help='the path where to search and store the results and the exports'
)
parser.add_argument(
'-d',
'--datasets',
type=str,
nargs='+',
choices=list(datasets),
default=['communities', 'adult', 'census'],
help='the datasets on which to run the experiment'
)
parser.add_argument(
'-on',
'--on',
type=str,
choices=['protected', 'target', 'both'],
default='both',
help='the variable with respect to which the importance is computed'
)
parser.add_argument(
'-t',
'--top',
type=int,
default=10,
help='the top features to show'
)
parser.add_argument(
'-e',
'--extensions',
type=str,
nargs='*',
default=['png'],
help='the extensions of the files to save'
)
parser.add_argument(
'--plot',
action='store_true',
help='whether to plot the results'
)
# parse arguments, build experiments, then export the results
args = parser.parse_args().__dict__
print("Starting experiment 'importance'...")
for k, v in args.items():
print(' >', k, '-->', v)
print()
args['datasets'] = [datasets[dataset] for dataset in args['datasets']]
AnalysisExperiment.importance(**args)