Repository navigation
SEER dataset and fixed-horizon survival task with temporal split and all-cause label (Hegselmann et al., MLHC 2018) - #1735
Conversation
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.
Test CoverageTotal: 88.23% (57646 / 65334 lines)
|
|
Why this PR has 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. |
|
#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 |
|
/review Generated by Claude Code |
| if continuous_columns is not None | ||
| else SEER_CONTINUOUS_FEATURES | ||
| ) | ||
| if feature_columns is not None and continuous_columns is not None: |
There was a problem hiding this comment.
[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: |
There was a problem hiding this comment.
[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.
| 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 |
There was a problem hiding this comment.
[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.
There was a problem hiding this comment.
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
Raisestext 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=Nonedelimiter sniffing can misparse unusual exports; an optionalsepargument 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
|
Duplicate: the SEER dataset is already in PyHealth ( 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. |
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:
SEERDatasetloads 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, andtemporal_splitsplits patients by year of diagnosis.SEERSurvivalPredictionlabels 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.pyreplicates the paper's encoding comparison with PyHealth'sLogisticRegressionandMLP, 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.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 splitpyhealth/datasets/configs/seer.yaml- configpyhealth/tasks/seer_survival_prediction.py- tasktests/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 exportexamples/seer_survival_prediction_mlp.py- replication, ablations, resultsdocs/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