-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataClass.py
418 lines (303 loc) · 15.6 KB
/
DataClass.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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
#-*-coding:utf-8
import unittest
from dataclasses import dataclass, field
from typing import List
@dataclass
class DataPath:
data_path: str = '/data/datasets/rrs-data/3yrs_raw_data'
valid_path: str = '/media/nghia/Nguyen NghiaW/RRS-2021/20210322_RRS/RRS/10yrs_refined_data'
output_path: str = '/media/nghia/Nguyen NghiaW/RRS-2021/20210322_RRS/RRS/3yrs_refined_data'
model_path: str = '/media/nghia/Nguyen NghiaW/RRS-2021/20210322_RRS/RRS/trained_model'
model_path1: str = '/media/nghia/Nguyen NghiaW/RRS-2021/20210322_RRS/RRS/trained_model1'
train_abn_sign_data: List[str] = field(default_factory=lambda: ['화순abn_ward.csv'])
train_nl_sign_data: List[str] = field(default_factory=lambda: ['화순_nl_ward_외부.xlsx'])
train_event_data: List[str] = field(default_factory=lambda: ['화순abn_list_외부.xlsx'])
train_abn_sign_icu_data: List[str] = field(default_factory=lambda: ['cnuhh_abn_ICU.xlsx'])
test_abn_sign_data: List[str] = field(default_factory=lambda: \
['학동abn_ICU(외부).xlsx', '학동abn_list_외부.xlsx', '학동abn_ward(외부).xlsx'])
test_nl_sign_data: List[str] = field(default_factory=lambda: ['학동nl_ward_ICU(외부).xlsx'])
test_event_data: str = '학동abn_list_외부.xlsx'
valid_abn_data: str = 'trn_abn_obj'
valid_abn_event: str = field(default_factory = lambda:
['10yrs_trn_abn.xlsx', '10yrs_tst_abn.csv'] )
valid_nl_event: str = field( default_factory = lambda: \
['10yrs_trn_nl_sample.csv', '10yrs_tst_nl_sample.csv'])
blood_data: List[str] = field(default_factory=lambda: ['외부 PD(고보건)-2019.11.7.xlsx'])
blood_train_abn_sheet: str = 'abn(결과,화순)'
blood_train_nl_sheet: str = 'nl(결과,화순)'
blood_test_abn_sheet: str = 'abn(결과,본원)'
blood_test_nl_sheet: str = 'nl(결과,본원)'
exclude_id: List[str] = field(default_factory=lambda: ['화순_학동 nl 중 제외 명단.xlsx'])
exclude_train_sheet: str = '화순nl제외명단'
exclude_test_sheet: str = '학동nl제외명단'
xgb_model: List[str] = field(default_factory = lambda: \
['xgb_full.pickle'])
rf_model: List[str] = field(default_factory = lambda: \
['rf_full.pickle'])
lgb_model: List[str] = field(default_factory = lambda: \
['lgb_full.pickle'])
dews_model: List[str] = field(default_factory = lambda: \
['dews_full.pickle'])
@dataclass
class VarSet:
# Feature Sets
stat_grp: List[str] = field(default_factory=lambda: ['mean', 'std', 'max', 'min'])
time_grp: List[str] = field(default_factory=lambda: ['timestamp'])
meta_grp: List[str] = field(default_factory=lambda: ['age', 'gender'])
vital_grp: List[str] = field(default_factory=lambda: ['SBP', 'BT', 'SaO2', 'RR', 'HR'])
vital_grp_stat: List[str] = field(default_factory=list)
# CRP 항목은 없으면 삭제
lab_grp_a: List[str] = field(default_factory=lambda: ['WBC Count', 'Hgb', 'platelet', 'CRP'])
lab_grp_a_stat: List[str] = field(default_factory=list)
# 영양
# total protein and Albumin 은 na시 초기 값으로 대체
# missing이 너무 많으면 제외
lab_grp_b: List[str] = field(default_factory=lambda: ['Total protein', 'Albumin'])
lab_grp_b_stat: List[str] = field(default_factory=list)
# 신장 및 전해질 상태
lab_grp_c: List[str] = field(default_factory=lambda: \
['BUN', 'Creatinin' 'Sodium', 'Potassium', 'Chloride'])
lab_grp_c_stat: List[str] = field(default_factory=list)
# 간
# total bilirubin 은 na시 평균 대체
lab_grp_d: List[str] = field(default_factory=lambda: ['AST', 'ALT', 'Total bilirubin'])
lab_grp_d_stat: List[str] = field(default_factory=list)
lab_grp_e: List[str] = field(default_factory=lambda: \
['CRP', 'Creatinin'])
#LAB_GRO_E = ['Glucose', 'Total calcium', 'Lactate', 'Alkaline phosphatase']
lab_grp_e_stat: List[str] = field(default_factory=list)
lab_grp_f: List[str] = field(default_factory=lambda: \
['CRP'])
lab_grp_f_stat: List[str] = field(default_factory=list)
lab_grp: List[str] = field(default_factory=list)
lab_grp_stat: List[str] = field(default_factory=list)
def __post_init__(self):
if not self.vital_grp_stat:
self.vital_grp_stat = self.create_vital_grp_stat()
if not self.lab_grp_a_stat:
self.lab_grp_a_stat = self.create_lab_grp_a_stat()
if not self.lab_grp_b_stat:
self.lab_grp_b_stat = self.create_lab_grp_b_stat()
if not self.lab_grp_c_stat:
self.lab_grp_c_stat = self.create_lab_grp_c_stat()
if not self.lab_grp_d_stat:
self.lab_grp_d_stat = self.create_lab_grp_d_stat()
if not self.lab_grp_e_stat:
self.lab_grp_e_stat = self.create_lab_grp_e_stat()
if not self.lab_grp_f_stat:
self.lab_grp_f_stat = self.create_lab_grp_f_stat()
if not self.lab_grp:
self.lab_grp = self.create_lab_grp()
if not self.lab_grp_stat:
self.lab_grp_stat = self.create_lab_grp_stat()
def create_vital_grp_stat(self) -> List[str]:
return [x + '_' + y for x in self.stat_grp for y in self.vital_grp]
def create_lab_grp_a_stat(self) -> List[str]:
return [x + '_' + y for x in self.stat_grp for y in self.lab_grp_a]
def create_lab_grp_b_stat(self):
return [x + '_' + y for x in self.stat_grp for y in self.lab_grp_b]
def create_lab_grp_c_stat(self):
return [x + '_' + y for x in self.stat_grp for y in self.lab_grp_c]
def create_lab_grp_d_stat(self):
return [x + '_' + y for x in self.stat_grp for y in self.lab_grp_d]
def create_lab_grp_e_stat(self):
return [x + '_' + y for x in self.stat_grp for y in self.lab_grp_e]
def create_lab_grp_f_stat(self):
return [x + '_' + y for x in self.stat_grp for y in self.lab_grp_f]
def create_lab_grp(self) -> List[str]:
return self.lab_grp_a + self.lab_grp_b + self.lab_grp_c + self.lab_grp_d
def create_lab_grp_stat(self) -> List[str]:
return self.lab_grp_a_stat + self.lab_grp_b_stat + self.lab_grp_c_stat + \
self.lab_grp_d_stat
@dataclass
class ModelSet(VarSet):
full: List[str] = field(default_factory=list)
full_time: List[str] = field(default_factory=list)
vital: List[str] = field(default_factory=list)
vital_time: List[str] = field(default_factory=list)
lab_A: List[str] = field(default_factory=list)
lab_A_time: List[str] = field(default_factory=list)
lab_B: List[str] = field(default_factory=list)
lab_B_time: List[str] = field(default_factory=list)
lab_C: List[str] = field(default_factory=list)
lab_C_time: List[str] = field(default_factory=list)
lab_D: List[str] = field(default_factory=list)
lab_D_time: List[str] = field(default_factory=list)
lab_E: List[str] = field(default_factory=list)
lab_E_time: List[str] = field(default_factory=list)
vital_lab_A: List[str] = field(default_factory=list)
vital_lab_A_time: List[str] = field(default_factory=list)
vital_lab_B: List[str] = field(default_factory=list)
vital_lab_B_time: List[str] = field(default_factory=list)
vital_lab_C: List[str] = field(default_factory=list)
vital_lab_C_time: List[str] = field(default_factory=list)
vital_lab_D: List[str] = field(default_factory=list)
vital_lab_D_time: List[str] = field(default_factory=list)
vital_lab_E: List[str] = field(default_factory=list)
vital_lab_E_time: List[str] = field(default_factory=list)
vital_lab_AB: List[str] = field(default_factory=list)
vital_lab_AB_time: List[str] = field(default_factory=list)
vital_lab_ABC: List[str] = field(default_factory=list)
vital_lab_ABC_time: List[str] = field(default_factory=list)
vital_lab_ABCD: List[str] = field(default_factory=list)
vital_lab_ABCD_time: List[str] = field(default_factory=list)
def __post_init__(self):
if not self.full:
self.full = self.create_full_model()
if not self.full_time:
self.full_time = self.create_full_time_model()
if not self.vital:
self.vital = self.create_vital_model()
if not self.vital_time:
self.vital_time = self.create_vital_time_model()
if not self.lab_A:
self.lab_A = self.create_lab_a_model()
if not self.lab_A_time:
self.lab_A_time = self.create_lab_a_time_model()
if not self.lab_B:
self.lab_B = self.create_lab_b_model()
if not self.lab_B_time:
self.lab_B_time = self.create_lab_b_time_model()
if not self.lab_C:
self.lab_C = self.create_lab_c_model()
if not self.lab_C_time:
self.lab_C_time = self.create_lab_c_time_model()
if not self.lab_D:
self.lab_D = self.create_lab_d_model()
if not self.lab_D_time:
self.lab_D_time = self.create_lab_d_time_model()
if not self.lab_E:
self.lab_E = self.create_lab_e_model()
if not self.lab_E_time:
self.lab_E_time = self.create_lab_e_time_model()
if not self.vital_lab_A:
self.vital_lab_A = self.create_vital_lab_a_model()
if not self.vital_lab_A_time:
self.vital_lab_A_time = self.create_vital_lab_a_time_model()
if not self.vital_lab_B:
self.vital_lab_B = self.create_vital_lab_b_model()
if not self.vital_lab_B_time:
self.vital_lab_B_time = self.create_vital_lab_b_time_model()
if not self.vital_lab_C:
self.vital_lab_C = self.create_vital_lab_c_model()
if not self.vital_lab_C_time:
self.vital_lab_C_time = self.create_vital_lab_c_time_model()
if not self.vital_lab_D:
self.vital_lab_D = self.create_vital_lab_d_model()
if not self.vital_lab_D_time:
self.vital_lab_D_time = self.create_vital_lab_d_time_model()
if not self.vital_lab_E:
self.vital_lab_E = self.create_vital_lab_e_model()
if not self.vital_lab_E_time:
self.vital_lab_E_time = self.create_vital_lab_e_time_model()
if not self.vital_lab_AB:
self.vital_lab_AB = self.create_vital_lab_ab_model()
if not self.vital_lab_AB_time:
self.vital_lab_AB_time = self.create_vital_lab_ab_time_model()
if not self.vital_lab_AB:
self.vital_lab_AB = self.create_vital_lab_ab_model()
if not self.vital_lab_ABC_time:
self.vital_lab_ABC_time = self.create_vital_lab_abc_time_model()
if not self.vital_lab_ABCD:
self.vital_lab_ABCD = self.create_vital_lab_abcd_model()
if not self.vital_lab_ABCD_time:
self.vital_lab_ABCD_time = self.create_vital_lab_abcd_time_model()
def create_full_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.time_grp + VarSet.vital_grp + VarSet.vital_grp_stat + \
VarSet.lab_grp_a + VarSet.lab_grp_a_stat + \
VarSet.lab_grp_b + VarSet.lab_grp_b_stat + \
VarSet.lab_grp_c + VarSet.lab_grp_c_stat + \
VarSet.lab_grp_d + VarSet.lab_grp_d_stat + \
VarSet.lab_grp_e + VarSet.lab_grp_e_stat
def create_full_time_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.time_grp + VarSet.vital_grp + VarSet.lab_grp
def create_vital_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.vital_grp
def create_vital_time_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.vital_grp + VarSet.vital_grp_stat + VarSet.time_grp
def create_lab_a_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.lab_grp_a + VarSet.lab_grp_a_stat
def create_lab_a_time_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.lab_grp_a + VarSet.time_grp
def create_lab_b_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.lab_grp_b + VarSet.lab_grp_b_stat
def create_lab_b_time_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.lab_grp_b + VarSet.time_grp
def create_lab_c_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.lab_grp_c + VarSet.lab_grp_c_stat
def create_lab_c_time_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.lab_grp_c + VarSet.time_grp
def create_lab_d_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.lab_grp_d + VarSet.lab_grp_d_stat
def create_lab_d_time_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.lab_grp_d + VarSet.time_grp
def create_lab_e_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.lab_grp_e + VarSet.lab_grp_e_stat
def create_lab_e_time_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.lab_grp_e + VarSet.time_grp
def create_vital_lab_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.vital_grp + VarSet.vital_grp_stat + VarSet.lab_grp + VarSet.lab_grp_stat
def create_vital_lab_a_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.vital_grp + VarSet.vital_grp_stat + VarSet.lab_grp_a + VarSet.lab_grp_a_stat
def create_vital_lab_a_time_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.vital_grp + VarSet.lab_grp_a + VarSet.time_grp
def create_vital_lab_b_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.vital_grp + VarSet.vital_grp_stat + VarSet.lab_grp_b + VarSet.lab_grp_b_stat
def create_vital_lab_b_time_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.vital_grp + VarSet.lab_grp_b + VarSet.time_grp
def create_vital_lab_c_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.vital_grp + VarSet.vital_grp_stat + VarSet.lab_grp_c + VarSet.lab_grp_c_stat
def create_vital_lab_c_time_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.vital_grp + VarSet.lab_grp_c + VarSet.time_grp
def create_vital_lab_d_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.vital_grp + VarSet.vital_grp_stat + VarSet.lab_grp_d + VarSet.lab_grp_d_stat
def create_vital_lab_d_time_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.vital_grp + VarSet.lab_grp_d + VarSet.time_grp
def create_vital_lab_e_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.vital_grp + VarSet.vital_grp_stat + VarSet.lab_grp_e + VarSet.lab_grp_e_stat
def create_vital_lab_e_time_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.vital_grp + VarSet.lab_grp_e + VarSet.time_grp
def create_vital_lab_ab_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.vital_grp + VarSet.vital_grp_stat + \
VarSet.lab_grp_a + VarSet.lab_grp_a_stat + \
VarSet.lab_grp_b + VarSet.lab_grp_b_stat
def create_vital_lab_ab_time_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.vital_grp + \
VarSet.lab_grp_a + VarSet.lab_grp_b + VarSet.time_grp
def create_vital_lab_abc_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.vital_grp + VarSet.vital_grp_stat + \
VarSet.lab_grp_a + VarSet.lab_grp_a_stat + \
VarSet.lab_grp_b + VarSet.lab_grp_b_stat + \
VarSet.lab_grp_c + VarSet.lab_grp_c_stat
def create_vital_lab_abc_time_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.vital_grp + \
VarSet.lab_grp_a + VarSet.lab_grp_b + \
VarSet.lab_grp_c + VarSet.time_grp
def create_vital_lab_abcd_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.vital_grp + VarSet.vital_grp_stat + \
VarSet.lab_grp_a + VarSet.lab_grp_a_stat + \
VarSet.lab_grp_b + VarSet.lab_grp_b_stat + \
VarSet.lab_grp_c + VarSet.lab_grp_c_stat + \
VarSet.lab_grp_d + VarSet.lab_grp_d_stat
def create_vital_lab_abcd_time_model(VarSet) -> List[str]:
return VarSet.meta_grp + VarSet.vital_grp + VarSet.lab_grp_a + \
VarSet.lab_grp_b + VarSet.time_grp + \
VarSet.lab_grp_c + VarSet.lab_grp_d
class DataTest(unittest.TestCase):
def test_DataPath(self) -> None:
data = DataPath()
print('Test DataPath')
print(data)
print('----')
def test_VarSet(self) -> None:
vars = VarSet()
print('Test VarSet')
print(vars)
print('----')
def test_ModelSet(self) -> None:
print('Test ModelSet')
models = ModelSet()
print(models)
print('----')
if __name__=='__main__':
unittest.main()