Skip to content

Add TPC-style Hourly Length-of-Stay Prediction Task for eICU - #1627

Merged
solarsys merged 52 commits into
sunlabuiuc:masterfrom
EmilyJYN:feature/tpc-eicu-los
Nov 29, 2026
Merged

solarsys merged 52 commits into
sunlabuiuc:masterfrom
EmilyJYN:feature/tpc-eicu-los

Conversation

@ahling21

@ahling21 ahling21 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Contributors

Name NetID Email
Manling Tan manling4 manling4@illinois.edu
Yining Jin yining34 yining34@illinois.edu
Xiao Luo xiaoluo6 xiaoluo6@illinois.edu

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 YAIBLengthOfStayEICU task 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_V2 with an LSTM architecture to evaluate the task and conduct a novel missingness robustness ablation study.

Implementation Details

The new task supports:

  • Adult ICU patients aged 18 or older with a minimum ICU stay of 5 hours.
  • Hourly prediction of remaining ICU length of stay, starting at hour 5, with a maximum observation horizon of 14 days.
  • 48 dynamic clinical features and 4 static admission features.
  • Hourly aggregation of clinical observations using completed observation windows to prevent future information leakage.
  • Forward-fill imputation, normalization, and missingness indicators through PyHealth's existing processors.
  • Configurable random observation removal through missing_rate, applied before forward-fill imputation.
  • Reproducible, stay-specific missingness generation.
  • Optional exponential decay features through include_decay.
  • Isolation of observations across different ICU stays.
  • Remaining-LOS labels are clamped to a minimum of 0.5 hours to prevent zero-valued raw targets.
  • Configurable label normalization through normalize_labels (default: True). Setting it to False preserves raw LOS labels in hours for models requiring unnormalized targets.
  • Compatibility with PyHealth's current YAIB task and RNN_V2 interfaces.

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 read pyhealth/datasets/configs/eicu.yaml to 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_FEATURES constant 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:

  • Model A: trained with 0% additional observation removal.
  • Model B: trained with 10% additional observation removal.
  • The validation set uses the same missingness rate as the corresponding training set (0% for Model A and 10% for Model B).
  • Both models are evaluated under 0%, 10%, and 20% additional observation removal on held-out test patients.

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

  • Dataset: A subset of 15,000 eICU-CRD patients used in the pre-rebase experiments. Patient subsampling was performed outside the example script.
  • Patient-disjoint split: 70% training, 15% validation, and 15% testing.
  • Random seed: 42 for patient-level splitting and reproducible experiment configuration.
  • Model: PyHealth RNN_V2 (LSTM).
  • Embedding dimension: 64.
  • Hidden dimension: 128.
  • Number of layers: 2.
  • Dropout: 0.2.
  • Learning rate: 0.00129.
  • Batch size: 128.
  • Training epochs: 8.
  • Decay features: enabled.
  • Training objective: MSE loss on normalized remaining-LOS targets.
  • Evaluation metrics: MAD, MAPE, MSE, MSLE, R², and Cohen's linear weighted Kappa.

Evaluation Metrics

LOS targets and predictions are converted from hours to days before evaluation.

Following the metric conventions described in the original paper:

  • MAD measures mean absolute prediction error.
  • MAPE uses a minimum target denominator of 4 hours to prevent numerical instability near discharge.
  • MSE measures squared prediction error.
  • MSLE clips targets and predictions to the interval [1/48, 100] days before computing squared log-space error.
  • R² measures the coefficient of determination.
  • Cohen's linear weighted Kappa uses 10 ordered LOS categories: 0–1, 1–2, 2–3, 3–4, 4–5, 5–6, 6–7, 7–8, 8–14, and 14+ days.

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.

Model Train Drop Test Drop MAD MAPE (%) MSE MSLE R² Kappa
Mean Baseline 0% 0% 3.336 413.3 28.24 2.750 -0.002 0.000
Median Baseline 0% 0% 2.837 187.8 31.32 2.008 -0.111 0.000
LSTM A 0% 0% 2.859 260.7 24.72 2.266 0.123 0.253
LSTM A 0% 10% 2.839 255.6 24.79 2.256 0.120 0.247
LSTM A 0% 20% 2.819 251.1 24.84 2.223 0.118 0.243
LSTM B 10% 0% 2.893 271.6 24.74 2.205 0.122 0.252
LSTM B 10% 10% 2.869 266.3 24.76 2.189 0.121 0.247
LSTM B 10% 20% 2.844 261.1 24.77 2.153 0.121 0.243

Findings

  • The mean and median baselines are reasonably consistent with those reported in the original paper.
  • Under the 0% additional missingness condition, our standard LSTM achieves an MSE of 24.72, compared with 24.5 for the standard LSTM (MSE) reported in the original paper.
  • When test missingness increases from 0% to 20%, Model A's MSE increases by 0.12, whereas Model B's MSE increases by only 0.03.
  • Under the same increase in test missingness, Model A's R² decreases by 0.005, whereas Model B's R² decreases by only 0.001.
  • Model B demonstrates improved MSE, R², and MSLE relative to Model A under the 10% and 20% additional missingness conditions, although the improvement is not consistent across all metrics.

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

python examples/eicu_hourly_los_lstm.py --synthetic --epochs 2

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

python examples/eicu_hourly_los_lstm.py --root /path/to/eicu-crd --batch-size 128 --epochs 8 --lr 0.00129 --embedding-dim 64 --hidden-dim 128 --num-layers 2 --dropout 0.2 --seed 42

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 --root should 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

python -m pytest tests/core/test_tpc_eicu.py tests/core/test_tpc_checkpoint.py -q

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:

  • 35 tests in tests/core/test_tpc_eicu.py passed, including the end-to-end synthetic training smoke test.
  • 1 synthetic CSV-to-task checkpoint test passed.
  • Total: 36 passed, 0 failed, 0 skipped.
  • Independent RNN_V2 smoke test passed.
  • Git diff whitespace and conflict-marker checks passed.

The independent RNN_V2 smoke test successfully verified:

  • Synthetic patient and sample generation.
  • SampleDataset construction.
  • Model initialization with dynamic, static, and decay features.
  • Forward propagation.
  • Finite loss computation.
  • Backward propagation.
  • Optimizer parameter updates.
  • Model prediction.

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:

  • Updated the task to use _static_record instead of _static_series.
  • Adopted the inherited single ordering for static features.
  • Explicitly included optional decay features in the prediction timeline when enabled.
  • Added a regression test to ensure that optional timeline configuration does not affect other task instances.

These changes preserve the intended temporal alignment and prevent optional decay features from being treated as whole-stay information during hourly prediction.

Checklist

  • Standalone task implemented using an existing PyHealth dataset.
  • Existing PyHealth model used for evaluation.
  • API documentation and documentation index updated.
  • Example script and missingness ablation study included.
  • Synthetic data and comprehensive task tests included.
  • Original paper referenced.
  • Rebased onto the upstream master branch.
  • Upstream API compatibility addressed.
  • Implementation dependencies documented.
  • Experimental configuration and pre-rebase results documented.
  • All 36 task and checkpoint tests passed locally after the maintainer-requested updates.
  • Independent RNN_V2 training and prediction smoke test passed after the rebase.
  • Remaining-LOS labels clamped to a minimum of 0.5 hours.
  • Optional label normalization implemented.
  • Committed synthetic CSV files documented as illustrative examples.
  • Checkpoint test moved into the core CI test suite.
  • All four maintainer-requested changes addressed.

Thank you for reviewing our contribution. We welcome feedback and suggestions from the PyHealth maintainers.

ahling21 and others added 30 commits November 26, 2026 15:30
Add complete docstring
Add docstring
Add docstring and 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

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous review

Reviewed commit daa9bcd

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_smoke in tests/core loads 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.0 is 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/*.csv files 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

@solarsys

Copy link
Copy Markdown
Collaborator

Why this PR has status: manual: three open PRs add a TPC model, #1412, #1428 and #1574 (#1412 and #1428 both claim BTY-72). #1428 and #1627 both add an eICU length-of-stay task. A maintainer has to pick one model and one eICU task.

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: tests/integration/test_tpc_checkpoint.py never runs in CI, which only runs tests/core and tests/nlp. Please move it under tests/core/ or drop it.

@solarsys

Copy link
Copy Markdown
Collaborator

Picked as PyHealth's hourly eICU length-of-stay task. It's the only clean BaseTask built on the existing eICUDataset:

  • hourly causal labels from hour 5;
  • decay features;
  • a seeded missingness ablation;
  • 97% coverage, and the AI review suggests approve.

The TPC model will be #1412.

Before it can merge:

  1. Don't emit zero labels. The test expects [0] for a 5-hour stay, and a zero target breaks MSLE. Clamp remaining length of stay to at least 0.5 h (1/48 day), or drop those hours.
  2. Add an option to turn off YAIB's min-max label normalization. MSLE models need raw days or hours.
  3. Remove the synthetic CSVs in examples/tpc_support/synthetic_eicu/, or say what uses them.
  4. Move tests/integration/test_tpc_checkpoint.py under tests/core/ or drop it. CI doesn't run tests/integration.

Once these fixes are pushed, we'll move this PR to status: automatic and request an AI review. If the review approves, it merges.

@ahling21

Copy link
Copy Markdown
Contributor Author

Picked as PyHealth's hourly eICU length-of-stay task. It's the only clean BaseTask built on the existing eICUDataset:

  • hourly causal labels from hour 5;
  • decay features;
  • a seeded missingness ablation;
  • 97% coverage, and the AI review suggests approve.

The TPC model will be #1412.

Before it can merge:

  1. Don't emit zero labels. The test expects [0] for a 5-hour stay, and a zero target breaks MSLE. Clamp remaining length of stay to at least 0.5 h (1/48 day), or drop those hours.
  2. Add an option to turn off YAIB's min-max label normalization. MSLE models need raw days or hours.
  3. Remove the synthetic CSVs in examples/tpc_support/synthetic_eicu/, or say what uses them.
  4. Move tests/integration/test_tpc_checkpoint.py under tests/core/ or drop it. CI doesn't run tests/integration.

Once these fixes are pushed, we'll move this PR to status: automatic and request an AI review. If the review approves, it merges.

Thank you for selecting our task implementation and for the constructive feedback!

All four requested changes have been addressed in commits 4d747aaf and 53bbffbe:

  1. Clamped remaining LOS labels to a minimum of 0.5 hours.
  2. Added the normalize_labels=False option to preserve raw LOS targets in hours for MSLE-based models.
  3. Clarified the purpose of the committed synthetic CSV files in both the PR description and API documentation.
  4. Moved test_tpc_checkpoint.py to tests/core/ and removed the opt-in environment variable requirement so that it runs in the core test suite.

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!

@solarsys

Copy link
Copy Markdown
Collaborator

/review

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous review

Reviewed commit 53bbffb

Comment thread examples/eicu_hourly_los_lstm.py Resolved

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 behind PYHEALTH_RUN_TPC_INTEGRATION. In the diff it is tests/core/test_tpc_checkpoint.py and 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 in test_tpc_eicu.py.
  • Placement of the new import: In pyhealth/tasks/__init__.py the 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_smoke passes.

Reviewed commit 53bbffb

Comment thread examples/eicu_hourly_los_lstm.py Resolved
@ahling21

Copy link
Copy Markdown
Contributor Author

Hi @solarsys, thank you for the feedback!

All additional AI review suggestions have been addressed in commit 403ad23c, including:

  • Updated the PR description with the correct test location and count.
  • Reorganized the task import and consolidated module docstrings.
  • Removed import-time environment and path side effects.
  • Fixed constant baseline reporting for non-zero test missingness rates and added regression coverage.
  • Removed the redundant implementation summary.

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!

@solarsys

Copy link
Copy Markdown
Collaborator

/review

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous review

Reviewed commit 403ad23

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 reading eicu.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.py is 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
solarsys previously approved these changes Nov 29, 2026

@solarsys solarsys left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving as PyHealth's hourly eICU length-of-stay task (the TPC task). Thanks for fixing the zero labels and the normalization option.

@solarsys

Copy link
Copy Markdown
Collaborator

Approved. One step left: #1412 merged just before this, and both PRs add export lines at the same spot in pyhealth/tasks/__init__.py, so this branch now conflicts there. Please rebase on master and keep both sets of lines. After you push, we'll request a fresh AI review and re-approve. The rebase will dismiss this approval, which is expected.

@solarsys

Copy link
Copy Markdown
Collaborator

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed commit 6ac4bb7

from .yaib_eicu import _DYNAMIC_FEATURES, YAIBLengthOfStayEICU


class TPCLengthOfStayEICU(YAIBLengthOfStayEICU):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown

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.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 read eicu.yaml.
  • Coverage meets the bar. tpc_eicu.py is at 97.4%, tasks/__init__.py at 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, TPCDayOne and examples/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__.py has lost its trailing newline. Restoring it would keep the diff clean.

Reviewed commit 6ac4bb7

@solarsys solarsys left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approving on the rebased commit (AI review suggests approve on 6ac4bb7).

@solarsys
solarsys merged commit 12fb659 into sunlabuiuc:master Nov 29, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: manual Pending maintainer's review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants