Skip to content

Add PhysioNet2012InHospitalMortality task - #1572

Merged
solarsys merged 6 commits into
sunlabuiuc:masterfrom
sadegh-n:transehr-physionet2012
Nov 27, 2026
Merged

solarsys merged 6 commits into
sunlabuiuc:masterfrom
sadegh-n:transehr-physionet2012

Conversation

@sadegh-n

@sadegh-n sadegh-n commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

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 PhysioNet2012Dataset with no dataset code changes. The only cross-module link is the shared _hourly_means helper (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.
  • Example examples/physionet2012_mortality_logreg.py (+ .md): compares task variants with PyHealth's LogisticRegression and Trainer; --synthetic needs no data.

Shared code with the forecasting task

The mortality task imports the private helper _hourly_means from pyhealth/tasks/physionet2012_forecasting.py and uses it to bin observations into hourly means (in physionet2012_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_means affects both tasks.

Ablation (one patient-level split, single run, test AUROC / AUPRC x100; details in examples/physionet2012_mortality_logreg.md):

Variant AUROC AUPRC
all variables, 48 h 83.2 51.1
vitals only 74.4 31.8
labs only 82.6 50.2
24 h window 80.8 43.6
clip=10 83.3 51.4
ICU type 1 only (smaller cohort, not comparable) 73.9 39.8

No spread is available (single run), so small differences are not evidence.

Files to Review:

  • pyhealth/tasks/physionet2012_inhospital_mortality.py - task and normalization
  • tests/core/test_physionet2012_inhospital_mortality.py (19 tests, synthetic data only)
  • examples/physionet2012_mortality_logreg.py and .md
  • docs/api/tasks/pyhealth.tasks.PhysioNet2012InHospitalMortality.rst, docs/api/tasks.rst
  • pyhealth/tasks/__init__.py - exports only

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>
@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Test Coverage

Total: 86.57% (47527 / 54899 lines)

Modified file Coverage Lines
pyhealth/interpret/__init__.py 100.00% 4 / 4
pyhealth/interpret/uni_acs.py 82.35% 182 / 221
pyhealth/tasks/__init__.py 98.13% 105 / 107
pyhealth/tasks/physionet2012_inhospital_mortality.py 94.52% 138 / 146

Workflow run · 1c5f416

@jhnwu3 jhnwu3 added the status: automatic The PR will go through automatic review process. label Nov 23, 2026
@jhnwu3

jhnwu3 commented Nov 23, 2026

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 14b6d03

@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: 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:

  1. The task imports the private helper _hourly_means from pyhealth/tasks/physionet2012_forecasting.py. It uses it in physionet2012_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.
  2. examples/physionet2012_mortality_logreg.md doesn'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's LogisticRegression, which embeds the inputs. Please correct the description of the model and the ablation setup.

Optional suggestions:

  • The .md has a literal \n in the Setup bullet, and both example files start with a BOM character.
  • Weight is 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_VARIABLES was reconstructed from the authors' code is hard for readers to verify. A short note on how it was derived would help.

Reviewed commit 14b6d03

Copy link
Copy Markdown
Collaborator

/review


Generated by Claude Code

@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 41e0c0c

@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: 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.py imports the private helper _hourly_means from physionet2012_forecasting.py, and physionet2012_normalization uses 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 GridMortality drops the lab-event stream, so the ablation never exercises that part of the task. A sentence in the .md saying so would help readers. The docstring mentions it, but the results discussion doesn't.
  • physionet2012_normalization takes 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

Copy link
Copy Markdown
Collaborator

/review


Generated by Claude Code

@sadegh-n
sadegh-n force-pushed the transehr-physionet2012 branch from 2425011 to e36d37f Compare November 26, 2026 06:24
Keep upstream's PhysioNet2012Mortality in physionet2012_mortality.py and move
PhysioNet2012InHospitalMortality (TransEHR layout) to
physionet2012_inhospital_mortality.py; update exports, docs, tests and example.
@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 a240572

@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: 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:

  1. Check the Weight column. As I read pyhealth/datasets/physionet2012.py (read_record, around lines 149-150), the 00:00 Weight descriptor goes into the patients table and not into the events table. The grid and physionet2012_normalization read only events. So the figures in examples/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-stay Weight event 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 checks Weight values. The synthetic test data writes 00:00,Weight,80, so it should show which behavior you get.
  2. Fix the description's file list. It names pyhealth/tasks/physionet2012_mortality.py and tests/core/test_physionet2012_mortality.py. The diff actually adds pyhealth/tasks/physionet2012_inhospital_mortality.py and tests/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_means sharing is explained clearly in the description, so no action is needed there.

Reviewed commit a240572

@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 1c5f416

icu, height = number("icutype"), number("height")
return np.array(
[
0.0 if np.isnan(age) else age,

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] 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

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] 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):

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] 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,

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] --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()

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

@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: 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_fill option.
  • The vitals docstring calls them "regularly sampled". The note about the authors' source may be enough, so you could soften that claim.
  • --output-dir in the example does little because Trainer logging is disabled. You could remove it or explain it.
  • split_patients in the example would fail if a stay had no outcome. Filtering those stays first would avoid that.
  • docs/api/tasks.rst has an unrelated title-underline change that you could revert.
  • You could mention the existing PhysioNet2012Mortality task in the description and say how this one differs. It uses the hourly grid and the lab-event stream.

Reviewed commit 1c5f416

@solarsys
solarsys merged commit 1ba1d8f into sunlabuiuc:master Nov 27, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: automatic The PR will go through automatic review process.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants