Repository navigation
Add PhysioNet2012InHospitalMortality task - #1572
Conversation
Standalone task for PhysioNet 2012 in-hospital mortality prediction on top of the existing PhysioNet2012Dataset: hourly-binned time series, static features, configurable variants, tests, docs and an example ablation script. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Test CoverageTotal: 86.57% (47527 / 54899 lines)
|
|
/review |
There was a problem hiding this comment.
Previous review
AI Review
suggestion: need change
decision: need change
Thank you for this contribution. It adds a PhysioNet 2012 in-hospital mortality task that follows the TransEHR input layout. It also adds a train-only normalization helper, tests, docs and an ablation example. It is close. Coverage is above the bar: 94.5% for the new task file, 98% for tasks/__init__.py and 86% for the whole repository.
To get this merged:
- The task imports the private helper
_hourly_meansfrompyhealth/tasks/physionet2012_forecasting.py. It uses it inphysionet2012_normalization. The description doesn't mention this link between components. Please either say in the description that the sharing is intended, and why, or keep the task self-contained by copying the helper. examples/physionet2012_mortality_logreg.mddoesn't match the script. The .md calls the model a "class-weighted logistic regression on per-stay summaries (mean, last value, observed fraction)". The script uses no class weights. It feeds the hourly grid to PyHealth'sLogisticRegression, which embeds the inputs. Please correct the description of the model and the ablation setup.
Optional suggestions:
- The .md has a literal
\nin the Setup bullet, and both example files start with a BOM character. Weightis recorded at 00:00 as a patient descriptor in the dataset. Check whether its grid column is mostly empty, and mention it if so.- The claim that
VITAL_VARIABLESwas reconstructed from the authors' code is hard for readers to verify. A short note on how it was derived would help.
Reviewed commit 14b6d03
|
/review Generated by Claude Code |
There was a problem hiding this comment.
Previous review
AI Review
suggestion: need change
decision: need change
Thank you for this contribution. It adds a TransEHR-style in-hospital mortality task for PhysioNet 2012. It comes with a normalization helper, 18 synthetic-data tests, docs, and a logistic-regression ablation example. It is close to ready.
To get this merged:
pyhealth/tasks/physionet2012_mortality.pyimports the private helper_hourly_meansfromphysionet2012_forecasting.py, andphysionet2012_normalizationuses it. Your code comment explains the reason (the two tasks bin hourly means the same way), but the PR description doesn't mention this link. Please do one of two things. Either confirm in the description that the sharing is intended and say why, for example by copying your code comment. Or make the task self-contained by copying the helper into this module. Either option is fine.
Optional suggestions:
- The example's
GridMortalitydrops the lab-event stream, so the ablation never exercises that part of the task. A sentence in the.mdsaying so would help readers. The docstring mentions it, but the results discussion doesn't. physionet2012_normalizationtakes statistics over non-zero values, while the grid treats 0 as a valid observation. This is documented, but you could note it for variables where 0 is plausible.
Coverage: physionet2012_mortality.py is at 94.5%, above the 80% bar for the file. Total repository coverage is 86.3%, above the 60% bar.
Reviewed commit 41e0c0c
|
/review Generated by Claude Code |
2425011 to
e36d37f
Compare
Keep upstream's PhysioNet2012Mortality in physionet2012_mortality.py and move PhysioNet2012InHospitalMortality (TransEHR layout) to physionet2012_inhospital_mortality.py; update exports, docs, tests and example.
|
/review |
There was a problem hiding this comment.
Previous review
AI Review
suggestion: need change
decision: need change
Thank you for this contribution. It adds a TransEHR-style in-hospital mortality task for PhysioNet 2012. It has an hourly grid with observation and padding masks, a lab-event stream, static features and training-only normalization. It also comes with an example script, docs and tests. It is close, and coverage is fine: the new task file is at 94.5% (bar 80%) and the whole repository is at 86.6% (bar 60%).
To get this merged:
- Check the
Weightcolumn. As I readpyhealth/datasets/physionet2012.py(read_record, around lines 149-150), the 00:00Weightdescriptor goes into thepatientstable and not into theeventstable. The grid andphysionet2012_normalizationread onlyevents. So the figures inexamples/physionet2012_mortality_logreg.md("92% of stays have it at hour 0", "53% of grid cells observed") probably don't describe this grid. Normalization would also raise if no in-stayWeightevent exists. Please either feed the admission weight into the grid (or into the static features), or correct the markdown and docstrings to say what the column holds. Add a test that checksWeightvalues. The synthetic test data writes00:00,Weight,80, so it should show which behavior you get. - Fix the description's file list. It names
pyhealth/tasks/physionet2012_mortality.pyandtests/core/test_physionet2012_mortality.py. The diff actually addspyhealth/tasks/physionet2012_inhospital_mortality.pyandtests/core/test_physionet2012_inhospital_mortality.py.
Optional suggestions:
- PyHealth already has
PhysioNet2012Mortality. Please add a sentence to the class docstring and the docs page on how this task differs from it (TransEHR hourly grid plus event stream, versus the existing irregular layout). - Revert the unrelated heading change at the top of
docs/api/tasks.rst. - The
_hourly_meanssharing is explained clearly in the description, so no action is needed there.
Reviewed commit a240572
|
/review |
| icu, height = number("icutype"), number("height") | ||
| return np.array( | ||
| [ | ||
| 0.0 if np.isnan(age) else age, |
There was a problem hiding this comment.
[low] Missing age silently encoded as 0
_static maps a missing age to 0.0 (0.0 if np.isnan(age) else age), which is an out-of-range value for an ICU adult and is not mentioned in the class docstring. Missing height is documented as filled with height_fill, so the age case is inconsistent. Either document the age fill in the static description, or add a fill parameter (e.g. the cohort median) like height_fill.
| VITAL_VARIABLES = ( | ||
| "DiasABP", "Glucose", "HR", "MAP", "RespRate", "SysABP", "Temp", | ||
| ) | ||
| """Regularly sampled measurements. The authors' ``feature_meta.json`` (read by |
There was a problem hiding this comment.
[low] Vitals docstring asserts an unverified property
The VITAL_VARIABLES docstring calls these 'Regularly sampled measurements', but the list is taken from a commented-out line in another repository, not from the paper. Glucose, for example, is usually an irregularly timed lab. Say only that the list follows that commented line, or drop the 'regularly sampled' claim, since the feature_groups ablation depends on this split.
| } | ||
|
|
||
|
|
||
| class PhysioNet2012InHospitalMortality(BaseTask): |
There was a problem hiding this comment.
[low] Existing PhysioNet2012Mortality task not mentioned
PhysioNet2012Mortality already predicts in-hospital death on the same stays with the same 36 variables. The new task differs only in its input layout (hourly grid plus lab-event stream), which the docstring explains, so it is not redundant. Add one sentence to the class docstring and the docs page saying how the two differ and when to use each.
| model = LogisticRegression(samples, embedding_dim=args.embedding_dim) | ||
| trainer = Trainer( | ||
| model, metrics=["roc_auc", "pr_auc"], enable_logging=False, | ||
| output_path=args.output_dir, |
There was a problem hiding this comment.
[low] --output-dir has no effect
Trainer is created with enable_logging=False, which ignores output_path, so output_path=args.output_dir and the --output-dir option do nothing. Remove the option, or enable logging if checkpoints are wanted.
| .collect() | ||
| .sort("patient_id") | ||
| ) | ||
| ids = df["patient_id"].to_list() |
There was a problem hiding this comment.
[low] Split does not drop stays without an outcome
split_patients stratifies on every patient's in_hospital_death. If a release has stays without an outcome (the mortality task skips these, noting set c in some releases), the Int64 cast gives nulls and train_test_split's stratify fails. Keep only patients with a known outcome before splitting, as the task does.
There was a problem hiding this comment.
AI Review
suggestion: approve
decision: approve
Thank you for this contribution. It adds a TransEHR-style in-hospital mortality task for PhysioNet 2012. It includes a per-stay builder, training-only normalization, docs, an ablation example and 19 synthetic tests. It looks ready to merge.
The change is additive. It adds a new task module, docs and exports in pyhealth/tasks/__init__.py. It touches no base class, Trainer, registry or shared utility. The one link to another component is the private _hourly_means helper from the forecasting task. Your description names it and explains why: both tasks need identical hourly binning. That meets the bar.
Coverage is above the bar. The new task file is at 94.5% (bar 80%) and the repository total is 86.6% (bar 60%). Your description cites the TransEHR paper for the task's input layout.
Optional suggestions:
- Missing age is silently encoded as 0, while missing height gets a documented fill. Please document this, or add an
age_filloption. - The vitals docstring calls them "regularly sampled". The note about the authors' source may be enough, so you could soften that claim.
--output-dirin the example does little because Trainer logging is disabled. You could remove it or explain it.split_patientsin the example would fail if a stay had no outcome. Filtering those stays first would avoid that.docs/api/tasks.rsthas an unrelated title-underline change that you could revert.- You could mention the existing
PhysioNet2012Mortalitytask in the description and say how this one differs. It uses the hourly grid and the lab-event stream.
Reviewed commit 1c5f416
Contributors: Sadegh Nassiri (GT username: snassiri6, email: snassiri6@gatech.edu), Kaushal Seelam (GT username: kseelam3, email: kseelam3@gatech.edu).
Contribution Type: Standalone Task (new task + tests + docs + example ablation script).
Paper: Xu et al., "TransEHR: Self-Supervised Transformer for Clinical Time Series Data", PMLR 225 (ML4H 2023), https://proceedings.mlr.press/v225/xu23a.html
Description:
This PR adds an in-hospital mortality task for PhysioNet 2012 whose inputs follow the TransEHR preprocessing. It uses the existing
PhysioNet2012Datasetwith no dataset code changes. The only cross-module link is the shared_hourly_meanshelper (see "Shared code with the forecasting task" below).PhysioNet2012InHospitalMortality(task): per stay, an hourly measurement grid + observation mask + padding mask (48 h x 36 variables), a values-free lab-event stream (times and types, padded to 400), and 8 static features; label is in-hospital death. Options:feature_groups(vitals / labs),icu_types,observation_hours,clip,center/scale.physionet2012_normalization(dataset, patient_ids=...):(x - median) / (p95 - p5)statistics from the given (training) patients only, to avoid leakage.build_mortality_sample: the pure per-stay function behind the task.examples/physionet2012_mortality_logreg.py(+.md): compares task variants with PyHealth'sLogisticRegressionandTrainer;--syntheticneeds no data.Shared code with the forecasting task
The mortality task imports the private helper
_hourly_meansfrompyhealth/tasks/physionet2012_forecasting.pyand uses it to bin observations into hourly means (inphysionet2012_normalization). This is deliberate: both tasks must bin hours identically, so the two feature pipelines can't drift apart. The trade-off is that the mortality task now depends on the forecasting module, and a change to_hourly_meansaffects both tasks.Ablation (one patient-level split, single run, test AUROC / AUPRC x100; details in
examples/physionet2012_mortality_logreg.md):clip=10No spread is available (single run), so small differences are not evidence.
Files to Review:
pyhealth/tasks/physionet2012_inhospital_mortality.py- task and normalizationtests/core/test_physionet2012_inhospital_mortality.py(19 tests, synthetic data only)examples/physionet2012_mortality_logreg.pyand.mddocs/api/tasks/pyhealth.tasks.PhysioNet2012InHospitalMortality.rst,docs/api/tasks.rstpyhealth/tasks/__init__.py- exports only