thbndi commited on
Commit
69bcace
·
1 Parent(s): e61db87

Update Mimic4Dataset.py

Browse files
Files changed (1) hide show
  1. Mimic4Dataset.py +17 -27
Mimic4Dataset.py CHANGED
@@ -1,5 +1,3 @@
1
- import csv
2
- import json
3
  import os
4
  import pandas as pd
5
  import datasets
@@ -13,10 +11,7 @@ from sklearn.preprocessing import LabelEncoder
13
  import numpy as np
14
  from tqdm import tqdm
15
  import yaml
16
- import torch
17
  import time
18
- from pathlib import Path
19
- import importlib
20
 
21
 
22
  _DESCRIPTION = """\
@@ -32,7 +27,6 @@ _CITATION = "https://proceedings.mlr.press/v193/gupta22a.html"
32
  _URL = "https://github.com/healthylaife/MIMIC-IV-Data-Pipeline"
33
  _DATA_GEN = 'https://huggingface.co/datasets/thbndi/Mimic4Dataset/resolve/main/data_generation_icu_modify.py'
34
  _DAY_INT= 'https://huggingface.co/datasets/thbndi/Mimic4Dataset/resolve/main/day_intervals_cohort_v22.py'
35
- #_COHORT = 'https://huggingface.co/datasets/thbndi/Mimic4Dataset/resolve/main/cohort.py'
36
  _CONFIG_URLS = {'los' : 'https://huggingface.co/datasets/thbndi/Mimic4Dataset/resolve/main/config/los.config',
37
  'mortality' : 'https://huggingface.co/datasets/thbndi/Mimic4Dataset/resolve/main/config/mortality.config',
38
  'phenotype' : 'https://huggingface.co/datasets/thbndi/Mimic4Dataset/resolve/main/config/phenotype.config',
@@ -989,26 +983,22 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
989
  def _generate_examples_deep(self, filepath):
990
  with open(filepath, 'rb') as fp:
991
  dico = pickle.load(fp)
992
- for key, data in dico.items():
993
- proc_features = data['proc']
994
- chart_features = data['chart']
995
- meds_features = data['meds']
996
- out_features = data['out']
997
- cond_features = data['stat']
998
- demo= data['demo']
999
- label = data['label']
1000
- lab=data['lab']
1001
-
1002
- yield int(key), {
1003
- 'label': label,
1004
- 'DEMO': demo,
1005
- 'COND': cond_features,
1006
- 'MEDS': meds_features,
1007
- 'PROC': proc_features,
1008
- 'CHART': chart_features,
1009
- 'OUT': out_features,
1010
- 'LAB': lab,
1011
- }
1012
 
1013
  #############################################################################################################################
1014
  def _info(self):
@@ -1027,7 +1017,7 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
1027
  return self.__split_generators_encoded()
1028
 
1029
  elif self.encoding == 'deep' :
1030
- return self.__split_generators_deep()
1031
  else:
1032
  return self.__split_generators_raw()
1033
 
 
 
 
1
  import os
2
  import pandas as pd
3
  import datasets
 
11
  import numpy as np
12
  from tqdm import tqdm
13
  import yaml
 
14
  import time
 
 
15
 
16
 
17
  _DESCRIPTION = """\
 
27
  _URL = "https://github.com/healthylaife/MIMIC-IV-Data-Pipeline"
28
  _DATA_GEN = 'https://huggingface.co/datasets/thbndi/Mimic4Dataset/resolve/main/data_generation_icu_modify.py'
29
  _DAY_INT= 'https://huggingface.co/datasets/thbndi/Mimic4Dataset/resolve/main/day_intervals_cohort_v22.py'
 
30
  _CONFIG_URLS = {'los' : 'https://huggingface.co/datasets/thbndi/Mimic4Dataset/resolve/main/config/los.config',
31
  'mortality' : 'https://huggingface.co/datasets/thbndi/Mimic4Dataset/resolve/main/config/mortality.config',
32
  'phenotype' : 'https://huggingface.co/datasets/thbndi/Mimic4Dataset/resolve/main/config/phenotype.config',
 
983
  def _generate_examples_deep(self, filepath):
984
  with open(filepath, 'rb') as fp:
985
  dico = pickle.load(fp)
986
+
987
+ task=self.config.name.replace(" ","_")
988
+ if 'Custom' in task:
989
+ task = task.rsplit('_', 1)[0]
990
+ for key, data in tqdm(dico.items(),desc='Encoding Splits Data for '+task+' task'):
991
+ stat, demo, meds, chart, out, proc, lab, y = getXY_deep(data, task, self.feat_cond, self.feat_proc, self.feat_out, self.feat_chart, self.feat_meds)
992
+ yield int(key), {
993
+ 'label': y,
994
+ 'DEMO': demo,
995
+ 'COND': stat,
996
+ 'MEDS': meds,
997
+ 'PROC': proc,
998
+ 'CHART': chart,
999
+ 'OUT': out,
1000
+ 'LAB': lab,
1001
+ }
 
 
 
 
1002
 
1003
  #############################################################################################################################
1004
  def _info(self):
 
1017
  return self.__split_generators_encoded()
1018
 
1019
  elif self.encoding == 'deep' :
1020
+ return self.__split_generators_raw()
1021
  else:
1022
  return self.__split_generators_raw()
1023