Update Mimic4Dataset.py
Browse files- Mimic4Dataset.py +4 -11
Mimic4Dataset.py
CHANGED
@@ -218,13 +218,13 @@ def generate_split(path,task,concat,feat_cond=True,feat_chart=True,feat_proc=Tru
|
|
218 |
with open(path, 'rb') as fp:
|
219 |
dico = pickle.load(fp)
|
220 |
df = pd.DataFrame.from_dict(dico, orient='index')
|
221 |
-
task=task.replace(" ","_")
|
222 |
X_df=pd.DataFrame()
|
223 |
#y_df=pd.DataFrame(df['label'],columns=['label'])
|
224 |
-
|
|
|
225 |
concat_cols=[]
|
226 |
sample=data
|
227 |
-
dyn_df,cond_df,demo=onehot(sample,
|
228 |
dyn=dyn_df.copy()
|
229 |
dyn.columns=dyn.columns.droplevel(0)
|
230 |
cols=dyn.columns
|
@@ -263,12 +263,7 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
|
|
263 |
self.test_size = kwargs.pop("test_size",0.2)
|
264 |
self.val_size = kwargs.pop("val_size",0.1)
|
265 |
|
266 |
-
|
267 |
-
|
268 |
super().__init__(**kwargs)
|
269 |
-
#self.feat_cond, self.feat_chart, self.feat_proc, self.feat_meds, self.feat_out,self.path = self.create_cohort()
|
270 |
-
print("init dataset")
|
271 |
-
|
272 |
|
273 |
|
274 |
BUILDER_CONFIGS = [
|
@@ -327,7 +322,6 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
|
|
327 |
raise ValueError(f"Unsupported dtype: {dtype}")
|
328 |
|
329 |
def create_cohort(self):
|
330 |
-
print("init cohort")
|
331 |
if self.config.name == 'Phenotype' : self.config_path = _CONFIG_URLS['phenotype']
|
332 |
if self.config.name == 'Readmission' : self.config_path = _CONFIG_URLS['readmission']
|
333 |
if self.config.name == 'Length of Stay' : self.config_path = _CONFIG_URLS['los']
|
@@ -603,7 +597,6 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
|
|
603 |
###########################################################ENCODED##################################################################
|
604 |
|
605 |
def _info_encoded(self,X_encoded):
|
606 |
-
|
607 |
columns = {col: self.map_dtype(X_encoded[col].dtype) for col in X_encoded.columns}
|
608 |
features = datasets.Features(columns)
|
609 |
return datasets.DatasetInfo(
|
@@ -625,7 +618,7 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
|
|
625 |
def _generate_examples_encoded(self, filepath):
|
626 |
df = pd.read_csv(filepath, header=0)
|
627 |
for i, row in df.iterrows():
|
628 |
-
yield i, row.to_dict(
|
629 |
|
630 |
|
631 |
#############################################################################################################################
|
|
|
218 |
with open(path, 'rb') as fp:
|
219 |
dico = pickle.load(fp)
|
220 |
df = pd.DataFrame.from_dict(dico, orient='index')
|
|
|
221 |
X_df=pd.DataFrame()
|
222 |
#y_df=pd.DataFrame(df['label'],columns=['label'])
|
223 |
+
taskf=task.replace(" ","_")
|
224 |
+
for _, data in tqdm(df.iterrows(),desc='Encoding Data for '+task+' task'):
|
225 |
concat_cols=[]
|
226 |
sample=data
|
227 |
+
dyn_df,cond_df,demo=onehot(sample,taskf,feat_cond,feat_chart,feat_proc, feat_meds, feat_out)
|
228 |
dyn=dyn_df.copy()
|
229 |
dyn.columns=dyn.columns.droplevel(0)
|
230 |
cols=dyn.columns
|
|
|
263 |
self.test_size = kwargs.pop("test_size",0.2)
|
264 |
self.val_size = kwargs.pop("val_size",0.1)
|
265 |
|
|
|
|
|
266 |
super().__init__(**kwargs)
|
|
|
|
|
|
|
267 |
|
268 |
|
269 |
BUILDER_CONFIGS = [
|
|
|
322 |
raise ValueError(f"Unsupported dtype: {dtype}")
|
323 |
|
324 |
def create_cohort(self):
|
|
|
325 |
if self.config.name == 'Phenotype' : self.config_path = _CONFIG_URLS['phenotype']
|
326 |
if self.config.name == 'Readmission' : self.config_path = _CONFIG_URLS['readmission']
|
327 |
if self.config.name == 'Length of Stay' : self.config_path = _CONFIG_URLS['los']
|
|
|
597 |
###########################################################ENCODED##################################################################
|
598 |
|
599 |
def _info_encoded(self,X_encoded):
|
|
|
600 |
columns = {col: self.map_dtype(X_encoded[col].dtype) for col in X_encoded.columns}
|
601 |
features = datasets.Features(columns)
|
602 |
return datasets.DatasetInfo(
|
|
|
618 |
def _generate_examples_encoded(self, filepath):
|
619 |
df = pd.read_csv(filepath, header=0)
|
620 |
for i, row in df.iterrows():
|
621 |
+
yield i, row.to_dict()
|
622 |
|
623 |
|
624 |
#############################################################################################################################
|