Repository navigation
Add TPC-style Hourly Length-of-Stay Prediction Task for eICU #1627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
b3f334e
Add files via upload
ahling21 b6d2e6a
Update tpc_eicu.py
ahling21 5ed55a7
Update test_tpc_real.py
ahling21 9392038
Update test_hourly.py
ahling21 e831314
Update tpc_eicu.py
ahling21 b121553
Update test_tpc_real.py
ahling21 276cc88
Update test_hourly.py
ahling21 319267e
Update tpc_eicu.py
ahling21 93c7e86
Update test_tpc_real.py
ahling21 61d78c4
Update test_hourly.py
ahling21 2fb2b61
Add Person C hourly LOS task fixtures and LSTM checkpoint
xiaoluo0916 5a483a0
Include synthetic intake-output fixture despite output ignore rule
xiaoluo0916 0fea051
Audit rubric readiness and fix hourly prediction look-ahead
xiaoluo0916 dca848f
Remove internal project planning notes from contribution
xiaoluo0916 b71e78d
Use neutral naming for TPC examples and test support
xiaoluo0916 b902f31
Remove machine-specific paths from validation reports
xiaoluo0916 1156863
Document reusable task interface and satisfy PR usage example check
xiaoluo0916 8bb5ebb
Apply repository lint rules to hourly task
xiaoluo0916 e2cd976
Leave explicit preprocessing and training extension points
xiaoluo0916 d6e569c
Clarify placeholders should reuse existing team implementations
xiaoluo0916 8d08fdd
Normalize generated CSV line endings for clean diffs
xiaoluo0916 7f88f5f
Delete tpc_eicu.py
ahling21 b3b1186
Update tpc_eicu.py
ahling21 4830d49
Update tpc_eicu.py
ahling21 bbce4a4
Update test_tpc_eicu.py
ahling21 71cd188
Update tpc_fixtures.py
ahling21 e534892
Update checkpoint.py
ahling21 ed655a3
Update tpc_fixtures.py
ahling21 a2d3ef7
Update generate_synthetic.py
ahling21 212164a
Update eicu_hourly_los_lstm.py
ahling21 736edc5
Update test_tpc_checkpoint.py
ahling21 8ae84f6
Update pyhealth.tasks.tpc_eicu.rst
ahling21 4a3ef18
Update pyhealth.tasks.tpc_eicu.rst
ahling21 15fd196
Update tpc_eicu.py
ahling21 99839e4
Update test_tpc_eicu.py
ahling21 9b0ff21
Apply Black formatting to TPC task and tests
ahling21 2b05e9b
Delete test_hourly.py
ahling21 9ad227c
Rename test_tpc_real.py to tests/integration/test_tpc_real.py
ahling21 d6a2d67
Update test_tpc_real.py
ahling21 92cf1da
Update pyhealth.tasks.tpc_eicu.rst
ahling21 0ba1306
Add RNN_V2 LSTM training, 6 metrics, and 2x3 missingness ablation
EmilyJYN 47f03a5
Complete TPC eICU LoS example results, PR rules, docs, and tests
EmilyJYN 4af6fe2
Adapt TPC eICU task to updated YAIB and RNN_V2 APIs
ahling21 d7f644f
Align default batch size with reported experimental settings
ahling21 84a2c3d
Merge latest upstream master and resolve task documentation conflict
ahling21 5ab8a04
Address AI review feedback on metrics tests, pre-rebase notes, and docs
EmilyJYN ba14b3f
Fix direct script import path, add synthetic ablation test, use jagge…
EmilyJYN daa9bcd
Clarify external patient subset preparation
ahling21 4d747aa
Clamp LOS labels and support optional label normalization
ahling21 53bbffb
Document synthetic CSVs and move checkpoint test into CI suite
ahling21 403ad23
Address AI review feedback on TPC task and example
ahling21 6ac4bb7
Merge upstream master and resolve task import conflict
ahling21 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| .. Contributors: Manling Tan, Yining Jin, Xiao Luo | ||
| .. NetIDs: manling4, yining34, xiaoluo6 | ||
| .. | ||
| .. Paper Title: | ||
| .. Temporal Pointwise Convolutional Networks for | ||
| .. Length of Stay Prediction in the Intensive Care Unit | ||
| .. | ||
| .. Paper Authors: | ||
| .. Emma Rocheteau, Pietro Liò, and Stephanie Hyland (2021) | ||
| .. | ||
| .. Paper URL: | ||
| .. https://arxiv.org/abs/2007.09483 | ||
|
|
||
|
|
||
| Hourly remaining ICU length of stay | ||
| =================================== | ||
|
|
||
| .. automodule:: pyhealth.tasks.tpc_eicu | ||
| :members: | ||
| :show-inheritance: | ||
|
|
||
| Implementation status | ||
| --------------------- | ||
|
|
||
| The task implements adult cohort selection, hourly dynamic feature | ||
| extraction, admission static features, and hourly remaining-LOS labels. | ||
| The observation horizon is capped at 336 hours. | ||
|
|
||
| Remaining LOS labels are clamped to a minimum of 0.5 hours | ||
| (1/48 day). | ||
|
|
||
| Label normalization is controlled by ``normalize_labels``. | ||
| The default is ``True``, which preserves YAIB's min-max label | ||
| normalization. Set ``normalize_labels=False`` to preserve raw | ||
| remaining-LOS labels in hours for MSLE-based models. | ||
|
|
||
| Observation removal is controlled by ``missing_rate`` (0.0 to 1.0). | ||
| Removal uses one deterministic mask per stay for a given seed and stay | ||
| identifier, so repeated training epochs over the same dataset see the same | ||
| masked observations. A rate of 0.0 preserves all observed values, while a rate | ||
| of 1.0 removes all observed feature cells. | ||
|
|
||
| When ``include_decay=True``, decay features are calculated after | ||
| observation removal. Observed values reset to 1.0, and unobserved | ||
| values decay by a factor of 0.75 per hour. | ||
|
|
||
| Missing dynamic values remain NaN in the task output. Forward filling | ||
| and normalization are handled by the configured YAIB preprocessing | ||
| pipeline. | ||
|
|
||
|
|
||
| Usage and validation | ||
| -------------------- | ||
|
|
||
| From a repository checkout in Python 3.12 or 3.13:: | ||
|
|
||
| python -m pip install -e . pytest | ||
| python examples/tpc_support/generate_synthetic.py /tmp/tpc_synthetic | ||
| python -m examples.tpc_support.checkpoint --output /tmp/tpc_checkpoint.json | ||
| python -m pytest tests/core/test_tpc_eicu.py -q --durations=5 | ||
| python -m pytest tests/core/test_tpc_checkpoint.py -q | ||
| python examples/eicu_hourly_los_lstm.py --synthetic --epochs 2 | ||
|
|
||
| The synthetic CSV generator produces invented records across five patients. | ||
| The committed CSV files in ``examples/tpc_support/synthetic_eicu/`` | ||
| serve as illustrative examples of the expected eICU data format for | ||
| manual inspection. They are not required at runtime. The synthetic | ||
| generator creates fresh CSV files for the example and checkpoint scripts. | ||
|
|
||
| The checkpoint script validates cohort selection, static values, aggregated | ||
| measurements, and remaining-LOS labels against independent numerical | ||
| expectations without training a model. The CSV-to-task checkpoint test | ||
| is included in the core test suite. | ||
|
|
||
| Input and output specification | ||
| ------------------------------ | ||
|
|
||
| Load ``lab``, ``vitalperiodic``, ``vitalaperiodic``, ``intakeoutput``, | ||
| ``respiratorycharting``, and ``nursecharting`` using :class:`~pyhealth.datasets.eICUDataset`. | ||
| One sample is produced per eligible stay: | ||
|
|
||
| * Adults have known age >=18 and total ICU stay >=5 hours; ``> 89`` maps to 90. | ||
| Unknown age excludes the stay. Unknown sex or invalid height/weight is NaN. | ||
| * Static features are age, sex (male=1, female=0), admission height and weight. | ||
| * Dynamic uses 48 YAIB features. For H=min(floor(total LOS hours),336), its | ||
| values have shape (H,48), with missing values retained as NaN. | ||
| * Bin [b,b+1) becomes available at timestamp b+1. At hour 5 the model may | ||
| consume bins 0–4 only. | ||
| * Labels at hours 5..H have shape (H-4,1) and equal | ||
| max(0.5, total LOS hours - h). All raw labels are at least | ||
| 0.5 hours, including exact-discharge labels. The observation | ||
| horizon is capped; remaining LOS is not capped. | ||
| * ``missing_rate`` controls deterministic per-stay removal of observed hourly | ||
| feature cells prior to forward-fill. A rate of 0.0 preserves observations; | ||
| 1.0 removes all observed cells. | ||
| * ``include_decay=True`` adds decay features matching the dynamic | ||
| feature dimensions. Decay resets to 1.0 upon observation and | ||
| decreases by a factor of 0.75 per unobserved hour. | ||
| * Split by ``patient_id`` rather than ``stay_id``, and fit learned processors | ||
| on training patients only. By default, YAIB label processors min-max scale | ||
| training targets. Set ``normalize_labels=False`` to disable label | ||
| normalization and retain raw LOS targets in hours for MSLE-based models. | ||
|
|
||
| For models requiring unnormalized LOS targets:: | ||
|
|
||
| from pyhealth.tasks import TPCLengthOfStayEICU | ||
|
|
||
| task = TPCLengthOfStayEICU( | ||
| missing_rate=0.1, | ||
| include_decay=True, | ||
| normalize_labels=False, | ||
| ) | ||
|
|
||
| This task reproduces the hourly remaining-LOS prediction formulation from the | ||
| paper using YAIB feature extraction and PyHealth's existing preprocessing | ||
| pipeline, rather than re-implementing the TPC model architecture. | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[low] Decay description omits features that are never observed
The page says unobserved values decay by 0.75 per hour. In the code (pyhealth/tasks/tpc_eicu.py, _decay), a feature with no prior observation stays at 0 rather than decaying. Add one sentence saying so.