-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrontend.py
More file actions
273 lines (223 loc) · 7.78 KB
/
Copy pathfrontend.py
File metadata and controls
273 lines (223 loc) · 7.78 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
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
import sys
sys.path.append("data/.")
sys.path.append("src/.")
sys.path.append("vars/.")
from functions import Helpers
from variables import Variables
from preproc import preprocess
from split import split
from LR import LR
from DT import DT
from NN import NN
from setup_logger import logger
################################################################################
# PREPROCESSING
################################################################################
# Preprocess?
do_preprocess = True
# Absolute path to the dataset to preprocess
pre_dataset = "data/HIVwidesub2.xls"
# Starting year
pre_start_year = 2011
# Ending year
pre_end_year = 2016
# Absolute path to the resulting dataset
pre_final_dataset = "data/HIV_RF_2016.csv"
################################################################################
# SPLIT DATA
################################################################################
# Split the dataset?
# (data, labels, train, test, unknown)
do_split = True
# Absolute path to the dataset to split
spl_dataset = pre_final_dataset
# Target variable
spl_target = "RF2016"
# Percentage of the dataset must be test
spl_test_size = 0.2
# Absolute directory to the path where the following files must be saved:
# 1. X.csv
# 2. Y.csv
# 3. X_train.csv
# 4. Y_train.csv
# 5. X_test.csv
# 6. Y_test.csv
# 7. X_unknown.csv
# 8. Y_unknown.csv
spl_output_direc = "data"
# Seed value
spl_seed = 123
################################################################################
# LOGISTIC REGRESSION
################################################################################
# Perform logistic regression?
do_lr = True
# Input list of absolute paths
# input_list = [<path_to_datapoints>,<path_to_labels>]
# or
# input_list = [<path_to_X_train>,<path_to_Y_train>,<path_to_X_test>,<path_to_Y_test>]
lr_X = "data/X.csv"
lr_Y = "data/Y.csv"
lr_input_list = [lr_X,lr_Y]
# Absolute path to the directory where the results are to be saved
lr_results_path = "results/lr"
# Seed
lr_seed = 123
# Number of folds for cross-validation
lr_k_folds = 10
################################################################################
# DECISION TREE
################################################################################
# Perform decision tree classification?
do_dt = True
# Input list of absolute paths
# input_list = [<path_to_X_train>,<path_to_Y_train>,<path_to_X_test>,<path_to_Y_test>
dt_X_train = "data/X_train.csv"
dt_Y_train = "data/Y_train.csv"
dt_X_test = "data/X_test.csv"
dt_Y_test = "data/Y_test.csv"
dt_input_list = [dt_X_train,dt_Y_train,dt_X_test,dt_Y_test]
# Absolute path to the directory where the results are to be saved
dt_results_path = "results/dt"
# Seed
dt_seed = 123
# Criterion to measure the quality of the split
# 'gini' or 'entropy'
dt_criterion = 'entropy'
# Strategy used to choose the split at each node
# 'best' or 'random'
dt_splitter = 'best'
# Maximum depth of tree
# 'None' or int value less than depth of tree
dt_max_depth = 5
################################################################################
# NEURAL NETWORK
################################################################################
# Perform neural network classification
do_nn = True
# Input list of absolute paths
# input_list = [<path_to_X_train>,<path_to_Y_train>,<path_to_X_test>,<path_to_Y_test>]
nn_X_train = "data/X_train.csv"
nn_Y_train = "data/Y_train.csv"
nn_X_test = "data/X_test.csv"
nn_Y_test = "data/Y_test.csv"
nn_input_list = [nn_X_train,nn_Y_train,nn_X_test,nn_Y_test]
# Absolute path to the directory where the results are to be saved
nn_results_path = "results/nn"
# Seed
nn_seed = 123
# Size of hidden layer
# number of elements of tuple indicates the number of hidden layers
# i-th entry of tuple indicates number of hidden units in the i-th hidden layer
nn_hidden_layer = (100,)
# Activation function
nn_activation = 'identity'
# Solver
nn_solver = 'adam'
# Regularization parameter
nn_regularization = 0.0001
# Size of minibatches
nn_batch_size = 'auto'
# Learning rate schedule
nn_learning_rate_sch = 'constant'
# Initial learning rate
nn_learning_rate_init = 0.001
# Maximum number of iterations
nn_max_iter = 100
# Tolerance for the optimization
nn_tol = 1e-4
# Momentum
nn_momentum = 0.9
# Nesterov's momentum
nn_nesterov = True
# Whether to use early stopping
nn_early = False
# Proportion of training data to set aside as validation set
nn_valid_frac = 0.1
# Exponential decay rate for estimates of first moment vector in adam
nn_beta_1 = 0.9
# Exponential decay rate for estimates of second moment vector in adam
nn_beta_2 = 0.999
# Maximum number of epochs to not meet tol improvement
nn_iter_no_change = 10
################################################################################
# CONSOLIDATED ROC CURVES
################################################################################
# Training datasets
test_list = ["data/X_test.csv", "data/Y_test.csv"]
# Absolute path to the directory where the joint ROC curve must be generated
results_path = 'results'
################################################################################
################################################################################
# DO NOT CHANGE CODE
################################################################################
if __name__ == "__main__":
h = Helpers()
v = Variables()
logit = None
dec_tree = None
neural_net = None
try:
if do_preprocess:
print("Preprocessing")
logger.info("Preprocessing")
preprocess(pre_dataset, pre_start_year, pre_end_year, pre_final_dataset)
logger.info("completed")
print("completed")
except Exception as e:
logger.error(e)
h.error()
try:
if do_split:
print("\nSplitting dataset")
logger.info("Splitting dataset")
split(spl_dataset, spl_target, spl_test_size, spl_output_direc, spl_seed)
logger.info("completed")
print("completed")
except Exception as e:
logger.error(e)
h.error()
try:
if do_lr:
print("\nLogistic regression")
logger.info("Logistic regression")
logit = LR(lr_input_list, lr_results_path, lr_seed, lr_k_folds)
logger.info("completed")
print("completed")
except Exception as e:
logger.error(e)
logger.warning("logistic regression skipped")
print("Skipping logistic regression. Check {0} for details".format(v.log_f))
try:
if do_dt:
print("\nDecision tree classification")
logger.info("Decision tree")
dec_tree = DT(dt_input_list, dt_results_path, dt_seed, dt_criterion, dt_splitter, dt_max_depth)
logger.info("completed")
print("completed")
except Exception as e:
logger.error(e)
logger.warning("decision tree skipped")
print("Skipping decision tree classification. Check {0} for details".format(v.log_f))
try:
if do_nn:
print("\nClassification using neural network")
logger.info("neural network")
neural_net = NN(nn_input_list, nn_results_path, nn_seed, nn_hidden_layer, nn_activation, nn_solver, nn_regularization, nn_batch_size, nn_learning_rate_sch, nn_learning_rate_init, nn_max_iter, nn_tol, nn_momentum, nn_nesterov, nn_early, nn_valid_frac, nn_beta_1, nn_beta_2, nn_iter_no_change)
logger.info("completed")
print("completed")
except Exception as e:
logger.error(e)
logger.warning("neural network skipped")
print("Skipping classification using neural network. Check {0} for details".format(v.log_f))
try:
print("\nGenerating consolidated ROC curve")
logger.info("consolidated ROC")
h.get_one_roc_curve(test_list, results_path, logit, dec_tree, neural_net)
logger.info("completed")
print("completed")
except Exception as e:
logger.error(e)
logger.warning("consolidated ROC failed")
print("Unable to generate consolidated ROC curve file. Check {0} for details".format(v.log_f))
h.done()