pyhealth.tasks.InHospitalMortalityMEDS#
- class pyhealth.tasks.in_hospital_mortality_meds.InHospitalMortalityMEDS(observation_window='full_stay', window_hours=48.0, code_mapping=None)[source]#
Bases:
BaseTaskIn-hospital mortality prediction for MEDS datasets.
One sample per completed hospital stay. The observation window is the half-open interval
[admission, prediction_time)and the binary label is whether the stay ended in death (discharge codeHOSPITAL_DISCHARGE//DIED). MEDS codes observed during the window, excluding the terminating discharge event and anyMEDS_DEATH, form the input sequence. See the module docstring for the full definition.- Parameters:
observation_window (str) –
"full_stay"(default) observes the entire stay, i.e.[admission, discharge)."first_hours"observes only[admission, admission + window_hours)and keeps stays whose length exceedswindow_hours(an early-warning setup with a strictly future outcome).window_hours (float) – Observation length used when
observation_window="first_hours". Ignored for"full_stay". Defaults to48.0, matchingInHospitalMortalityMIMIC4.code_mapping (Optional[Dict[str, Tuple[str, str]]]) – Optional vocab mapping forwarded to
BaseTask(e.g.{"codes": ("ICD10CM", "CCSCM")}).
- Raises:
ValueError – If
observation_windowis not one of"full_stay"/"first_hours", or ifwindow_hoursis not positive.
Examples
>>> from pathlib import Path >>> import pyhealth.datasets.configs as meds_configs >>> from pyhealth.datasets import MEDSDataset >>> from pyhealth.tasks import InHospitalMortalityMEDS >>> # A bundled stay-aware config exposes hadm_id (not a core MEDS >>> # field, so it is kept out of the default configs/meds.yaml): >>> cfg = Path(meds_configs.__file__).parent / "meds_with_hadm.yaml" >>> dataset = MEDSDataset( ... root="/path/to/mimic-iv-demo-meds/0.0.1", ... config_path=str(cfg), ... ) >>> samples = dataset.set_task(InHospitalMortalityMEDS()) >>> # Early-warning variant: first 48h, stays longer than 48h only >>> early = InHospitalMortalityMEDS(observation_window="first_hours")