Skip to content

SEER dataset and fixed-horizon survival task with temporal split and all-cause label (Hegselmann et al., MLHC 2018) - #1735

Open
HowardLiu0830 wants to merge 1 commit into
sunlabuiuc:masterfrom
HowardLiu0830:seer-survival-benchmark
Open

HowardLiu0830 wants to merge 1 commit into
sunlabuiuc:masterfrom
HowardLiu0830:seer-survival-benchmark

Conversation

@HowardLiu0830

Copy link
Copy Markdown

Contributor: Howard Liu (NetID: yl140)

Contribution Type: Dataset + Task (CS 598 DL4H final project, Option 1)

Paper: Hegselmann et al., Reproducible Survival Prediction with SEER Cancer Data, MLHC 2018.
https://proceedings.mlr.press/v85/hegselmann18a.html

Description:

  • SEERDataset loads a SEER*Stat case-listing export as one event per tumor record. It checks the required columns, patient IDs and diagnosis years before writing anything, and temporal_split splits patients by year of diagnosis.
  • SEERSurvivalPrediction labels each record with survival at a fixed horizon (Algorithm 1 of the paper). competing_risk="negative" gives an all-cause label instead. Features use the paper's two encodings (numeric and one-hot), fitted on the training patients. Follow-up and cause-of-death columns cannot be features.
  • examples/seer_survival_prediction_mlp.py replicates the paper's encoding comparison with PyHealth's LogisticRegression and MLP, and adds three ablations that are not in the paper: a temporal split against a random one, the all-cause label against the cancer-specific one, and retraining without groups of features (the paper's attribute analysis zeroes inputs of a trained model). Results for lung cancer (2004-2009, 12 and 60 months) are in its docstring next to the paper's Table 3. It runs on generated data with --synthetic.
  • Tests and the example use synthetic data only. No patient-level SEER data or trained weights are included.

Relation to #1561: #1561 implements the same paper. This PR was developed independently for the course. What it has that #1561 does not: the temporal split, the all-cause label, 60-month results, and the administrative and staging-only feature sets. I can rebase these onto #1561 once it merges.

Files to Review:

  • pyhealth/datasets/seer.py - dataset, export validation, temporal split
  • pyhealth/datasets/configs/seer.yaml - config
  • pyhealth/tasks/seer_survival_prediction.py - task
  • tests/core/test_seer_dataset.py, tests/core/test_seer_survival_prediction.py, tests/core/seer_test_utils.py - 35 tests on a synthetic 5-patient export
  • examples/seer_survival_prediction_mlp.py - replication, ablations, results
  • docs/api/datasets/pyhealth.datasets.SEERDataset.rst, docs/api/tasks/pyhealth.tasks.SEERSurvivalPrediction.rst, docs/api/datasets.rst, docs/api/tasks.rst - API docs and index entries

Reproduces Hegselmann et al., Reproducible Survival Prediction with SEER
Cancer Data (MLHC 2018), https://proceedings.mlr.press/v85/hegselmann18a.html

- SEERDataset loads a SEER*Stat case-listing export as one event per tumor
  record, validates it, and splits patients by year of diagnosis.
- SEERSurvivalPrediction labels each record with survival at a fixed
  horizon (Algorithm 1 of the paper), with an all-cause variant, and encodes
  features in the paper's numeric and one-hot ways.
- The example replicates the encoding comparison with LogisticRegression
  and MLP and adds split, label and feature-group ablations. It runs on
  generated data with --synthetic.
- Tests use a synthetic five-patient export. No patient-level SEER data is
  included.
@github-actions

Copy link
Copy Markdown

Test Coverage

Total: 88.23% (57646 / 65334 lines)

Modified file Coverage Lines
pyhealth/datasets/__init__.py 100.00% 92 / 92
pyhealth/datasets/seer.py 98.41% 124 / 126
pyhealth/tasks/__init__.py 98.57% 138 / 140
pyhealth/tasks/seer_survival_prediction.py 98.01% 148 / 151

Workflow run · c434527

@solarsys solarsys added the status: manual Pending maintainer's review label Nov 30, 2026
@solarsys

Copy link
Copy Markdown
Collaborator

Why this PR has status: manual: overlap. Two other PRs add a SEER dataset and survival task: #1561, which the maintainers picked as the SEER base, and #1667. PyHealth keeps one implementation per component.

What you can contribute instead: after #1561 merges, rebase and add only what yours has that it doesn't, as options on #1561's dataset and task. Your temporal split and fixed-horizon options are two possibilities. To help a maintainer decide, please comment here with what your PR does that the other doesn't. Whichever isn't picked can contribute its unique parts on top of the chosen one. Overlaps are tracked in #1668.

@solarsys

Copy link
Copy Markdown
Collaborator

#1561 (the SEER dataset and survival task, picked as the SEER base) has merged. You can now rebase on master and contribute only what yours adds, as options on the merged SEERDataset and task, with tests in tests/core, as described in my earlier comment.

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.

Reviewed commit c434527

if continuous_columns is not None
else SEER_CONTINUOUS_FEATURES
)
if feature_columns is not None and continuous_columns is not None:

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] continuous_columns is only checked against feature_columns when both are passed

The check runs only when feature_columns and continuous_columns are both given. With the default continuous set and a custom feature list, continuous features that are not in the list are dropped silently, while the Raises text on line 201 says a continuous column that is not a feature raises ValueError. Either validate against the effective feature set, or change the Raises text to say the check applies when both are passed. Keep the silent drop if it is intended, since the tests rely on it.

if self.encoding == "numeric":
if number is None and raw is not None:
codes = self.category_codes.get(name, {})
if text not in codes:

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] encoding="numeric" fails on a blank feature cell with a misleading message

category_codes skips empty strings (pyhealth/datasets/seer.py:312), so a blank cell in a feature column has no code. Here it raises 'has the text value ... pass category_codes=...', which does not describe the problem. Onehot encoding handles the same cell as a missing value. Treat blank cells as missing (NaN, imputed to zero) in numeric encoding, or raise an error that names the blank cell.

Comment thread pyhealth/datasets/seer.py
raise ValueError(f"Rename the export: {export.name} is written by PyHealth")

table = pd.read_csv(
export, sep=None, engine="python", dtype=str, keep_default_na=False

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] Delimiter is sniffed with sep=None

pd.read_csv(sep=None) guesses the delimiter from the file. Values that contain candidate delimiters, such as the semicolon in 'Poorly differentiated; Grade III', can make the guess wrong, and the export is then read as a different column set. Consider detecting the delimiter from the header (for example, checking that the header has more than one column) and failing with a clear message, or accepting an explicit sep argument.

@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, Howard. It adds a SEER*Stat dataset with export validation and a temporal split, plus a fixed-horizon survival task with an all-cause label option, an example, docs and tests. It looks ready to merge. The change is self-contained, the dataset cites its sources, the docs match the code, and coverage meets the bar (repository 88.23%; seer.py 98.4%; seer_survival_prediction.py 98.0%). The overlap with #1561 is named in the description.

Optional suggestions:

  • The Raises text says a continuous column that is not a feature raises ValueError, but the check only runs when both feature_columns and continuous_columns are passed. Align the docstring or the check.
  • encoding="numeric" raises on a blank feature cell. Treating it as missing (NaN) or documenting it would help.
  • sep=None delimiter sniffing can misparse unusual exports; an optional sep argument would help.
  • #1561 uses the same class name, so the two PRs will conflict. A maintainer will need to decide the order.

Reviewed commit c434527

@jhnwu3

jhnwu3 commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Duplicate: the SEER dataset is already in PyHealth (pyhealth/datasets/seer.py), merged in #1561. The fixed-horizon task with a temporal split may still be new; if so, a PR adding just that task on the existing SEERDataset is welcome.

We're keeping this PR open for now, and it may already have an AI review for feedback on your code, but we're unlikely to merge a second implementation. If your version adds something the existing one lacks (for example a different dataset, task or ablation), a focused follow-up PR that builds on it is very welcome; please link this PR from it. Before opening a PR, please check master and open PRs for the same component.

@jhnwu3 jhnwu3 added the duplicate Duplicates an existing PR or a component already on master label Dec 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate Duplicates an existing PR or a component already on master status: manual Pending maintainer's review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants