Skip to content

Add SEER dataset and 12-month survival prediction - #1561

Merged
solarsys merged 5 commits into
sunlabuiuc:masterfrom
nrking0:seer-survival
Nov 30, 2026
Merged

solarsys merged 5 commits into
sunlabuiuc:masterfrom
nrking0:seer-survival

Conversation

@kushaal-manchella

Copy link
Copy Markdown
Contributor

Contributors

Contribution type

Dataset + task for CS 598. The experiment reuses PyHealth's logistic regression
and MLP.

Original paper

Hegselmann et al. (2018), Reproducible Survival Prediction with SEER Cancer
Data
. Paper

Description

This contribution adds support for locally exported SEER*Stat Case Listings
and fixed-horizon cancer survival prediction. The example reproduces the
12-month lung and bronchus comparison using the November 2025 SEER release.
It fits numeric and one-hot encoders on training patients and compares a
majority baseline, logistic regression, and an MLP.

On 20,446 held-out patients, the one-hot MLP achieved 0.8349 ROC-AUC, 0.7143 F1,
and 0.7627 accuracy. Removing AJCC stage, tumor size, extension, lymph nodes,
and metastases lowered ROC-AUC by 0.1146 on average over three matched model
seeds. The available Case Listing determined the feature group for this
ablation. The accompanying results explain the differences between the
current-release experiment and the paper's November 2016 experiment.

Files to review

  • pyhealth/datasets/seer.py and pyhealth/datasets/configs/seer.yaml load,
    validate, and group tumor events by patient.
  • pyhealth/tasks/seer_survival.py creates labels and diagnosis-time samples.
  • pyhealth/processors/seer_processor.py fits the two feature encodings.
  • pyhealth/datasets/__init__.py and pyhealth/tasks/__init__.py expose the
    dataset and task.
  • examples/seer_survival_mlp.py runs the benchmarks and grouped ablation.
    examples/seer_survival/ includes the setup, findings, aggregate scores,
    and saved cohort settings.
  • tests/core/test_seer_dataset.py and tests/core/test_seer_survival.py cover
    data loading, patient grouping, eligibility, features, and split-aware
    preprocessing. tests/core/conftest.py and tests/fixtures/seer/ supply the
    four-patient fixture.
  • docs/api/datasets/pyhealth.datasets.SEERDataset.rst and
    docs/api/tasks/pyhealth.tasks.SEERSurvivalPrediction.rst describe usage,
    with links from the respective API indexes.

Verification

python -m pytest -q tests/core/test_seer_dataset.py tests/core/test_seer_survival.py
python examples/seer_survival_mlp.py

The tests and synthetic example use generated data. The Case Listing and
patient-level caches stay in approved local storage.

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Test Coverage

Total: 88.35% (58458 / 66164 lines)

Modified file Coverage Lines
pyhealth/datasets/__init__.py 100.00% 93 / 93
pyhealth/datasets/seer.py 92.19% 59 / 64
pyhealth/processors/seer_processor.py 95.40% 83 / 87
pyhealth/tasks/__init__.py 98.59% 140 / 142
pyhealth/tasks/seer_survival.py 96.97% 32 / 33

Workflow run · 23d7c0f

@solarsys solarsys added the status: manual Pending maintainer's review label Nov 21, 2026
@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 8ea3065

@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 a SEER dataset loader, a fixed-horizon survival task, a fitted feature encoder, and a reproducible example that compares majority, logistic regression and MLP models. It also includes a grouped ablation. It looks ready to merge.

Coverage meets the bar. The whole repository is at 86.06%, against the 60% bar. seer.py is at 92.19%, seer_processor.py at 95.35% and seer_survival.py at 96.97%. Both __init__.py files are well above 80%.

The dataset, task and processor are self-contained. The only links are the example's reuse of PyHealth's LogisticRegression, MLP and Trainer, which your description states. The __init__.py changes only add exports. The paper is cited in the module docstrings and the README, and the docs page links to SEER data access.

Optional suggestions:

  • Task docs wording: the task page says to pass split= "at task creation". The code passes it to dataset.set_task(task, split=split), so please reword that sentence to match.
  • Numeric encoding: in numeric mode, tumor-size special codes such as 991 and 999 are standardized as if they were millimetres. This is arguably faithful to the paper's raw-code baseline. A sentence in the docs saying so, or a test that pins the behaviour, would make it clearer.
  • Reduced feature set test: a small test of SEERFeatureProcessor with include_extent=False would cover that path directly.
  • Binary session file: Lung_2004_2009_current.ss is committed as a binary. Please confirm it contains no local paths or user information. A short note in the README about what it contains would also help.

Reviewed commit 8ea3065

- Document that numeric encoding standardizes special codes such as
  tumor size 999 as numbers, and pin it with a test.
- Test that include_extent=False removes extent fields from the
  fitted processor.
- Say that split= goes to dataset.set_task in the task docs.
- Add Args/Returns/Raises to SEERSurvivalPrediction.__call__ and
  SEERFeatureProcessor.fit/process.
- Wrap the 90-character stage pattern line in seer.py.
- Note in the example README that the SEER*Stat session holds no
  patient records or local paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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 82444bd

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

Thank you for this contribution. It adds a SEER*Stat Case Listing dataset, a 12-month survival task, a training-only feature processor, docs, tests and a reproducible benchmark with an ablation. It is close. The tests are thorough, and coverage meets the bar: the whole repository is at 86.26%, and the new files are at 92.19% (seer.py), 95.35% (seer_processor.py) and 96.97% (seer_survival.py).

To get this merged:

  • SEERFeatureProcessor in pyhealth/processors/seer_processor.py subclasses the existing TensorProcessor, and the description doesn't mention this. Please do one of two things. Either confirm the sharing is intended and say why in the description, for example to reuse its dtype and process contract. Or keep the processor self-contained by deriving from the base processor class instead, or by copying what you need.
  • If you keep the subclass, please check the inherited methods. fit is overridden and doesn't set the attributes the parent's dim() and spatial() rely on, so those inherited calls may raise. Either set those attributes in fit or override the methods.

Optional suggestions:

  • SEERDataset._scan_table reads the whole export into memory before caching. A note in the docs would help users with large exports.
  • The task docs could say plainly that all unseen categories in a field share one indicator column, which is separate from the blank and special-size columns.

Reviewed commit 82444bd

- SEERFeatureProcessor subclasses TensorProcessor to reuse its float
  dtype, size()/process() contract and learns_statistics handling.
  Its fit now sets _n_dim, so the inherited dim() and spatial()
  report one flat vector instead of raising; a test covers this.
- Say in the task docs that all unseen categories of a field share
  one indicator column.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@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 04898bf

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

Thank you for this contribution. It adds a SEER*Stat Case Listing dataset, a fixed-horizon survival task, a split-aware feature processor, tests, docs and a reproduction example. It is self-contained and well tested. Coverage looks good: the added files are at 92.19% (seer.py), 95.4% (seer_processor.py) and 96.97% (seer_survival.py), and the whole repository is at 87.17%.

To get this merged:

  1. Fix the numeric-encoding documentation so it matches the code. docs/api/tasks/pyhealth.tasks.SEERSurvivalPrediction.rst says the numeric encoding uses "verified exported codes" for primary site. The README also says the numeric baseline "uses verified native codes". In seer_processor.py, _numeric_value only uses the value as a number when it is purely decimal. Formatted primary-site values such as C341, as in your fixture, go down the ordinal-category path instead. Either update the docs and README to say which fields use native numeric codes (histology, extension, nodes, metastases and size) and that primary site is ordinal-coded for formatted exports, or change the code to match. Please also check that the README's description of the real-data numeric results is accurate.

Optional suggestions:

  • A blank line in the export currently aborts the loader with a "Wrong number of fields" error. Skipping blank rows would be friendlier.
  • tests/core/conftest.py writes the internal global_event_df.parquet cache file directly. Going through a public path would be less brittle.
  • Add tests for the one-hot include_extent=False path and for the BOM and cp1252 encoding detection.
  • Consider adding the paper link to the SEERDataset class docstring or to its docs page. It is currently only in the module docstring. The SEER access link is already in the docs.

Reviewed commit 04898bf

@solarsys

Copy link
Copy Markdown
Collaborator

Why this PR has status: manual:

  • It adds tests/core/conftest.py. A conftest there applies to every core test, so it's shared test setup rather than part of this component.
  • Its fixture data sits in tests/fixtures/. Data for tests belongs in test-resources/.
  • The AI review asks for one fix: the numeric-encoding docs don't match what _numeric_value does.

To make it eligible for automatic review:

  • Move the fixtures from conftest.py into the test modules (or a helper module they import), and delete tests/core/conftest.py.
  • Move tests/fixtures/seer/seer_export.txt to test-resources/core/seer/.
  • Fix the encoding docs, as the AI review describes.

#1667 (opened today) adds another SEER dataset and survival task. Yours came first and is closer to ready, so we've suggested that #1667 build on this one.

Once that's pushed, we'll switch the label to status: automatic and request a fresh AI review. If the AI review approves, it merges the PR.

@solarsys

Copy link
Copy Markdown
Collaborator

Picked as PyHealth's SEER dataset and survival task. We compared this with #1667. Yours:

  • reads SEER exports directly;
  • handles censoring and other-cause deaths correctly;
  • supports any horizon;
  • fits the encodings on the training split only;
  • is tested in CI.

It was also opened first.

What's left are the fixes from my earlier comment:

  • Fold the conftest.py fixture into the test modules, and build the cache through a public path rather than writing global_event_df.parquet directly.
  • Move the fixture to test-resources/core/seer/.
  • Make the encoding docs match _numeric_value.
  • Optional: skip blank lines, and test the one-hot include_extent=False path and the BOM/cp1252 detection.

After that, we'll move it to status: automatic.

nrking0 and others added 2 commits November 29, 2026 20:23
- Remove tests/core/conftest.py. Each SEER test module defines its own
  seer_dataset fixture, and the fixture builds the event cache through
  the public global_event_df property instead of writing the parquet
  file by hand.
- Move the synthetic export to test-resources/core/seer/ and update
  the test and docs paths.
- Say in the task docs and README which fields numeric encoding uses
  as numbers: primary site is numeric only when exported as digits
  (as in the real export, e.g. 341); a formatted value such as C341
  gets an ordinal code. No code or results change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolves the import conflict in pyhealth/datasets/__init__.py by keeping
both SEERDataset and the new HIRIDDataset imports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@solarsys solarsys added status: automatic The PR will go through automatic review process. and removed status: manual Pending maintainer's review labels Nov 30, 2026
@solarsys

Copy link
Copy Markdown
Collaborator

Good news: the reasons this PR had status: manual are fixed, so it has moved to status: automatic. We've requested an AI review of the latest commit. If it approves, the PR merges; if it asks for changes, push a fix and comment /review yourself (on automatic PRs you can).

@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 23d7c0f

Use ``encoding="numeric"`` for the standardized numeric baseline. The
processor uses the numeric diagnosis year and size, and uses primary site,
histology, extension, lymph nodes, and metastases as numbers when their
exported values are all digits (for example primary site ``341``). Any other

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] Numeric-encoding wording implies a field-level rule that the code does not apply

The text says the numeric baseline uses primary site, histology, extension, lymph nodes and metastases as numbers "when their exported values are all digits". In pyhealth/processors/seer_processor.py:133 (_numeric_value) the check is made per value, not per field. A field that mixes "341" with "C341" therefore puts digit values on the raw code scale and the other values on ordinal indices in one standardized column. Reword the sentence to say the choice is made per value, or make the choice per field in fit() so the doc is accurate.

The inputs are an explicit list of diagnosis-time fields. It includes
diagnosis year, primary site, sex, age group, histology, grade, laterality,
marital status, AJCC stage group, tumor size, extension, lymph nodes, and
metastases. The site cohort filter, survival outcomes, follow-up fields,

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] Site cohort filter is described but not applied or checked

The text refers to a "site cohort filter" as being outside the feature list. Neither SEERDataset nor SEERSurvivalPrediction filters or validates the Site recode field, so a non-lung export is accepted silently and labelled as the same task. The lung-only cohort exists only in the external SEER*Stat session described in the example README. Say explicitly that the caller must export the lung cohort, or check the site value in the dataset loader.

return float(number)


class SEERFeatureProcessor(TensorProcessor):

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] Subclassing TensorProcessor makes transform_processor bridge it with TensorProcessor's converter

SEERFeatureProcessor inherits from TensorProcessor, so the MRO lookup in pyhealth/processors/unified_bridge.py:1037 gives it TensorToUnifiedBridge. The subclass overrides fit and process entirely and never sets the fields that bridge reads (_shape stays None). A flat vector probably still converts correctly, but I did not verify the bridged output. Either give the processor an explicit bridge, or subclass a base that is not a concrete processor. This does not block the merge.

@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 SEER*Stat Case Listing dataset, a fixed-horizon 12-month survival task, and a train-fitted one-hot and numeric feature processor. It also adds a benchmark and ablation example with aggregate results, API docs, and tests. It looks ready to merge.

  • Code and docs: The dataset, task and processor are self-contained. They only register new exports in the package init files and reuse the generic TensorProcessor base. The dataset cites the Hegselmann et al. paper in its module docstring and in the docs. The docs match the code.
  • Tests: Coverage meets the bar. The new files are at 92.2% (seer.py), 95.4% (seer_processor.py) and 97.0% (seer_survival.py). The repository total is 88.35%, above the 60% guideline.
  • Redundancy: PyHealth has no existing SEER dataset or task, so nothing is duplicated.

Optional suggestions:

  • Description paths: The description mentions tests/core/conftest.py and tests/fixtures/seer/. The diff has neither. The fixture is at test-resources/core/seer/, so please update the description.
  • Site cohort filter: The task docs refer to a "site cohort filter". Neither the dataset nor the task applies one, so a non-lung export would load without complaint. Either state that the cohort is chosen in SEER*Stat, or add a filter.
  • Numeric encoding wording: The docs describe the numeric-encoding rule as if it applied per field. The code decides per value: a digits-only value is used as a number, and anything else gets an ordinal code. Rewording the docs would make this clearer.
  • Session file: I couldn't inspect the binary Lung_2004_2009_current.ss file. Please check that it holds no local paths or user details.

Reviewed commit 23d7c0f

@solarsys
solarsys merged commit c04c62a into sunlabuiuc:master Nov 30, 2026
2 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