Repository navigation
Closes #913: Add split_by_predefined and document how to port official dataset splits - #1293
Open
Aprameyaraya wants to merge 5 commits into
Open
Aprameyaraya wants to merge 5 commits into
Aprameyaraya wants to merge 5 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #913
Problem
Datasets with pre-defined splits (e.g. TUEV/TUAB) each needed their own
function in
splitter.py. The four*_tuhfunctions repeat the same logic,and every new dataset would add more copies.
Changes
pyhealth/datasets/splitter.pysplit_by_predefined, a generic splitter for datasets whose samplescarry an official partition label (
split_key, default"split").Samples with
train_valueform the pool that is cut byratios(2 valuesfor train/val, 3 for train/val/cal). All other samples are the test set.
by_patient=Truekeeps each patient's samples in one split. Patient IDsare sorted before shuffling, so the result does not depend on sample order.
split_by_patient_tuh,split_by_sample_tuh,split_by_patient_conformal_tuhandsplit_by_sample_conformal_tuhtothin wrappers. Names, signatures and docstrings are unchanged.
three times.
pyhealth/datasets/__init__.py: exportsplit_by_predefined.CONTRIBUTING.md: add "Porting a Dataset's Official Splits", the standardasked 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, callsplit_by_predefinedinstead of adding a splitter, and put anyfixed-argument wrapper next to the dataset module.
Backward compatibility
The
*_tuhfunctions keep their public API. For the same seed they shouldreturn the same indices as before. <Say here how you checked, e.g. compared
old vs new
get_index=Trueoutput on a fake dataset.>Testing
pytest tests/core/test_splitter_predefined.py>python tools/check_pr_rules.py --base <base_sha> --head HEADNotes
These functions split an already-processed
SampleDataset, so its processorswere fitted on all samples. This PR does not change that. For preprocessing fitted
on the training part only, use
set_task(..., split=PatientSplit(...)).