Repository navigation
MIT-BIH Arrhythmia dataset and ECG anomaly detection task (MedTsLLM, part 1 of #1594) - #1671
Conversation
MITBIHDataset reads the 48 WFDB records; MITBIHAnomalyDetection makes the MedTsLLM windows with per-step abnormal-beat labels; and MITBIHAnomalyRatioSplit is the paper's record-level split. Split out of sunlabuiuc#1594 as the maintainers asked. Co-authored-by: Thi Van Trinh Tran <ttran493@gatech.edu> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Test CoverageTotal: 87.58% (53157 / 60697 lines)
|
|
/review |
There was a problem hiding this comment.
Previous review
AI Review
suggestion: need change
decision: need change
Thank you for this contribution. It adds the MIT-BIH Arrhythmia dataset, the paper's record-level anomaly-ratio split, and a windowed ECG anomaly-detection task. The code is well tested and documented. Coverage is above the bar: the new files are at 97.35% and 98.41%, and the whole repository is at 87.58%.
To get this merged:
- Describe the dataset–task links, or remove them. Two places connect the dataset and the task.
pyhealth/tasks/mitbih.pyimportsMITBIH_BEAT_SYMBOLS,MITBIH_EVENT_TYPE,MITBIH_NORMAL_SYMBOLand the private_require_wfdbfrompyhealth/datasets/mitbih.py.MITBIHDataset.default_taskimportsMITBIHAnomalyDetectionfrom the task module.
Please either confirm in the description that this sharing is intended and say why, for example so the annotation symbols and the wfdb error handling stay in sync. Or make the task self-contained by copying the few constants and the helper into it. Either option is fine.
Optional suggestions:
- The class docstring says that changing the records in
rootnever reuses a stale event cache, because of the metadata hash indataset_name. A small test would back this up. It could build the dataset, change a record, rebuild, and check thatdataset_namediffers. docs/api/datasets.rsthas a summary table (around line 438) that doesn't list MIT-BIH. You could add it there too.- With
label_level="window",BinaryLabelProcessormay raise if a split part contains only one label value. A short note in the docs would help users. - The
wfdberror message says it is "also provided bypip install pyhealth[ptbxl]". You may want to check that this extra exists and includeswfdb.
Reviewed commit 6708fc5
…he datasets table Addresses the AI review: a test rewrites one record's annotations and checks that the dataset name, the metadata and the loaded event change, and MIT-BIH is added to the dataset summary table in docs/api/datasets.rst. Co-authored-by: Thi Van Trinh Tran <ttran493@gatech.edu> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
/review |
| f"{self.n_train} + n_test={self.n_test}." | ||
| ) | ||
| return ordered[: self.n_train], ordered[len(ordered) - self.n_test :] | ||
| n_train = max(1, round(len(ordered) * self.train_frac)) |
There was a problem hiding this comment.
[low] Fraction-mode split can silently return an empty train or test part
In "fraction" mode, select_records() does not check train_frac or the number of eligible records. With train_frac=1.0 the test part is empty, and with no eligible records the train part is empty, yet no error is raised. The docstring only promises ValueError for an unknown mode or for too few paper-mode records. Suggested fix: raise ValueError when train_frac is outside (0, 1) or when either part would be empty, or document that the parts may be empty.
| self.root = data_root | ||
|
|
||
| @property | ||
| def default_task(self) -> MITBIHAnomalyDetection: |
There was a problem hiding this comment.
[low] default_task is not exercised by any test
MITBIHDataset.default_task is new public behavior and no test in tests/core/test_mitbih.py reads it. Tests call set_task with an explicit task, so a regression in the default would go unnoticed. Suggested fix: add one assertion that dataset.default_task is a MITBIHAnomalyDetection with target_fs 125.0 and window_len 128.
There was a problem hiding this comment.
AI Review
suggestion: approve
decision: approve
Thank you for this contribution. It adds an MIT-BIH Arrhythmia dataset, a record-level anomaly-ratio split that reproduces the MedTsLLM selection, and a windowed ECG anomaly detection task. The diff looks correct and complete, and it is ready to merge.
- Self-contained: The new components subclass BaseDataset, Split and BaseTask without modifying them. The only edits to existing files are the exports and the docs index entries.
- Sharing: The task reuses the dataset's beat-symbol table, event type and
_require_wfdb, anddefault_taskreturns the task. Your description names both links and gives a reason, which is what the review needs. - Source citation: The dataset cites PhysioNet and the paper in its docstring and its docs page.
- Docs: The docs match the code.
- Tests: The 24 synthetic tests cover the main paths. Coverage is 97.35% for
mitbih.pyand 98.41% for the task file. The repository total is 87.58%, so all of these are above the bar.
Optional suggestions:
- In
fractionmode,train_frac=1.0or having no eligible records quietly returns an empty part. A clear error or a warning would help users. - Add a small test for
MITBIHDataset.default_task.
Reviewed commit e5580c4
|
/merge |
Contributors:
Georgia Tech CSE 6250 (Big Data for Health), Fall 2026
Part 1 of 3 split out of #1594, as the maintainers asked there. This part adds the MIT-BIH dataset and task. Part 2, #1672 (
MedTsLLMAnomaly, the anomaly metrics and the MIT-BIH example), builds on it. Part 3 will add the LUDBMedTsLLM, adapted to the LUDB dataset and task from #1593, after that PR merges. Parts 1 and 2 include no LUDB code, so they don't overlap with #1593.Contribution Type: Dataset + Task
Paper: Chan et al., "MedTsLLM: Leveraging LLMs for Multimodal Medical Time Series Analysis," MLHC 2024. https://arxiv.org/abs/2408.07773
Description:
The paper's ECG anomaly detection task on the MIT-BIH Arrhythmia Database: find abnormal beats in two-lead ECG.
MITBIHDatasetreads the 48 WFDB records (two leads, 360 Hz, beat annotations, header metadata).MITBIHAnomalyDetectionmakes the paper's samples: signals resampled to 125 Hz, 128-step two-lead windows, and a per-step label marking abnormal beats, each expanded by ±150 ms (configurable).MITBIHAnomalyRatioSplitis the paper's record-level split. The paper doesn't list its records. Its sample counts (Tables 1 and 11) match exactly 33 MLII+V1 records and a 6 train / 4 test split by abnormal-beat ratio, which"paper"mode reproduces.On the real data, the task's signals and labels match the data of our run of the authors' code (within 3e-6, no label mismatches). The only change to existing files is the
__init__.pyexports and docs index entries.Design note: the task reuses the dataset's beat-symbol table, event type and
wfdbimport helper (MITBIH_BEAT_SYMBOLS,MITBIH_NORMAL_SYMBOL,MITBIH_EVENT_TYPE,_require_wfdb), so the two can't drift apart, andMITBIHDataset.default_taskreturnsMITBIHAnomalyDetection, following PyHealth's default-task pattern.Files to Review:
pyhealth/datasets/mitbih.py,pyhealth/datasets/configs/mitbih.yaml- dataset and record splitpyhealth/tasks/mitbih.py- anomaly detection tasktests/core/test_mitbih.py- test casesdocs/api/datasets/pyhealth.datasets.MITBIHDataset.rst,docs/api/tasks/pyhealth.tasks.mitbih.rst, entries indocs/api/{datasets,tasks}.rst, exports inpyhealth/{datasets,tasks}/__init__.pyChecklist:
master, based on the latest upstreammastertools/check_pr_rules.pypasses; code follows PEP 8 with 88-character lines