pyhealth.tasks.length_of_stay_stagenet_mimic4#

class pyhealth.tasks.length_of_stay_stagenet_mimic4.LengthOfStayStageNetMIMIC4(padding=0)[source]#

Bases: BaseTask

StageNet-format length of stay prediction for MIMIC-IV.

Creates a single PATIENT-LEVEL sample by aggregating all admissions. Input structures mirror MortalityPredictionStageNetMIMIC4 (ICD codes and labs with StageNet encodings). The target is the length-of-stay category for the most recent valid admission, using the same 10-category scheme as LengthOfStayPredictionMIMIC4.

  • ICD codes: hours since previous admission (first admission uses 0)

  • Labs: hours from admission start (within-visit)

  • 10D vectors, one value per lab category (first observed per category per timestamp, missing -> None)

  • The prediction target is the LOS of the most recent (target) admission. diagnoses_icd/procedures_icd events are timestamped at dischtime (per the MIMIC-IV config) – i.e. at-or-after that admission’s own discharge, which is what determines its LOS label. Those codes are excluded for the target admission; codes from earlier, already-resolved admissions are unaffected.

  • Labs for the target admission are restricted to the first TARGET_ADMISSION_INPUT_WINDOW_HOURS hours after admission, rather than through discharge, so labs that are only available because the stay ran long are not used to predict its own length. Labs for earlier admissions are unaffected.

Parameters:

padding (int) – Optional padding forwarded to the StageNet processor for nested sequences. Default is 0.

Examples

>>> from pyhealth.datasets import MIMIC4EHRDataset
>>> from pyhealth.tasks import LengthOfStayStageNetMIMIC4
>>> dataset = MIMIC4EHRDataset(
...     root="/path/to/mimic-iv/2.2",
...     tables=["diagnoses_icd", "procedures_icd", "labevents"],
... )
>>> task = LengthOfStayStageNetMIMIC4()
>>> samples = dataset.set_task(task)
task_name: str = 'LengthOfStayStageNetMIMIC4'#
TARGET_ADMISSION_INPUT_WINDOW_HOURS: ClassVar[int] = 48#
input_schema: Dict[str, Tuple[str, Dict[str, Any]]]#
output_schema: Dict[str, str]#
LAB_CATEGORIES: ClassVar[Dict[str, List[str]]] = {'Anion Gap': ['50868', '52500'], 'Bicarbonate': ['50803', '50804'], 'Calcium': ['50808', '51624'], 'Chloride': ['50806', '52434', '50902', '52535'], 'Glucose': ['50809', '52027', '50931', '52569'], 'Magnesium': ['50960'], 'Osmolality': ['52031', '50964', '51701'], 'Phosphate': ['50970'], 'Potassium': ['50822', '52452', '50971', '52610'], 'Sodium': ['50824', '52455', '50983', '52623']}#
LAB_CATEGORY_NAMES: ClassVar[List[str]] = ['Sodium', 'Potassium', 'Chloride', 'Bicarbonate', 'Glucose', 'Calcium', 'Magnesium', 'Anion Gap', 'Osmolality', 'Phosphate']#
LABITEMS: ClassVar[List[str]] = ['50824', '52455', '50983', '52623', '50822', '52452', '50971', '52610', '50806', '52434', '50902', '52535', '50803', '50804', '50809', '52027', '50931', '52569', '50808', '51624', '50960', '50868', '52500', '52031', '50964', '51701', '50970']#
pre_filter(df)#
Return type:

LazyFrame