-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
365 lines (349 loc) · 13.7 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
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
354
355
356
357
358
359
360
361
362
363
364
365
import typer
import ml as main_experiment
import ml_cross_farm_validation as cross_farm_validation
import ml_temporal_validation as temporal_validation
from pathlib import Path
def main(
exp_main: bool = True,
exp_temporal: bool = True,
exp_cross_farm: bool = False,
weather_exp: bool = True,
regularisation_exp: bool = False,
output_dir: Path = Path("output"),
delmas_dir_mrnn: Path = Path("datasets/delmas_dataset4_mrnn_7day"),
cedara_dir_mrnn: Path = Path("datasets/cedara_datasetmrnn7_23"),
n_job: int = 5,
enable_regularisation: bool = False,
export_hpc_string: bool = False,
plot_2d_space: bool = True
):
"""Thesis script runs all key experiments for data exploration chapter
Args:\n
output_dir: Output directory
"""
if regularisation_exp:
print("regularisation test....")
steps_list = [
["QN", "ANSCOMBE", "LOG"]
]
for class_unhealthy_label in ["2To2", "2To1"]:
for steps in steps_list:
slug = "_".join(steps)
for clf in ["rbf"]:
for i_day in [1,2,3,4,5,6,7]:
for a_day in [1,2,3,4,5,6,7]:
# if i_day >= a_day:
# continue
for cv in ["RepeatedKFold"]:
for dataset in [
cedara_dir_mrnn,
delmas_dir_mrnn
]:
farm_id = "delmas"
if "cedara" in str(dataset).lower():
farm_id = "cedara"
main_experiment.main(
output_dir=output_dir
/ "main_experiment"
/ clf
/ dataset.stem
/ f"{dataset.stem}_{farm_id}_{cv}_{i_day}_{a_day}_{slug}"
/ class_unhealthy_label,
dataset_folder=dataset,
preprocessing_steps=steps,
n_imputed_days=i_day,
n_activity_days=a_day,
cv=cv,
classifiers=[clf],
class_unhealthy_label=[
class_unhealthy_label
],
study_id=farm_id,
export_fig_as_pdf=False,
plot_2d_space=plot_2d_space,
pre_visu=False,
export_hpc_string=export_hpc_string,
skip=False,
enable_regularisation=True,
n_job=1,
)
if exp_main:
print("experiment 1: main pipeline")
class_unhealthy_label = "2To2"
steps = ["QN", "ANSCOMBE", "LOG"]
slug = "_".join(steps)
print("Health status...")
clf = "rbf"
farm_id = "delmas"
cv = "RepeatedKFold"
i_day = 7
a_day = 7
main_experiment.main(
output_dir=output_dir
/ "main_experiment"
/ clf
/ delmas_dir_mrnn.stem
/ f"{delmas_dir_mrnn.stem}_{farm_id}_{cv}_{i_day}_{a_day}_{slug}"
/ class_unhealthy_label,
dataset_folder=delmas_dir_mrnn,
preprocessing_steps=steps,
n_imputed_days=i_day,
n_activity_days=a_day,
cv=cv,
classifiers=[clf],
class_unhealthy_label=[
class_unhealthy_label
],
study_id=farm_id,
plot_2d_space=plot_2d_space,
pre_visu=False,
export_hpc_string=export_hpc_string,
skip=False,
enable_regularisation=enable_regularisation,
n_job=n_job,
)
cv = "LeaveTwoOut"
clf = "linear"
main_experiment.main(
output_dir=output_dir
/ "main_experiment"
/ clf
/ delmas_dir_mrnn.stem
/ f"{delmas_dir_mrnn.stem}_{farm_id}_{cv}_{i_day}_{a_day}_{slug}"
/ class_unhealthy_label,
dataset_folder=delmas_dir_mrnn,
preprocessing_steps=steps,
n_imputed_days=i_day,
n_activity_days=a_day,
cv=cv,
classifiers=[clf],
class_unhealthy_label=[
class_unhealthy_label
],
study_id=farm_id,
plot_2d_space=plot_2d_space,
pre_visu=False,
export_hpc_string=export_hpc_string,
skip=False,
enable_regularisation=enable_regularisation,
n_job=n_job,
)
clf = "linear"
farm_id = "cedara"
cv = "RepeatedKFold"
i_day = 7
a_day = 7
main_experiment.main(
output_dir=output_dir
/ "main_experiment"
/ clf
/ cedara_dir_mrnn.stem
/ f"{cedara_dir_mrnn.stem}_{farm_id}_{cv}_{i_day}_{a_day}_{slug}"
/ class_unhealthy_label,
dataset_folder=cedara_dir_mrnn,
preprocessing_steps=steps,
n_imputed_days=i_day,
n_activity_days=a_day,
cv=cv,
classifiers=[clf],
class_unhealthy_label=[
class_unhealthy_label
],
study_id=farm_id,
plot_2d_space=plot_2d_space,
pre_visu=False,
export_hpc_string=export_hpc_string,
skip=False,
enable_regularisation=enable_regularisation,
n_job=n_job,
)
print("Response to treatment...")
clf = "linear"
farm_id = "delmas"
cv = "RepeatedKFold"
i_day = 7
a_day = 7
class_unhealthy_label = "2To1"
main_experiment.main(
output_dir=output_dir
/ "main_experiment"
/ clf
/ delmas_dir_mrnn.stem
/ f"{delmas_dir_mrnn.stem}_{farm_id}_{cv}_{i_day}_{a_day}_{slug}"
/ class_unhealthy_label,
dataset_folder=delmas_dir_mrnn,
preprocessing_steps=steps,
n_imputed_days=i_day,
n_activity_days=a_day,
cv=cv,
classifiers=[clf],
class_unhealthy_label=[
class_unhealthy_label
],
study_id=farm_id,
plot_2d_space=plot_2d_space,
pre_visu=False,
export_hpc_string=export_hpc_string,
skip=False,
enable_regularisation=enable_regularisation,
n_job=n_job,
)
clf = "linear"
farm_id = "cedara"
cv = "RepeatedKFold"
class_unhealthy_label = "2To1"
i_day = 7
a_day = 3
main_experiment.main(
output_dir=output_dir
/ "main_experiment"
/ clf
/ cedara_dir_mrnn.stem
/ f"{cedara_dir_mrnn.stem}_{farm_id}_{cv}_{i_day}_{a_day}_{slug}"
/ class_unhealthy_label,
dataset_folder=cedara_dir_mrnn,
preprocessing_steps=steps,
n_imputed_days=i_day,
n_activity_days=a_day,
cv=cv,
classifiers=[clf],
class_unhealthy_label=[
class_unhealthy_label
],
study_id=farm_id,
plot_2d_space=plot_2d_space,
pre_visu=False,
export_hpc_string=export_hpc_string,
skip=False,
enable_regularisation=enable_regularisation,
n_job=n_job,
)
if weather_exp:
print("experiment 1 (weather): main pipeline")
steps_list = [
# ["WINDSPEED", "STDS"],
# ["QN", "ANSCOMBE", "LOG", "WINDSPEED", "STDS"],
# ["HUMIDITY", "STDS"],
# ["QN", "ANSCOMBE", "LOG", "HUMIDITY", "STDS"],
# ["TEMPERATURE", "STDS"],
# ["QN", "ANSCOMBE", "LOG", "TEMPERATURE", "STDS"],
["RAINFALL", "STDS"],
["QN", "ANSCOMBE", "LOG", "RAINFALLAPPEND", "STDS"],
["QN", "ANSCOMBE", "LOG"]
]
for steps in steps_list:
slug = "_".join(steps)
for w_day in [84]:
for cv in ["RepeatedKFold"]:
n_imputed_days = 6
n_activity_days = 7
main_experiment.main(
output_dir=output_dir
/ "weather_experiment"
/ f"delmas_{cv}_{n_imputed_days}_{n_activity_days}_{w_day}_{slug}"
/ "2To2",
dataset_folder=delmas_dir_mrnn,
preprocessing_steps=steps,
n_imputed_days=n_imputed_days, #need this for preprocessing wont be used for the weather
n_activity_days=n_activity_days,
n_weather_days=w_day,
cv=cv,
classifiers=["rbf"],
class_unhealthy_label=["2To2"],
study_id="delmas",
export_fig_as_pdf=False,
plot_2d_space=False,
pre_visu=False,
skip=True,
enable_regularisation=enable_regularisation,
n_job=n_job,
weather_file=Path("weather_data/delmas_south_africa_2011-01-01_to_2015-12-31.csv")
)
n_imputed_days = 6
n_activity_days = 7
main_experiment.main(
output_dir=output_dir
/ "weather_experiment"
/ f"cedara_{cv}_{0}_{0}_{w_day}_{slug}"
/ "2To2",
dataset_folder=cedara_dir_mrnn,
preprocessing_steps=steps,
n_imputed_days=n_imputed_days,
n_activity_days=n_activity_days,
n_weather_days=w_day,
class_unhealthy_label=["2To2"],
cv=cv,
classifiers=["linear"],
study_id="cedara",
plot_2d_space=False,
export_fig_as_pdf=False,
pre_visu=False,
skip=True,
n_job=n_job,
export_hpc_string=export_hpc_string,
enable_regularisation=enable_regularisation,
weather_file=Path("weather_data/cedara_south_africa_2011-01-01_to_2015-12-31.csv"
)
)
if exp_temporal:
print("experiment 2: temporal validation")
i = 7
n_a = 6
temporal_validation.main(
output_dir=output_dir
/ "temporal_validation"
/ f"delmas_{i}_{n_a}"
/ "2To2",
dataset_folder=delmas_dir_mrnn,
n_imputed_days=i,
n_activity_days=n_a,
plot_2d_space=plot_2d_space
)
# i = 7
# n_a = 6
# temporal_validation.main(
# output_dir=output_dir / "temporal_validation" / f"cedara_{i}_{n_a}" / "2To2",
# dataset_folder=cedara_dir,
# n_imputed_days=i,
# n_activity_days=n_a,
# sample_date_filter="2013-02-14",
# class_healthy_label=["1To1"],
# class_unhealthy_label=["2To2", "2To4", "3To4", "1To4", "1To3", "4To5", "2To3"],
# export_fig_as_pdf=True)
if exp_cross_farm:
print("experiment 3: cross farm validation")
for imp_d in [7]:
for a_act_day in [1, 4, 7]:
cross_farm_validation.main(
farm1_path=delmas_dir_mrnn,
farm2_path=cedara_dir_mrnn,
output_dir=output_dir
/ "cross_farm"
/ f"{imp_d}_{a_act_day}"
/ "2To2",
n_imputed_days=imp_d,
n_activity_days=a_act_day,
class_unhealthy_f2=["2To2"],
)
# cross_farm_validation.main(
# farm1_path=Path("E:\Data2\debug3\delmas\dataset4_mrnn_7day"),
# farm2_path=Path("E:\Data2\debug3\cedara\dataset6_mrnn_7day"),
# output_dir=output_dir
# / "cross_Farm"
# / f"{imp_d}_{a_act_day}"
# / "4To4_3To5_4To3_5To3_2To5_2To2",
# n_imputed_days=imp_d,
# n_activity_days=a_act_day,
# class_unhealthy_f2=[
# "4To4",
# "3To5",
# "4To3",
# "5To3",
# "2To5",
# "2To2",
# ],
# )
if __name__ == "__main__":
# main(delmas_dir_mrnn=Path("datasets/delmas_dataset4_mrnn_7day"),
# cedara_dir_mrnn=Path("datasets/cedara_datasetmrnn7_23"))
typer.run(main)