Update cohort.py
Browse files
cohort.py
CHANGED
@@ -16,108 +16,7 @@ def task_cohort(task,mimic_path,path_benchmark, config):
|
|
16 |
import day_intervals_cohort_v2
|
17 |
import day_intervals_cohort
|
18 |
import feature_selection_icu
|
19 |
-
import data_generation_icu_modify
|
20 |
version_path = mimic_path
|
21 |
version = version_path.split('/')[-1][0]
|
22 |
-
start = time.time()
|
23 |
-
#----------------------------------------------config----------------------------------------------------
|
24 |
-
with open(config) as f:
|
25 |
-
config = yaml.safe_load(f)
|
26 |
-
|
27 |
-
disease_label = config['disease_label']
|
28 |
-
tim = config['time']
|
29 |
-
label = config['label']
|
30 |
-
timeW = config['timeW']
|
31 |
-
include=int(timeW.split()[1])
|
32 |
-
bucket = config['bucket']
|
33 |
-
radimp = config['radimp']
|
34 |
-
predW = config['predW']
|
35 |
-
diag_flag = config['diagnosis']
|
36 |
-
out_flag = config['output']
|
37 |
-
chart_flag = config['chart']
|
38 |
-
proc_flag= config['proc']
|
39 |
-
med_flag = config['meds']
|
40 |
-
disease_filter = config['disease_filter']
|
41 |
-
icu_no_icu = config['icu_no_icu']
|
42 |
-
groupingICD = config['groupingICD']
|
43 |
-
# -------------------------------------------------------------------------------------------------------------
|
44 |
-
|
45 |
-
data_icu=icu_no_icu=="ICU"
|
46 |
-
data_mort=label=="Mortality"
|
47 |
-
data_admn=label=='Readmission'
|
48 |
-
data_los=label=='Length of Stay'
|
49 |
-
|
50 |
-
if (disease_filter=="Heart Failure"):
|
51 |
-
icd_code='I50'
|
52 |
-
elif (disease_filter=="CKD"):
|
53 |
-
icd_code='N18'
|
54 |
-
elif (disease_filter=="COPD"):
|
55 |
-
icd_code='J44'
|
56 |
-
elif (disease_filter=="CAD"):
|
57 |
-
icd_code='I25'
|
58 |
-
else:
|
59 |
-
icd_code='No Disease Filter'
|
60 |
-
|
61 |
-
#-----------------------------------------------EXTRACT MIMIC-----------------------------------------------------
|
62 |
-
if version == '2':
|
63 |
-
cohort_output = day_intervals_cohort_v2.extract_data(icu_no_icu,label,tim,icd_code, root_dir,disease_label)
|
64 |
-
elif version == '1':
|
65 |
-
cohort_output = day_intervals_cohort.extract_data(icu_no_icu,label,tim,icd_code, root_dir,disease_label)
|
66 |
-
end = time.time()
|
67 |
-
print("Time elapsed : ", round((end - start)/60,2),"mins")
|
68 |
-
#----------------------------------------------FEATURES-------------------------------------------------------
|
69 |
-
if data_icu :
|
70 |
-
feature_selection_icu.feature_icu(cohort_output, version_path,diag_flag,out_flag,chart_flag,proc_flag,med_flag)
|
71 |
-
end = time.time()
|
72 |
-
print("Time elapsed : ", round((end - start)/60,2),"mins")
|
73 |
-
#----------------------------------------------GROUPING-------------------------------------------------------
|
74 |
-
group_diag=False
|
75 |
-
group_med=False
|
76 |
-
group_proc=False
|
77 |
-
if data_icu:
|
78 |
-
if diag_flag:
|
79 |
-
group_diag=groupingICD
|
80 |
-
feature_selection_icu.preprocess_features_icu(cohort_output, diag_flag, group_diag,False,False,False,0,0)
|
81 |
-
end = time.time()
|
82 |
-
print("Time elapsed : ", round((end - start)/60,2),"mins")
|
83 |
-
#----------------------------------------------SUMMARY-------------------------------------------------------
|
84 |
-
if data_icu:
|
85 |
-
feature_selection_icu.generate_summary_icu(cohort_output,diag_flag,proc_flag,med_flag,out_flag,chart_flag)
|
86 |
-
end = time.time()
|
87 |
-
print("Time elapsed : ", round((end - start)/60,2),"mins")
|
88 |
-
#----------------------------------------------FEATURE SELECTION---------------------------------------------
|
89 |
-
|
90 |
-
select_diag= config['select_diag']
|
91 |
-
select_med= config['select_med']
|
92 |
-
select_proc= config['select_proc']
|
93 |
-
#select_lab= config['select_lab']
|
94 |
-
select_out= config['select_out']
|
95 |
-
select_chart= config['select_chart']
|
96 |
-
|
97 |
-
feature_selection_icu.features_selection_icu(cohort_output, diag_flag,proc_flag,med_flag,out_flag, chart_flag,select_diag,select_med,select_proc,select_out,select_chart)
|
98 |
-
end = time.time()
|
99 |
-
print("Time elapsed : ", round((end - start)/60,2),"mins")
|
100 |
-
#---------------------------------------CLEANING OF FEATURES-----------------------------------------------
|
101 |
-
thresh=0
|
102 |
-
if data_icu:
|
103 |
-
if chart_flag:
|
104 |
-
outlier_removal=config['outlier_removal']
|
105 |
-
clean_chart=outlier_removal!='No outlier detection'
|
106 |
-
impute_outlier_chart=outlier_removal=='Impute Outlier (default:98)'
|
107 |
-
thresh=config['outlier']
|
108 |
-
left_thresh=config['left_outlier']
|
109 |
-
feature_selection_icu.preprocess_features_icu(cohort_output, False, False,chart_flag,clean_chart,impute_outlier_chart,thresh,left_thresh)
|
110 |
-
end = time.time()
|
111 |
-
print("Time elapsed : ", round((end - start)/60,2),"mins")
|
112 |
-
# ---------------------------------------tim-Series Representation--------------------------------------------
|
113 |
-
if radimp == 'forward fill and mean' :
|
114 |
-
impute='Mean'
|
115 |
-
elif radimp =='forward fill and median':
|
116 |
-
impute = 'Median'
|
117 |
-
else :
|
118 |
-
impute = False
|
119 |
-
|
120 |
-
if data_icu:
|
121 |
-
gen=data_generation_icu_modify.Generator(task,cohort_output,data_mort,data_admn,data_los,diag_flag,proc_flag,out_flag,chart_flag,med_flag,impute,include,bucket,predW)
|
122 |
-
print("[============TASK COHORT SUCCESSFULLY CREATED============]")
|
123 |
-
|
|
|
16 |
import day_intervals_cohort_v2
|
17 |
import day_intervals_cohort
|
18 |
import feature_selection_icu
|
19 |
+
#import data_generation_icu_modify
|
20 |
version_path = mimic_path
|
21 |
version = version_path.split('/')[-1][0]
|
22 |
+
start = time.time()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|