Update Mimic4Dataset.py
Browse files- Mimic4Dataset.py +15 -9
Mimic4Dataset.py
CHANGED
@@ -201,7 +201,9 @@ def encoding(X_data):
|
|
201 |
return X_data
|
202 |
|
203 |
def generate_split(path,task,concat,feat_cond=True,feat_chart=True,feat_proc=True, feat_meds=True, feat_out=False):
|
204 |
-
|
|
|
|
|
205 |
df = pd.DataFrame.from_dict(path)
|
206 |
task=task.replace(" ","_")
|
207 |
X_df=pd.DataFrame()
|
@@ -587,23 +589,19 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
|
|
587 |
|
588 |
###########################################################ENCODED##################################################################
|
589 |
|
590 |
-
def _info_encoded(self):
|
591 |
|
|
|
|
|
592 |
return datasets.DatasetInfo(
|
593 |
description=_DESCRIPTION,
|
|
|
594 |
homepage=_HOMEPAGE,
|
595 |
citation=_CITATION,
|
596 |
)
|
597 |
|
598 |
def __split_generators_encoded(self):
|
599 |
data_dir = "./data/dict/"+self.config.name.replace(" ","_")
|
600 |
-
X_train_encoded=generate_split(self.path+'/train_data.pkl',self.config.name,True,self.feat_cond, self.feat_chart, self.feat_proc, self.feat_meds, self.feat_out)
|
601 |
-
X_test_encoded=generate_split(self.path+'/test_data.pkl',self.config.name,True,self.feat_cond, self.feat_chart, self.feat_proc, self.feat_meds, self.feat_out)
|
602 |
-
X_val_encoded=generate_split(self.path+'/val_data.pkl',self.config.name,True,self.feat_cond, self.feat_chart, self.feat_proc, self.feat_meds, self.feat_out)
|
603 |
-
|
604 |
-
X_train_encoded.to_csv(self.path+"/X_train_encoded.csv", index=False)
|
605 |
-
X_test_encoded.to_csv(self.path+"/X_test_encoded.csv", index=False)
|
606 |
-
X_val_encoded.to_csv(self.path+"/X_val_encoded.csv", index=False)
|
607 |
|
608 |
return [
|
609 |
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": data_dir+'/X_train_encoded.csv'}),
|
@@ -620,7 +618,15 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
|
|
620 |
#############################################################################################################################
|
621 |
def _info(self):
|
622 |
self.feat_cond, self.feat_chart, self.feat_proc, self.feat_meds, self.feat_out,self.path = self.create_cohort()
|
|
|
623 |
if self.encoding :
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
624 |
return self._info_encoded()
|
625 |
else:
|
626 |
return self._info_raw()
|
|
|
201 |
return X_data
|
202 |
|
203 |
def generate_split(path,task,concat,feat_cond=True,feat_chart=True,feat_proc=True, feat_meds=True, feat_out=False):
|
204 |
+
with open(path, 'rb') as fp:
|
205 |
+
dico = pickle.load(fp)
|
206 |
+
df = pd.DataFrame.from_dict(dico, orient='index')
|
207 |
df = pd.DataFrame.from_dict(path)
|
208 |
task=task.replace(" ","_")
|
209 |
X_df=pd.DataFrame()
|
|
|
589 |
|
590 |
###########################################################ENCODED##################################################################
|
591 |
|
592 |
+
def _info_encoded(self,X_encoded):
|
593 |
|
594 |
+
columns = {col: self.map_dtype(X_encoded[col].dtype) for col in X_encoded.columns}
|
595 |
+
features = datasets.Features(columns)
|
596 |
return datasets.DatasetInfo(
|
597 |
description=_DESCRIPTION,
|
598 |
+
features=features,
|
599 |
homepage=_HOMEPAGE,
|
600 |
citation=_CITATION,
|
601 |
)
|
602 |
|
603 |
def __split_generators_encoded(self):
|
604 |
data_dir = "./data/dict/"+self.config.name.replace(" ","_")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
605 |
|
606 |
return [
|
607 |
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": data_dir+'/X_train_encoded.csv'}),
|
|
|
618 |
#############################################################################################################################
|
619 |
def _info(self):
|
620 |
self.feat_cond, self.feat_chart, self.feat_proc, self.feat_meds, self.feat_out,self.path = self.create_cohort()
|
621 |
+
|
622 |
if self.encoding :
|
623 |
+
X_train_encoded=generate_split(self.path+'/train_data.pkl',self.config.name,True,self.feat_cond, self.feat_chart, self.feat_proc, self.feat_meds, self.feat_out)
|
624 |
+
X_test_encoded=generate_split(self.path+'/test_data.pkl',self.config.name,True,self.feat_cond, self.feat_chart, self.feat_proc, self.feat_meds, self.feat_out)
|
625 |
+
X_val_encoded=generate_split(self.path+'/val_data.pkl',self.config.name,True,self.feat_cond, self.feat_chart, self.feat_proc, self.feat_meds, self.feat_out)
|
626 |
+
|
627 |
+
X_train_encoded.to_csv(self.path+"/X_train_encoded.csv", index=False)
|
628 |
+
X_test_encoded.to_csv(self.path+"/X_test_encoded.csv", index=False)
|
629 |
+
X_val_encoded.to_csv(self.path+"/X_val_encoded.csv", index=False)
|
630 |
return self._info_encoded()
|
631 |
else:
|
632 |
return self._info_raw()
|