Repository navigation
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
changed header
added header
Updated with new info
updated header
Test CoverageTotal: 86.76% (48483 / 55882 lines)
|
|
/review |
| ) | ||
| parser.set_defaults(include_decay=True) | ||
| parser.add_argument("--epochs", type=int, default=8) | ||
| parser.add_argument("--batch-size", type=int, default=64) |
There was a problem hiding this comment.
[medium] Default batch size contradicts documented setting
The documented setting is batch_size=128 (module docstring, line 49, and the PR description), but the CLI default here is 64 (train_and_evaluate also defaults to 64 at line 357). The documented command python examples/eicu_hourly_los_lstm.py --root /path/to/eicu-crd therefore trains with a different batch size and does not reproduce the reported table. Set the default to 128 in both places, or correct the documented setting.
| from pyhealth.data import Patient | ||
|
|
||
| # Every column of the eICU config, as in the dataset's event dataframe. | ||
| _CONFIG = yaml.safe_load( |
There was a problem hiding this comment.
[medium] Test fixtures read the eICU dataset config, which the description does not explain
The fixture loads pyhealth/datasets/configs/eicu.yaml to derive its column list. examples/tpc_support/generate_synthetic.py:38 does the same. This makes the tests and synthetic data depend on another component's config, and that link is not mentioned in the description. Either explain the link in the description and say why, or keep these helpers self-contained by listing the columns they need directly.
| DEFAULT_TEST_RATES = (0.0, 0.1, 0.2) | ||
|
|
||
|
|
||
| def compute_los_metrics( |
There was a problem hiding this comment.
[low] New LOS metrics are untested and partly duplicate existing metrics
compute_los_metrics implements MAD and MSE, which pyhealth/metrics/regression.py already provides through regression_metrics_fn and timeseries_regression_metrics_fn. The MAPE floor, MSLE clipping and kappa binning are untested, yet they produce the reported table. A few unit tests for this function would cover them, and the MAE/MSE part could reuse the existing metric functions.
There was a problem hiding this comment.
AI Review
suggestion: need change
decision: human review
Thank you for this contribution. It adds an hourly remaining-LOS task for eICU (TPCLengthOfStayEICU) that extends the YAIB task. It also adds a missingness-robustness example, synthetic data and tests. Coverage is good: tpc_eicu.py is at 97.3% and the whole repository is at 86.65%, which is above the bar. The task is self-contained, and the only shared-file edit is its export in tasks/init.py.
To get this merged:
- The example's
--batch-sizedefaults to 64 (and so doestrain_and_evaluate). The docstring, the description and the reported results all use 128. Please change the default to 128, or say in the docs which setting produced the table, so that the documented command reproduces the results. examples/tpc_support/generate_synthetic.pyandtests/core/tpc_fixtures.pyboth readpyhealth/datasets/configs/eicu.yaml. The description doesn't mention this. Please either confirm in the description that this coupling is intended and say why (for example, to keep the CSV schema in sync with the dataset config), or make those files self-contained.- The description says the task reuses YAIB's private helpers and the
_DYNAMIC_FEATURESconstant, and it also says the task "extends" YAIB. Please add one sentence saying why these private internals are reused. For example, say that they're reused so the preprocessing matches YAIB, and note that changes to YAIB will therefore affect this task.
Optional suggestions:
- Add tests for the example's MAPE, MSLE and Kappa code. You could also reuse
pyhealth.metrics.regressionfor MAE and MSE, but only if you choose to share that code and explain why. - The committed
synthetic_eicu/CSVs aren't used by any code, because the generator rewrites them. Consider removing them or documenting their purpose. - The task's cohort drops YAIB's base-cohort exclusions. A short note in the docs would help.
- The reported numbers were produced before the rebase. Rerunning the full experiment, or stating this prominently in the docs, would help.
- The description text is duplicated (an HTML copy and a Markdown copy). Please tidy it.
- Move the
from .tpc_eicu import ...line intasks/__init__.pyup with the other imports.
Reviewed commit 4af6fe2
|
Thank you for the helpful review. We have addressed all three main review comments:
We also cleaned up the duplicated PR description, clarified cohort selection and synthetic CSV usage, and prominently identified the experimental results as pre-rebase results. All 30 unit and integration tests passed after the update, and Updated commit: Thank you for your feedback. |
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.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:
Observation removal is performed before imputation. Both models use identical patient-level splits and deterministic test masking to ensure comparable evaluation conditions.
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, and optional decay features.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 synthetic CSV files representing the required eICU clinical tables. These files provide inspectable examples of the synthetic data format. The generator regenerates the synthetic CSV files during execution.Tests
tests/core/test_tpc_eicu.py— Unit tests covering cohort eligibility, static features, hourly aggregation, remaining-LOS labels, observation removal, decay, temporal leakage prevention, stay isolation, and timeline configuration.tests/core/tpc_fixtures.py— Reusable synthetic patient fixtures.tests/integration/test_tpc_checkpoint.py— Opt-in synthetic CSV-to-task integration test.Usage Examples
Run the Synthetic-Data Example
Run the Full Missingness Ablation Study
To reproduce the reported experimental setup, use the same 15,000-patient eICU subset. Running this command on a different patient cohort may produce different numerical results.
Run the Unit Tests
Run the Unit and Integration Tests
Linux/macOS:
Windows CMD:
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 compatibility updates, the following checks were completed:
The independent RNN_V2 smoke test successfully verified:
The CSV integration test is opt-in to avoid unnecessary data-loading overhead during routine unit testing.
Post-Rebase Validation Scope
The full synthetic training example was also attempted after rebasing but was interrupted during event-dataframe cache construction in the local Windows environment.
An independent in-memory smoke test was subsequently used to verify the core model training and prediction functionality.
The post-rebase tests validate the task implementation and its compatibility with RNN_V2. They do not constitute a complete rerun of the pre-rebase 15,000-patient experiment.
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.