thbndi commited on
Commit
7bf6511
1 Parent(s): 841622f

Update dataset_utils.py

Browse files
Files changed (1) hide show
  1. dataset_utils.py +22 -2
dataset_utils.py CHANGED
@@ -3,6 +3,13 @@ import pickle
3
  import numpy as np
4
  import torch
5
 
 
 
 
 
 
 
 
6
 
7
  def create_vocab(file,task):
8
  with open ('./data/dict/'+task+'/'+file, 'rb') as fp:
@@ -78,6 +85,10 @@ def vocab(task,diag_flag,proc_flag,out_flag,chart_flag,med_flag,lab_flag):
78
  return (len(condVocabDict),len(procVocabDict),len(medVocabDict),len(outVocabDict),len(chartVocabDict),len(labVocabDict),
79
  ethVocabDict,genderVocabDict,ageVocabDict,insVocabDict,condVocabDict,procVocabDict,medVocabDict,outVocabDict,chartVocabDict,labVocabDict)
80
 
 
 
 
 
81
  def concat_data(data,interval,feat_cond,feat_proc,feat_out,feat_chart,feat_meds,feat_lab,condDict, procDict, outDict, chartDict, medDict):
82
  meds=data['Med']
83
  proc = data['Proc']
@@ -181,7 +192,9 @@ def concat_data(data,interval,feat_cond,feat_proc,feat_out,feat_chart,feat_meds,
181
  return dyn_df,cond_df,demo
182
 
183
 
184
-
 
 
185
  def generate_deep(data,interval,task,feat_cond,feat_proc,feat_out,feat_chart,feat_meds,feat_lab,condDict, procDict, outDict, chartDict, medDict, eth_vocab,gender_vocab,age_vocab,ins_vocab):
186
  meds = []
187
  charts = []
@@ -214,9 +227,13 @@ def generate_deep(data,interval,task,feat_cond,feat_proc,feat_out,feat_chart,fea
214
  return stat, demo, meds, charts, out, proc, lab, y
215
 
216
 
 
 
 
 
217
  def generate_ml(dyn, stat, demo, concat_cols, concat):
218
  X_df = pd.DataFrame()
219
-
220
  if concat:
221
  dyna=dyn.copy()
222
  dyna.columns=dyna.columns.droplevel(0)
@@ -247,6 +264,9 @@ def generate_ml(dyn, stat, demo, concat_cols, concat):
247
  return X_df
248
 
249
 
 
 
 
250
  def generate_text(data,icd,items,feat_cond,feat_chart,feat_meds, feat_proc, feat_out):
251
  #Demographics
252
  age = data['age']
 
3
  import numpy as np
4
  import torch
5
 
6
+ ################################################################################
7
+ ################################################################################
8
+ ## ##
9
+ ## MIMIC IV DATASET UTILITY FUNCTIONS ##
10
+ ## ##
11
+ ################################################################################
12
+ ################################################################################
13
 
14
  def create_vocab(file,task):
15
  with open ('./data/dict/'+task+'/'+file, 'rb') as fp:
 
85
  return (len(condVocabDict),len(procVocabDict),len(medVocabDict),len(outVocabDict),len(chartVocabDict),len(labVocabDict),
86
  ethVocabDict,genderVocabDict,ageVocabDict,insVocabDict,condVocabDict,procVocabDict,medVocabDict,outVocabDict,chartVocabDict,labVocabDict)
87
 
88
+ ###################################
89
+ # CONCATENATE DATA FROM #
90
+ # DICT TO CREATE CSV FILES #
91
+ ###################################
92
  def concat_data(data,interval,feat_cond,feat_proc,feat_out,feat_chart,feat_meds,feat_lab,condDict, procDict, outDict, chartDict, medDict):
93
  meds=data['Med']
94
  proc = data['Proc']
 
192
  return dyn_df,cond_df,demo
193
 
194
 
195
+ ###################################
196
+ # CALLED FOR "tensor" ENCODING #
197
+ ###################################
198
  def generate_deep(data,interval,task,feat_cond,feat_proc,feat_out,feat_chart,feat_meds,feat_lab,condDict, procDict, outDict, chartDict, medDict, eth_vocab,gender_vocab,age_vocab,ins_vocab):
199
  meds = []
200
  charts = []
 
227
  return stat, demo, meds, charts, out, proc, lab, y
228
 
229
 
230
+ ###################################
231
+ # CALLED FOR "aggreg" OR #
232
+ # "concat" ENCODING #
233
+ ###################################
234
  def generate_ml(dyn, stat, demo, concat_cols, concat):
235
  X_df = pd.DataFrame()
236
+ dyn.to_csv("./data/dyn.csv")
237
  if concat:
238
  dyna=dyn.copy()
239
  dyna.columns=dyna.columns.droplevel(0)
 
264
  return X_df
265
 
266
 
267
+ ###################################
268
+ # CALLED FOR "text" ENCODING #
269
+ ###################################
270
  def generate_text(data,icd,items,feat_cond,feat_chart,feat_meds, feat_proc, feat_out):
271
  #Demographics
272
  age = data['age']