Update Mimic4Dataset.py
Browse files- Mimic4Dataset.py +36 -10
Mimic4Dataset.py
CHANGED
@@ -9,6 +9,7 @@ from urllib.request import urlretrieve
|
|
9 |
from sklearn.model_selection import train_test_split
|
10 |
from sklearn.preprocessing import LabelEncoder
|
11 |
import yaml
|
|
|
12 |
from .dataset_utils import vocab, concat_data, generate_deep, generate_ml
|
13 |
from .task_cohort import create_cohort
|
14 |
|
@@ -517,6 +518,7 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
|
|
517 |
{
|
518 |
"label": datasets.ClassLabel(num_classes=2,names=["0", "1"]),
|
519 |
"COND" : datasets.Value(dtype='string', id=None),
|
|
|
520 |
}
|
521 |
)
|
522 |
return datasets.DatasetInfo(
|
@@ -531,18 +533,42 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
|
|
531 |
with open(filepath, 'rb') as fp:
|
532 |
dico = pickle.load(fp)
|
533 |
for key, data in dico.items():
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
542 |
yield int(key),{
|
543 |
'label' : data['label'],
|
544 |
-
'COND':
|
545 |
-
|
|
|
546 |
|
547 |
#############################################################################################################################
|
548 |
def _info(self):
|
|
|
9 |
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 |
|
|
|
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(
|
|
|
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 |
+
charts=chart['val']
|
554 |
+
feat=charts.keys()
|
555 |
+
chart_val=[charts[key] for key in feat]
|
556 |
+
chart_mean = [round(np.mean(c),3) for c in chart_val]
|
557 |
+
feat_text = [(items[items['itemid']==f]['label']).to_string(index=False) for f in feat]
|
558 |
+
template='{} for {}'
|
559 |
+
chart_text = []
|
560 |
+
for mean_val, feat_label in zip(chart_mean, feat_text):
|
561 |
+
text = template.format(mean_val,feat_label)
|
562 |
+
chart_text.append(text)
|
563 |
+
chart_text='The chart events mesured are : ' + '; '.join(chart_text)
|
564 |
+
else:
|
565 |
+
chart_text=''
|
566 |
+
|
567 |
yield int(key),{
|
568 |
'label' : data['label'],
|
569 |
+
'COND': cond_text,
|
570 |
+
'CHART/LAB': chart_text,
|
571 |
+
}
|
572 |
|
573 |
#############################################################################################################################
|
574 |
def _info(self):
|