thbndi commited on
Commit
809e7f8
1 Parent(s): 8c8e656

Update Mimic4Dataset.py

Browse files
Files changed (1) hide show
  1. Mimic4Dataset.py +8 -12
Mimic4Dataset.py CHANGED
@@ -165,11 +165,7 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
165
  self.feat_cond, self.feat_lab, self.feat_proc, self.feat_meds, self.feat_chart, self.feat_out = config['diagnosis'], config['lab'], config['proc'], config['meds'], False, False
166
 
167
 
168
- #####################downloads modules from hub
169
- #if not os.path.exists('./icd10.txt'):
170
- # file_path, head = urlretrieve(_ICD_CODE, "icd10.txt")
171
- # shutil.move(file_path, './')
172
-
173
  if not os.path.exists('./model/data_generation_icu_modify.py'):
174
  file_path, head = urlretrieve(_DATA_GEN, "data_generation_icu_modify.py")
175
  shutil.move(file_path, './model')
@@ -219,8 +215,7 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
219
  return dict_dir
220
 
221
 
222
- def verif_dim_tensor(self, proc, out, chart, meds, lab):
223
- interv = (self.timeW//self.bucket)
224
  verif=True
225
  if self.feat_proc:
226
  if (len(proc)!= interv):
@@ -435,7 +430,7 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
435
 
436
  df = pd.DataFrame.from_dict(dico, orient='index')
437
  for i, data in df.iterrows():
438
- dyn_df,cond_df,demo=concat_data(data,self.config.name.replace(" ","_"),self.feat_cond,self.feat_proc,self.feat_out, self.feat_chart, self.feat_meds,self.feat_lab,self.condDict, self.procDict, self.outDict, self.chartDict, self.medDict)
439
  dyn=dyn_df.copy()
440
  dyn.columns=dyn.columns.droplevel(0)
441
  concat_cols = [f"{col}_{t}" for t in range(dyn.shape[0]) for col in dyn.columns]
@@ -447,8 +442,8 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
447
  X= generate_ml(dyn_df,cond_df,demo,concat_cols,self.concat)
448
  X=X.values[0]
449
 
450
- interv = (self.timeW//self.bucket)
451
- size_concat = self.size_cond+ self.size_proc * interv + self.size_meds * interv+ self.size_out * interv+ self.size_chart *interv+ self.size_lab * interv + 4
452
  size_aggreg = self.size_cond+ self.size_proc + self.size_meds+ self.size_out+ self.size_chart+ self.size_lab + 4
453
 
454
  if ((self.concat and len(X)==size_concat) or ((not self.concat) and len(X)==size_aggreg)):
@@ -484,8 +479,8 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
484
  dico = pickle.load(fp)
485
 
486
  for key, data in dico.items():
487
- stat, demo, meds, chart, out, proc, lab, y = generate_deep(data, self.config.name.replace(" ","_"), self.feat_cond, self.feat_proc, self.feat_out, self.feat_chart, self.feat_meds,self.feat_lab,self.condDict, self.procDict, self.outDict, self.chartDict, self.medDict)
488
- if self.verif_dim_tensor(proc, out, chart, meds, lab):
489
  if self.data_icu:
490
  yield int(key), {
491
  'label': y,
@@ -538,6 +533,7 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
538
  #############################################################################################################################
539
  def _info(self):
540
  self.path = self.init_cohort()
 
541
  self.size_cond, self.size_proc, self.size_meds, self.size_out, self.size_chart, self.size_lab, eth_vocab,gender_vocab,age_vocab,ins_vocab=vocab(self.config.name.replace(" ","_"),self.feat_cond,self.feat_proc,self.feat_out,self.feat_chart,self.feat_meds,self.feat_lab)
542
  self.condDict, self.procDict, self.outDict, self.chartDict, self.medDict = open_dict(self.config.name.replace(" ","_"),self.feat_cond,self.feat_proc,self.feat_out,self.feat_chart,self.feat_lab,self.feat_meds)
543
  if (self.encoding == 'concat' or self.encoding =='aggreg'):
 
165
  self.feat_cond, self.feat_lab, self.feat_proc, self.feat_meds, self.feat_chart, self.feat_out = config['diagnosis'], config['lab'], config['proc'], config['meds'], False, False
166
 
167
 
168
+ #####################downloads modules from hub
 
 
 
 
169
  if not os.path.exists('./model/data_generation_icu_modify.py'):
170
  file_path, head = urlretrieve(_DATA_GEN, "data_generation_icu_modify.py")
171
  shutil.move(file_path, './model')
 
215
  return dict_dir
216
 
217
 
218
+ def verif_dim_tensor(self, proc, out, chart, meds, lab,interv):
 
219
  verif=True
220
  if self.feat_proc:
221
  if (len(proc)!= interv):
 
430
 
431
  df = pd.DataFrame.from_dict(dico, orient='index')
432
  for i, data in df.iterrows():
433
+ dyn_df,cond_df,demo=concat_data(data,self.interval,self.feat_cond,self.feat_proc,self.feat_out, self.feat_chart, self.feat_meds,self.feat_lab,self.condDict, self.procDict, self.outDict, self.chartDict, self.medDict)
434
  dyn=dyn_df.copy()
435
  dyn.columns=dyn.columns.droplevel(0)
436
  concat_cols = [f"{col}_{t}" for t in range(dyn.shape[0]) for col in dyn.columns]
 
442
  X= generate_ml(dyn_df,cond_df,demo,concat_cols,self.concat)
443
  X=X.values[0]
444
 
445
+
446
+ size_concat = self.size_cond+ self.size_proc * self.interval + self.size_meds * self.interval+ self.size_out * self.interval+ self.size_chart *self.interval+ self.size_lab * self.interval + 4
447
  size_aggreg = self.size_cond+ self.size_proc + self.size_meds+ self.size_out+ self.size_chart+ self.size_lab + 4
448
 
449
  if ((self.concat and len(X)==size_concat) or ((not self.concat) and len(X)==size_aggreg)):
 
479
  dico = pickle.load(fp)
480
 
481
  for key, data in dico.items():
482
+ stat, demo, meds, chart, out, proc, lab, y = generate_deep(data,self.interval, self.config.name.replace(" ","_"), self.feat_cond, self.feat_proc, self.feat_out, self.feat_chart, self.feat_meds,self.feat_lab,self.condDict, self.procDict, self.outDict, self.chartDict, self.medDict)
483
+ if self.verif_dim_tensor(proc, out, chart, meds, lab, self.interval):
484
  if self.data_icu:
485
  yield int(key), {
486
  'label': y,
 
533
  #############################################################################################################################
534
  def _info(self):
535
  self.path = self.init_cohort()
536
+ self.interval = (self.timeW//self.bucket)
537
  self.size_cond, self.size_proc, self.size_meds, self.size_out, self.size_chart, self.size_lab, eth_vocab,gender_vocab,age_vocab,ins_vocab=vocab(self.config.name.replace(" ","_"),self.feat_cond,self.feat_proc,self.feat_out,self.feat_chart,self.feat_meds,self.feat_lab)
538
  self.condDict, self.procDict, self.outDict, self.chartDict, self.medDict = open_dict(self.config.name.replace(" ","_"),self.feat_cond,self.feat_proc,self.feat_out,self.feat_chart,self.feat_lab,self.feat_meds)
539
  if (self.encoding == 'concat' or self.encoding =='aggreg'):