Update Mimic4Dataset.py
Browse files- Mimic4Dataset.py +4 -52
Mimic4Dataset.py
CHANGED
|
@@ -10,7 +10,7 @@ from sklearn.model_selection import train_test_split
|
|
| 10 |
from sklearn.preprocessing import LabelEncoder
|
| 11 |
import yaml
|
| 12 |
import numpy as np
|
| 13 |
-
from .dataset_utils import vocab, concat_data, generate_deep, generate_ml
|
| 14 |
from .task_cohort import create_cohort
|
| 15 |
|
| 16 |
|
|
@@ -532,61 +532,13 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
|
|
| 532 |
items= pd.read_csv(self.mimic_path+'/icu/d_items.csv.gz',compression='gzip', header=0)
|
| 533 |
with open(filepath, 'rb') as fp:
|
| 534 |
dico = pickle.load(fp)
|
| 535 |
-
for key, data in dico.items():
|
| 536 |
-
|
| 537 |
-
#Diagnosis
|
| 538 |
-
if self.feat_cond:
|
| 539 |
-
conds = data['Cond']['fids']
|
| 540 |
-
cond_text=[]
|
| 541 |
-
for code in conds:
|
| 542 |
-
desc = icd[icd['code']==code]
|
| 543 |
-
if not desc.empty:
|
| 544 |
-
cond_text.append(desc['description'].to_string(index=False))
|
| 545 |
-
template = 'The patient is diagnosed with {}.'
|
| 546 |
-
cond_text = template.format(';'.join(cond_text))
|
| 547 |
-
else :
|
| 548 |
-
cond_text=''
|
| 549 |
-
|
| 550 |
-
#chart
|
| 551 |
-
if self.feat_chart:
|
| 552 |
-
chart = data['Chart']
|
| 553 |
-
if chart:
|
| 554 |
-
charts=chart['val']
|
| 555 |
-
feat=charts.keys()
|
| 556 |
-
chart_val=[charts[key] for key in feat]
|
| 557 |
-
chart_mean = [round(np.mean(c),3) for c in chart_val]
|
| 558 |
-
feat_text = [(items[items['itemid']==f]['label']).to_string(index=False) for f in feat]
|
| 559 |
-
template='{} for {}'
|
| 560 |
-
chart_text = []
|
| 561 |
-
for mean_val, feat_label in zip(chart_mean, feat_text):
|
| 562 |
-
text = template.format(mean_val,feat_label)
|
| 563 |
-
chart_text.append(text)
|
| 564 |
-
chart_text='The chart events mesured are :{}.' + ';'.join(chart_text)
|
| 565 |
-
else:
|
| 566 |
-
chart_text=''
|
| 567 |
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
if self.feat_meds:
|
| 571 |
-
meds = data['Med']
|
| 572 |
-
if meds:
|
| 573 |
-
meds=meds['val']
|
| 574 |
-
feat=meds['signal'].keys()
|
| 575 |
-
meds_val=[meds[key] for key in feat]
|
| 576 |
-
meds_mean = [round(np.mean(c),3) for c in meds_val]
|
| 577 |
-
feat_text = [(items[items['itemid']==f]['label']).to_string(index=False) for f in feat]
|
| 578 |
-
template='{} of {}'
|
| 579 |
-
meds_text = []
|
| 580 |
-
for mean_val, feat_label in zip(meds_mean, feat_text):
|
| 581 |
-
text = template.format(mean_val,feat_label)
|
| 582 |
-
meds_text.append(text)
|
| 583 |
-
meds_text='The medications administered are :{}.' + ';'.join(meds_text)
|
| 584 |
-
else:
|
| 585 |
-
meds_text=''
|
| 586 |
|
| 587 |
yield int(key),{
|
| 588 |
'label' : data['label'],
|
| 589 |
-
'text': cond_text+chart_text+meds_text
|
| 590 |
}
|
| 591 |
|
| 592 |
#############################################################################################################################
|
|
|
|
| 10 |
from sklearn.preprocessing import LabelEncoder
|
| 11 |
import yaml
|
| 12 |
import numpy as np
|
| 13 |
+
from .dataset_utils import vocab, concat_data, generate_deep, generate_ml, generate_text
|
| 14 |
from .task_cohort import create_cohort
|
| 15 |
|
| 16 |
|
|
|
|
| 532 |
items= pd.read_csv(self.mimic_path+'/icu/d_items.csv.gz',compression='gzip', header=0)
|
| 533 |
with open(filepath, 'rb') as fp:
|
| 534 |
dico = pickle.load(fp)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 535 |
|
| 536 |
+
for key, data in dico.items():
|
| 537 |
+
cond_text,chart_text,meds_text,proc_text,out_text = self.generate_text(data,icd,items, self.feat_cond, self.feat_chart, self.feat_meds, self.feat_proc, self.feat_out)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 538 |
|
| 539 |
yield int(key),{
|
| 540 |
'label' : data['label'],
|
| 541 |
+
'text': cond_text+chart_text+meds_text+proc_text+out_text
|
| 542 |
}
|
| 543 |
|
| 544 |
#############################################################################################################################
|