thbndi commited on
Commit
39dc75d
1 Parent(s): dd7c0c8

Update Mimic4Dataset.py

Browse files
Files changed (1) hide show
  1. Mimic4Dataset.py +12 -41
Mimic4Dataset.py CHANGED
@@ -239,36 +239,6 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
239
  verif=False
240
  return verif
241
 
242
- def open_dict(self,cond, proc, out, chart, lab, med):
243
- if cond:
244
- with open("./data/dict/"+self.config.name.replace(" ","_")+"/condVocab", 'rb') as fp:
245
- condDict = pickle.load(fp)
246
- else :
247
- condDict=None
248
- if proc:
249
- with open("./data/dict/"+self.config.name.replace(" ","_")+"/procVocab", 'rb') as fp:
250
- procDict = pickle.load(fp)
251
- else :
252
- procDict=None
253
- if out:
254
- with open("./data/dict/"+self.config.name.replace(" ","_")+"/outVocab", 'rb') as fp:
255
- outDict = pickle.load(fp)
256
- else :
257
- outDict=None
258
- if chart:
259
- with open("./data/dict/"+self.config.name.replace(" ","_")+"/chartVocab", 'rb') as fp:
260
- chartDict = pickle.load(fp)
261
- elif lab:
262
- with open("./data/dict/"+self.config.name.replace(" ","_")+"/labsVocab", 'rb') as fp:
263
- chartDict = pickle.load(fp)
264
- else :
265
- chartDict=None
266
- if med:
267
- with open("./data/dict/"+self.config.name.replace(" ","_")+"/medVocab", 'rb') as fp:
268
- medDict = pickle.load(fp)
269
- else :
270
- medDict=None
271
- return condDict, procDict, outDict, chartDict, medDict
272
  ###########################################################RAW##################################################################
273
 
274
  def _info_raw(self):
@@ -462,11 +432,11 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
462
  ins_encoder.fit(insVocab)
463
  with open(filepath, 'rb') as fp:
464
  dico = pickle.load(fp)
 
465
  df = pd.DataFrame.from_dict(dico, orient='index')
466
-
467
  for i, data in df.iterrows():
468
  concat_cols=[]
469
- 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.outDict,self.chartDict,self.condDict,self.procDict,self.medDict)
470
  dyn=dyn_df.copy()
471
  dyn.columns=dyn.columns.droplevel(0)
472
  cols=dyn.columns
@@ -474,7 +444,6 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
474
  for t in range(time):
475
  cols_t = [str(x) + "_"+str(t) for x in cols]
476
  concat_cols.extend(cols_t)
477
-
478
  demo['gender']=gen_encoder.transform(demo['gender'])
479
  demo['ethnicity']=eth_encoder.transform(demo['ethnicity'])
480
  demo['insurance']=ins_encoder.transform(demo['insurance'])
@@ -482,7 +451,8 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
482
  demo=demo.drop(['label'],axis=1)
483
  X= generate_ml(dyn_df,cond_df,demo,concat_cols,self.concat)
484
  X=X.values.tolist()[0]
485
- interv = (self.timeW//self.bucket)+1
 
486
  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
487
  size_aggreg = self.size_cond+ self.size_proc + self.size_meds+ self.size_out+ self.size_chart+ self.size_lab + 4
488
 
@@ -517,8 +487,9 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
517
  def _generate_examples_deep(self, filepath):
518
  with open(filepath, 'rb') as fp:
519
  dico = pickle.load(fp)
 
520
  for key, data in dico.items():
521
- 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.outDict,self.chartDict,self.condDict,self.procDict,self.medDict)
522
 
523
  if self.verif_dim_tensor(proc, out, chart, meds, lab):
524
  if self.data_icu:
@@ -546,7 +517,8 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
546
  features = datasets.Features(
547
  {
548
  "label": datasets.ClassLabel(num_classes=2,names=["0", "1"]),
549
- "text" : datasets.Value(dtype='string', id=None),
 
550
  }
551
  )
552
  return datasets.DatasetInfo(
@@ -572,7 +544,7 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
572
  if not desc.empty:
573
  cond_text.append(desc['description'].to_string(index=False))
574
  template = 'The patient is diagnosed with {}.'
575
- cond_text = template.format(';'.join(cond_text))
576
  else :
577
  cond_text=''
578
 
@@ -590,21 +562,20 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
590
  for mean_val, feat_label in zip(chart_mean, feat_text):
591
  text = template.format(mean_val,feat_label)
592
  chart_text.append(text)
593
- chart_text='The chart events mesured are : {}.' + ';'.join(chart_text)
594
  else:
595
  chart_text=''
596
 
597
  yield int(key),{
598
  'label' : data['label'],
599
- 'text': cond_text+chart_text
 
600
  }
601
 
602
  #############################################################################################################################
603
  def _info(self):
604
  self.path = self.init_cohort()
605
  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)
606
- self.outDict,self.chartDict,self.condDict,self.procDict,self.medDict = self.open_dict(self.feat_cond,self.feat_proc,self.feat_out, self.feat_chart, self.feat_lab, self.feat_meds)
607
-
608
  if (self.encoding == 'concat' or self.encoding =='aggreg'):
609
  return self._info_encoded()
610
 
 
239
  verif=False
240
  return verif
241
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  ###########################################################RAW##################################################################
243
 
244
  def _info_raw(self):
 
432
  ins_encoder.fit(insVocab)
433
  with open(filepath, 'rb') as fp:
434
  dico = pickle.load(fp)
435
+
436
  df = pd.DataFrame.from_dict(dico, orient='index')
 
437
  for i, data in df.iterrows():
438
  concat_cols=[]
439
+ 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)
440
  dyn=dyn_df.copy()
441
  dyn.columns=dyn.columns.droplevel(0)
442
  cols=dyn.columns
 
444
  for t in range(time):
445
  cols_t = [str(x) + "_"+str(t) for x in cols]
446
  concat_cols.extend(cols_t)
 
447
  demo['gender']=gen_encoder.transform(demo['gender'])
448
  demo['ethnicity']=eth_encoder.transform(demo['ethnicity'])
449
  demo['insurance']=ins_encoder.transform(demo['insurance'])
 
451
  demo=demo.drop(['label'],axis=1)
452
  X= generate_ml(dyn_df,cond_df,demo,concat_cols,self.concat)
453
  X=X.values.tolist()[0]
454
+
455
+ interv = (self.timeW//self.bucket) + 1
456
  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
457
  size_aggreg = self.size_cond+ self.size_proc + self.size_meds+ self.size_out+ self.size_chart+ self.size_lab + 4
458
 
 
487
  def _generate_examples_deep(self, filepath):
488
  with open(filepath, 'rb') as fp:
489
  dico = pickle.load(fp)
490
+
491
  for key, data in dico.items():
492
+ 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)
493
 
494
  if self.verif_dim_tensor(proc, out, chart, meds, lab):
495
  if self.data_icu:
 
517
  features = datasets.Features(
518
  {
519
  "label": datasets.ClassLabel(num_classes=2,names=["0", "1"]),
520
+ "COND" : datasets.Value(dtype='string', id=None),
521
+ "CHART/LAB" : datasets.Value(dtype='string', id=None),
522
  }
523
  )
524
  return datasets.DatasetInfo(
 
544
  if not desc.empty:
545
  cond_text.append(desc['description'].to_string(index=False))
546
  template = 'The patient is diagnosed with {}.'
547
+ cond_text = template.format('; '.join(cond_text))
548
  else :
549
  cond_text=''
550
 
 
562
  for mean_val, feat_label in zip(chart_mean, feat_text):
563
  text = template.format(mean_val,feat_label)
564
  chart_text.append(text)
565
+ chart_text='The chart events mesured are : ' + '; '.join(chart_text)
566
  else:
567
  chart_text=''
568
 
569
  yield int(key),{
570
  'label' : data['label'],
571
+ 'COND': cond_text,
572
+ 'CHART/LAB': chart_text,
573
  }
574
 
575
  #############################################################################################################################
576
  def _info(self):
577
  self.path = self.init_cohort()
578
  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)
 
 
579
  if (self.encoding == 'concat' or self.encoding =='aggreg'):
580
  return self._info_encoded()
581