Repository navigation
Add TPC-style Hourly Length-of-Stay Prediction Task for eICU - #1627
Conversation
Add complete docstring
Add docstring
Add docstring
Add docstring and apply black
apply black
apply black
Added header for paper title, authors, URL, and team mates name
Added team mates name, paper title, author and URL
Added paper title, author, URL and team mates name
Update TPC eICU tests for missingness and decay
Change heading for formatting
Changed headers
Changed headers
changed headers
Changed header
There was a problem hiding this comment.
Previous review
AI Review
suggestion: approve
decision: human review
Thank you for this contribution. TPCLengthOfStayEICU adds an hourly remaining-LOS task for eICU. It comes with an LSTM example, a 2×3 missingness ablation, docs, and synthetic-data tests.
It looks ready to merge. The task extends YAIBLengthOfStayEICU without modifying it or any shared code. The only shared-file edit is the export line in pyhealth/tasks/__init__.py. Your description names both sharing links and gives a reason for each. The links are the reuse of YAIB's private helpers and _DYNAMIC_FEATURES, and the generator and fixtures reading eicu.yaml. The docs match the code, and the new task file has 97.3% coverage against the 80% bar. Whole-repo coverage is 87.5%, above the 60% bar.
Optional suggestions:
test_train_and_evaluate_synthetic_smokeintests/coreloads CSVs and trains a model. That contradicts your stated reason for making the CSV integration test opt-in, so consider moving it behind the same flag.- The description reports 29 unit tests, but the file appears to contain more, so the count may need updating.
- If
0.0is not in--test-rates, the mean and median baseline rows are silently left out. A warning or an explicit baseline pass would avoid surprises. - The committed
synthetic_eicu/*.csvfiles aren't read by any code. Either say in the docs that they are illustrative only, or remove them. - The robustness claim rests on one seed and MSE differences of 0.01–0.03. Softer wording such as "suggestive" would match the evidence. Several seeds would strengthen it.
- The 15,000-patient results predate the rebase and can't be reproduced from the repo. You already say this clearly.
Reviewed commit daa9bcd
|
Why this PR has To help the maintainers decide, please comment here with what your PR does that the others don't, such as fidelity to the paper, results or test coverage. Whichever PR isn't picked can still contribute its unique parts on top of the chosen one. The decision is tracked in #1668. One more fix either way: |
|
Picked as PyHealth's hourly eICU length-of-stay task. It's the only clean
The TPC model will be #1412. Before it can merge:
Once these fixes are pushed, we'll move this PR to |
Thank you for selecting our task implementation and for the constructive feedback! All four requested changes have been addressed in commits
All 36 tests passed locally, including the end-to-end synthetic training test and the CSV-to-task checkpoint test. The PR is ready for another review. Thank you! |
|
/review |
There was a problem hiding this comment.
Previous review
AI Review
suggestion: approve
decision: human review
Thank you for this contribution. TPCLengthOfStayEICU adds hourly remaining-LOS prediction for eICU. It builds on the existing YAIB task, and the example adds an RNN_V2 LSTM training run and a missingness-robustness ablation. It looks ready to merge.
I read the cohort rules, the label timing (bin [h-1, h) is available at hour h, so there is no future leakage), and the order of masking before forward-fill. Training-fitted processors are reused on the test splits without refitting. All of this looks correct. The task's coverage is 97.37%, and total repository coverage is 87.58%. Both clear the bar.
The links to YAIB are all named in your description with a reason. These are the subclassing, the private helpers, _DYNAMIC_FEATURES, and reading eicu.yaml in the generator and fixtures. The only shared-file edit is the one export line in pyhealth/tasks/__init__.py, which is registration.
Optional suggestions:
- Test location: The description puts the CSV integration test at
tests/integration/test_tpc_checkpoint.py, opt-in behindPYHEALTH_RUN_TPC_INTEGRATION. In the diff it istests/core/test_tpc_checkpoint.pyand always runs. The API docs match the diff, so please update the PR description. The same applies to the "29 unit tests" count, which looks lower than the number of cases intest_tpc_eicu.py. - Placement of the new import: In
pyhealth/tasks/__init__.pythe new import sits after the__getattr__function. It would read more cleanly next to the other eager imports. - Docstring layout: Several files have a second string literal after the header docstring. It isn't treated as a docstring, so you could merge the two or turn the second into a comment.
- Post-rebase check: You noted the full synthetic example was interrupted locally after the rebase. CI should confirm that
test_train_and_evaluate_synthetic_smokepasses.
Reviewed commit 53bbffb
|
Hi @solarsys, thank you for the feedback! All additional AI review suggestions have been addressed in commit
All 36 tests passed locally, Black formatting checks passed, and the full synthetic 2×3 missingness ablation completed successfully after the rebase. The PR is ready for another review. Could you please move it to automatic status and request a new AI review when you have a chance? Thank you for your time and guidance! |
|
/review |
There was a problem hiding this comment.
Previous review
AI Review
suggestion: approve
decision: human review
Thank you for this contribution. It adds TPCLengthOfStayEICU, an hourly remaining-ICU-LOS task for eICU. It also adds an RNN_V2 LSTM example with a missingness-robustness ablation, a synthetic data generator, docs and tests. It looks ready to merge.
What I checked:
- The task is self-contained. It subclasses YAIBLengthOfStayEICU and reuses its private helpers and
_DYNAMIC_FEATURES. The description names this link and gives a reason. It also names the generator and fixtures readingeicu.yaml. - The only shared-file edit is the export in
tasks/__init__.py, which is registration. - Coverage meets the bar. The whole repository is at 87.83% (bar 60%).
tpc_eicu.pyis at 97.37% (bar 80%). - The tests cover cohort, labels, masking, decay, leakage prevention, stay isolation, metrics and an end-to-end smoke run.
- The docs match the code.
Optional suggestions:
- State in the class docstring which YAIB cohort exclusions this task drops.
- Note in the PR text that the robustness conclusion rests on one seed, with MSE gaps of only 0.03 to 0.07. The example docstring already says so.
- In
tasks/__init__.py, restore the trailing newline at the end of the file. - The committed illustrative CSVs aren't used by any test. Keep them only if you find them useful.
Reviewed commit 403ad23
solarsys
left a comment
There was a problem hiding this comment.
Approving as PyHealth's hourly eICU length-of-stay task (the TPC task). Thanks for fixing the zero labels and the normalization option.
|
Approved. One step left: #1412 merged just before this, and both PRs add export lines at the same spot in |
|
/review |
| from .yaib_eicu import _DYNAMIC_FEATURES, YAIBLengthOfStayEICU | ||
|
|
||
|
|
||
| class TPCLengthOfStayEICU(YAIBLengthOfStayEICU): |
There was a problem hiding this comment.
[low] Relation to existing TPC components is not explained
The description says the work does not implement the TPC architecture, which implies PyHealth has no TPC support. In fact the repo already has pyhealth/models/tpc.py (a TPC model with its own decay indicators and an all-hour forward_sequence that predicts remaining LoS at every hour), pyhealth/tasks/tpc_day_one.py (TPCDayOne), and examples/eicu_los_tpc.py. This task is not redundant, because it produces hourly labels, which TPCDayOne excludes. Please add a short description paragraph stating how it differs from TPCDayOne and why the example trains RNN_V2 instead of the existing TPC model.
| 24.5, Kappa 0.253 vs 0.28). Remaining gaps may reflect differences in cohort | ||
| size, 48 YAIB dynamic + 4 static features (vs 87 + 17), and MSE loss rather | ||
| than log-space MSLE loss. | ||
| 2. Robustness ablation: in this single-seed (``seed=42``) evaluation, as |
There was a problem hiding this comment.
[low] Robustness conclusion drawn from a single seed
The finding that training with removal improves robustness rests on one seed (42). The differences it cites are small, for example MSE 24.79 vs 24.76 and R^2 0.001. The text should present this as an observation that needs more seeds, or report variance across seeds.
|
|
||
| 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. |
There was a problem hiding this comment.
[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.
There was a problem hiding this comment.
AI Review
suggestion: approve
decision: human review
Thank you for this contribution. It adds TPCLengthOfStayEICU, an hourly remaining-ICU-LOS task for eICU. The task has configurable missingness, optional decay features and optional label normalization. It comes with an LSTM missingness-ablation example, a synthetic data generator, docs and tests.
It looks ready to merge.
- The change is self-contained. It subclasses YAIBLengthOfStayEICU and only adds an export in
pyhealth/tasks/__init__.py. - The sharing is named in the description with reasons. The task reuses YAIB's private helpers and
_DYNAMIC_FEATURES. The generator and fixtures readeicu.yaml. - Coverage meets the bar.
tpc_eicu.pyis at 97.4%,tasks/__init__.pyat 98.5%, and the whole repository at 87.9%. - The tests cover cohort selection, labels, the horizon, missingness, decay, leakage and stay isolation.
- The docs match the code.
Optional suggestions:
- The repository already has
pyhealth/models/tpc.py,TPCDayOneandexamples/eicu_los_tpc.py. A sentence in the description or docs on how this task relates to them would help readers. - The robustness conclusion comes from one seed, with differences of about 0.001 to 0.03. It would be worth wording it more cautiously, or adding more seeds.
- The docs could mention that features with no earlier observation keep a decay value of 0.
- The committed CSVs in
examples/tpc_support/synthetic_eicu/are not used by any code. You could drop them or keep them as illustrations. pyhealth/tasks/__init__.pyhas lost its trailing newline. Restoring it would keep the diff clean.
Reviewed commit 6ac4bb7
Contributors
Type of Contribution
Standalone Task (Option 3) for the existing PyHealth eICU dataset.
Original Paper
Temporal Pointwise Convolutional Networks for Length of Stay Prediction in the Intensive Care Unit
Emma Rocheteau, Pietro Liò, and Stephanie Hyland (2021).
Paper: https://arxiv.org/abs/2007.09483
Overview
This PR introduces
TPCLengthOfStayEICU, an hourly remaining ICU length-of-stay (LOS) prediction task inspired by the original TPC paper.The implementation extends the existing
YAIBLengthOfStayEICUtask and reuses PyHealth's eICU data loading, feature extraction, and preprocessing infrastructure.Our contribution focuses on reproducing the hourly remaining-LOS prediction task rather than implementing the original TPC model architecture. We use PyHealth's existing
RNN_V2with an LSTM architecture to evaluate the task and conduct a novel missingness robustness ablation study.Implementation Details
The new task supports:
missing_rate, applied before forward-fill imputation.include_decay.normalize_labels(default: True). Setting it to False preserves raw LOS labels in hours for models requiring unnormalized targets.The 14-day observation horizon limits the prediction timeline rather than truncating the remaining-LOS labels.
Cohort Selection
The task uses its own cohort eligibility criteria to support TPC-style hourly remaining-LOS prediction. It does not inherit all of the original YAIB base-cohort exclusions.
Implementation Dependencies
Synthetic data and test fixtures: The synthetic data generator (
examples/tpc_support/generate_synthetic.py) and test fixtures (tests/core/tpc_fixtures.py) intentionally readpyhealth/datasets/configs/eicu.yamlto keep the synthetic CSV schema and test columns consistent with PyHealth's eICU dataset configuration.YAIB dependency: The task intentionally reuses YAIB's private preprocessing helpers and
_DYNAMIC_FEATURESconstant to maintain preprocessing consistency and avoid duplicate implementations. Future changes to these YAIB internals may therefore require corresponding updates to this task.Ablation Study: Missingness Robustness
We investigate whether introducing additional observation missingness during training improves model robustness to missing observations at inference time.
The experiment follows a 2 × 3 design:
Each model reuses its own training-fitted preprocessing and normalization processors when evaluating the different test missingness conditions.
This extension investigates training-time observation removal as a robustness intervention, rather than simply repeating the original paper's decay-removal ablation.
Experimental Setup
RNN_V2(LSTM).Evaluation Metrics
LOS targets and predictions are converted from hours to days before evaluation.
Following the metric conventions described in the original paper:
Experimental Results (Pre-Rebase)
The following numerical results were obtained before rebasing onto upstream PyHealth, using a batch size of 128. The full 15,000-patient experiment has not been rerun after the rebase.
Findings
These results suggest that training with additional observation removal may improve robustness under increased test-time missingness.
Differences from the original paper include the smaller patient subset, different feature sets, and the use of PyHealth's existing LSTM implementation instead of the original TPC architecture.
File Guide
Core Implementation
pyhealth/tasks/tpc_eicu.py— Implements the hourly remaining-LOS task, cohort selection, temporal alignment, missingness simulation, optional decay features, minimum LOS label enforcement, and configurable label normalization.pyhealth/tasks/__init__.py— Exports the new task.Documentation
docs/api/tasks/pyhealth.tasks.tpc_eicu.rst— API documentation, task description, usage instructions, and experimental overview.docs/api/tasks.rst— Registers the task in the API documentation index.Example and Supporting Utilities
examples/eicu_hourly_los_lstm.py— LSTM training, baseline evaluation, six evaluation metrics, and the 2 × 3 missingness robustness ablation study.examples/tpc_support/checkpoint.py— Synthetic data validation checkpoint.examples/tpc_support/generate_synthetic.py— Synthetic eICU data generator.examples/tpc_support/synthetic_eicu/— Seven illustrative synthetic CSV files provided for manual inspection of the eICU data format. The example and checkpoint generate fresh synthetic CSV files at runtime and do not depend on these committed files.Tests
tests/core/test_tpc_eicu.py— Tests covering cohort eligibility, static features, hourly aggregation, remaining-LOS labels, observation removal, decay, temporal leakage prevention, stay isolation, timeline configuration, optional label normalization, evaluation metrics, and end-to-end synthetic training.tests/core/tpc_fixtures.py— Reusable synthetic patient fixtures.tests/core/test_tpc_checkpoint.py— Synthetic CSV-to-task checkpoint test included in the core CI test suite.Usage Examples
Run the Synthetic-Data Example
When running with --synthetic, the script generates fresh synthetic CSV files at runtime rather than directly loading the committed illustrative CSV files.
Run the Full Missingness Ablation Study
To approximate the reported pre-rebase experimental setup, use the same 15,000-patient eICU subset. The example script does not perform patient subsampling automatically, so
--rootshould point to the externally prepared dataset.Numerical results may differ due to cohort selection and subsequent task and upstream API updates.
Run the Task and Checkpoint Tests
Testing and Validation
All committed tests use synthetic or pseudo-patient data. No real patient records are included in this PR.
Following the rebase and maintainer-requested updates, the following checks were completed locally:
tests/core/test_tpc_eicu.pypassed, including the end-to-end synthetic training smoke test.The independent RNN_V2 smoke test successfully verified:
Post-Rebase Validation Scope
After the rebase and maintainer-requested updates, the end-to-end synthetic training smoke test and the synthetic CSV-to-task checkpoint test both passed locally.
These tests validate the task implementation, synthetic data loading, preprocessing, and compatibility with RNN_V2.
The full 15,000-patient real-data experiment has not been rerun after the rebase or the subsequent maintainer-requested updates. The reported numerical results reflect the pre-rebase experiments.
Upstream Compatibility
This contribution has been rebased onto the upstream PyHealth master branch.
To accommodate the recent YAIB and RNN_V2 changes introduced in PR #1461:
_static_recordinstead of_static_series.singleordering for static features.These changes preserve the intended temporal alignment and prevent optional decay features from being treated as whole-stay information during hourly prediction.
Checklist
Thank you for reviewing our contribution. We welcome feedback and suggestions from the PyHealth maintainers.