-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
188 lines (159 loc) · 8.8 KB
/
main.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
"""Main script. Configure logger and argparser. Launch scripts"""
import os
import argparse
import logging
import time
import prediction
import selection
import statistics
import pvals
import whatsavailable
import whosmissing
import dump_ids
if __name__ == '__main__':
# Configure logger
logs_folder = 'logs/'
os.makedirs(logs_folder, exist_ok=True)
logger = logging.getLogger(__name__)
logger.addHandler(logging.StreamHandler()) # Print also in console.
log_filepath = f'{logs_folder}{int(1e6*time.time())}_prediction.log'
logging.basicConfig(
filename=log_filepath,
filemode='w',
level=logging.INFO,
format='%(asctime)s.%(msecs)03d:%(levelname)s:%(module)s.%(funcName)s:'
'%(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
)
# Configure parser
parser = argparse.ArgumentParser(description='main program')
subparsers = parser.add_subparsers(dest='action')
# Script 1: Compute pvals for feature selection with ANOVA
p = subparsers.add_parser('select', description='Compute p-values for '
'feature selection with ANOVA')
p.set_defaults(func=selection.run)
p.add_argument('task_name', nargs='?', default=None)
p.add_argument('--RS', dest='RS', default=0, nargs='?',
help='The random state to use.')
p.add_argument('--T', dest='T', default=0, nargs='?',
help='The trial #.')
p.add_argument('--TMAX', dest='TMAX', default=5, nargs='?',
help='The max # of trials.')
# Script 2: Filter p-values
p = subparsers.add_parser('filter', description='Filter all p-values.')
p.set_defaults(func=pvals.filter)
# Script 3: Run experiments
p = subparsers.add_parser('predict', description='Launch experiment for '
'1 task, 1 method and 1 trial.')
p.set_defaults(func=prediction.run)
p.add_argument('task_name', default=None, help='Name of the '
'task.')
p.add_argument('strategy_name', default=None, help='Name or id of the '
'method. See `python main.py info available` for ids.')
p.add_argument('--RS', dest='RS', default=0, nargs='?',
help='The random state to use.')
p.add_argument('--T', dest='T', default=0, nargs='?',
help='The trial #.')
p.add_argument('--n_top_pvals', dest='n_top_pvals', default=100,
nargs='?', help='The trial #.')
p.add_argument('--idx', dest='dump_idx_only', default=False, const=True,
nargs='?', help='Dump only the idx (no prediction).')
p.add_argument('--nbagging', type=int, default=None, dest='n_bagging')
p.add_argument('--n', type=int, default=None, dest='train_size')
p.add_argument('--npermutation', type=int, default=None, dest='n_permutation')
p.add_argument('--fold', type=int, default=None, dest='asked_fold')
p.add_argument('--out', type=str, default=None, dest='results_folder')
# Script 4: Aggregate results
p = subparsers.add_parser('aggregate', description='Aggregate results.')
p.set_defaults(func=prediction.aggregate_results)
p.add_argument('--root', type=str, help='The root folder where the '
'results are stored.', default='results/', dest='root_folder')
p.add_argument('-n', type=int, default=None, dest='n')
p.add_argument('--out', type=str, default='test_scores', dest='out')
# Script 5: Figures and tables of the paper
p = subparsers.add_parser('figs', description='Build figure and tables '
'of the paper.')
p.set_defaults(func=statistics.run)
subp = p.add_subparsers(dest='action')
parent_l = argparse.ArgumentParser(add_help=False)
parent_l.add_argument('--linear', dest='linear', default=False, const=True,
nargs='?', help='Whether to use linear methods')
parent_csv = argparse.ArgumentParser(add_help=False)
parent_csv.add_argument('--csv', dest='csv', default=False, const=True,
nargs='?',
help='Whether to dump into csv as well.')
parent_a = argparse.ArgumentParser(add_help=False)
parent_a.add_argument('-a', dest='article', default=False, const=True,
nargs='?',
help='Whether to dump in article folder.')
p = subp.add_parser('wilcoxon', parents=[parent_l, parent_csv, parent_a],
description='Wilcoxon test.')
p.add_argument('--less', type=bool, default=False, const=True, nargs='?',
help='Whether to use greater or less one sided wilcoxon.')
p = subp.add_parser('friedman', parents=[parent_l, parent_csv, parent_a],
description='Friedman & Nemenyi tests + crit. difference.')
p.add_argument('--ref', type=str, default=None, dest='ref')
subp.add_parser('scores', parents=[parent_l, parent_csv, parent_a],
description='Compute scores and ranks.')
p = subp.add_parser('boxplot', parents=[parent_l, parent_a],
description='Plot boxplots scores & times.')
p = subp.add_parser('desc', parents=[parent_a], description='Overview table.')
p = subp.add_parser('time', parents=[parent_a], description='Total time of fit.')
p = subp.add_parser('check', parents=[parent_a], description='Check score files.')
p = subp.add_parser('difficulty', parents=[parent_a], description='Plot rank vs difficulty.')
p.add_argument('--no-avg', type=bool, nargs='?', const=False, default=True, dest='avg')
p = subp.add_parser('breakout', parents=[parent_l, parent_a],
description='Plot broken out boxplots scores & times.')
p = subp.add_parser('mi', parents=[parent_l, parent_a], description='Plot multiple imputation results.')
p.add_argument('-n', type=int, default=None)
p.add_argument('--bagging', type=bool, nargs='?', default=False, const=True, dest='bagging_only')
p = subp.add_parser('imp', parents=[parent_a], description='Plot feature importance results.')
p.add_argument('-n', type=int, default=None)
p.add_argument('--root', type=str)
p.add_argument('--no-avg', type=bool, nargs='?', default=True, const=False, dest='average_folds')
p.add_argument('--mode', type=str, choices=['abs', 'rel', 'percent', 'ratio'], default='abs', dest='mode')
p.add_argument('--task', type=bool, nargs='?', default=False, const=True, dest='hue_by_task')
# Script 6: Data statistics
p = subparsers.add_parser('datastats', description='Build figures and '
'tables of the paper on data statistics.')
p.set_defaults(func=statistics.run)
subp = p.add_subparsers(dest='action')
p = subp.add_parser('mv', help='Missing values distributions.')
p.add_argument('tag', default=None, nargs='?', help='The task tag')
p.add_argument('--hide', dest='hide', default=False, const=True,
nargs='?', help='Whether to plot the stats or print')
p.add_argument('--fig1', dest='fig1', default=False, const=True,
nargs='?', help='Whether to plot the figure1')
p.add_argument('--fig2', dest='fig2', default=False, const=True,
nargs='?', help='Whether to plot the figure2')
p.add_argument('--fig2b', dest='fig2b', default=False, const=True,
nargs='?', help='Whether to plot the figure2')
p.add_argument('--fig3', dest='fig3', default=False, const=True,
nargs='?', help='Whether to plot the figure3')
p = subp.add_parser('ftypes', help='Feature types')
p = subp.add_parser('fcor', parents=[parent_csv],
help='Feature correlations.')
p.add_argument('--t', type=float, default=0.1,
help='Threshold for correlation')
p.add_argument('--abs', type=bool, default=False, const=True, nargs='?',
help='Whether to use absolute values of correlation')
# Script 7: Get information
p = subparsers.add_parser('info', description='Get informations.')
subp = p.add_subparsers(dest='action')
p = subp.add_parser('available',
description='What task/method is available.')
p.add_argument('-t', dest='task', type=bool, default=False, const=True,
nargs='?', help='Get task info.')
p.add_argument('-m', dest='method', type=bool, default=False, const=True,
nargs='?', help='Get method info.')
p.set_defaults(func=whatsavailable.run)
p = subp.add_parser('missing', description='Who is missing in scores.')
p.set_defaults(func=whosmissing.run)
# Script 8: Dump IDs
p = subparsers.add_parser('ids', description='Dump all IDs used.')
p.set_defaults(func=dump_ids.run)
# Start run
logger.info('Started run')
args = parser.parse_args()
args.func(args)
logger.info('Ended run')