Skip to content

Closes #913: Add split_by_predefined and document how to port official dataset splits - #1293

Open
Aprameyaraya wants to merge 5 commits into
sunlabuiuc:masterfrom
Aprameyaraya:master
Open

Aprameyaraya wants to merge 5 commits into
sunlabuiuc:masterfrom
Aprameyaraya:master

Conversation

@Aprameyaraya

Copy link
Copy Markdown

Closes #913

Problem

Datasets with pre-defined splits (e.g. TUEV/TUAB) each needed their own
function in splitter.py. The four *_tuh functions repeat the same logic,
and every new dataset would add more copies.

Changes

  • pyhealth/datasets/splitter.py
    • Add split_by_predefined, a generic splitter for datasets whose samples
      carry an official partition label (split_key, default "split").
      Samples with train_value form the pool that is cut by ratios (2 values
      for train/val, 3 for train/val/cal). All other samples are the test set.
    • by_patient=True keeps each patient's samples in one split. Patient IDs
      are sorted before shuffling, so the result does not depend on sample order.
    • Reduce split_by_patient_tuh, split_by_sample_tuh,
      split_by_patient_conformal_tuh and split_by_sample_conformal_tuh to
      thin wrappers. Names, signatures and docstrings are unchanged.
    • The sample-level versions now read each sample once instead of two or
      three times.
  • pyhealth/datasets/__init__.py: export split_by_predefined.
  • CONTRIBUTING.md: add "Porting a Dataset's Official Splits", the standard
    asked for in Create file structure standard/documentation for how people should port over their task data splits. #913: tag samples with "split" in the task, call
    split_by_predefined instead of adding a splitter, and put any
    fixed-argument wrapper next to the dataset module.
  • <docs file(s) updated>
  • <example file(s) updated>

Backward compatibility

The *_tuh functions keep their public API. For the same seed they should
return the same indices as before. <Say here how you checked, e.g. compared
old vs new get_index=True output on a fake dataset.>

Testing

  • <command you ran, e.g. pytest tests/core/test_splitter_predefined.py>
  • python tools/check_pr_rules.py --base <base_sha> --head HEAD

Notes

These functions split an already-processed SampleDataset, so its processors
were fitted on all samples. This PR does not change that. For preprocessing fitted
on the training part only, use set_task(..., split=PatientSplit(...)).

Added a new function to split datasets based on predefined train/test partitions, allowing for patient-based or sample-based splits with specified ratios.
Added 'split' field to the sample return structure.
Added guidelines for porting official dataset splits to CONTRIBUTING.md.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create file structure standard/documentation for how people should port over their task data splits.

1 participant