Source-linked AI summary
Medformer: A Multi-Granularity Patching Transformer for Medical Time-Series Classification
Yihe Wang, Nan Huang, Taida Li, Yujun Yan, Xiang Zhang
TL;DR
Medical time-series classification is important for healthcare, but transformer-based methods for it remain underexplored, and MedTS has temporal, cross-channel, and multi-scale features to capture. Medformer combines cross-channel patching, multi-granularity embeddings, and two-stage attention. Across five datasets and six metrics, it achieves the highest average ranking among ten baselines.
Problem
Medical time-series classification remains underexplored by transformer-based methods, despite the importance of capturing local temporal dynamics, inter-channel correlations, and multi-scale features.
Source: §1 · pp. 1–2Method
Medformer uses cross-channel multi-granularity patching and two-stage self-attention to learn features within and across granularities.
Source: §4 · pp. 6–7Results
Medformer achieves the highest average ranking across five datasets and six evaluation metrics among ten baselines.
Source: §1 · p. 2Takeaways & Limitations
Experiments across five datasets under the subject-independent setup demonstrate the method’s effectiveness and robustness, with potential for real-world applications.
Source: §6 · p. 10Not all patch-length configurations are optimal; some may perform worse than uniform lengths, so patch lengths require careful tuning.
Source: §6 · p. 10
Abstract
from arXiv · showhide
Medical time series (MedTS) data, such as Electroencephalography (EEG) and Electrocardiography (ECG), play a crucial role in healthcare, such as diagnosing brain and heart diseases. Existing methods for MedTS classification primarily rely on handcrafted biomarkers extraction and CNN-based models, with limited exploration of transformer-based models. In this paper, we introduce Medformer, a multi-granularity patching transformer tailored specifically for MedTS classification. Our method incorporates three novel mechanisms to leverage the unique characteristics of MedTS: cross-channel patching to leverage inter-channel correlations, multi-granularity embedding for capturing features at different scales, and two-stage (intra- and inter-granularity) multi-granularity self-attention for learning features and correlations within and among granularities. We conduct extensive experiments on five public datasets under both subject-dependent and challenging subject-independent setups. Results demonstrate Medformer's superiority over 10 baselines, achieving top averaged ranking across five datasets on all six evaluation metrics. These findings underscore the significant impact of our method on healthcare applications, such as diagnosing Myocardial Infarction, Alzheimer's, and Parkinson's disease. We release the source code at https://github.com/DL4mHealth/Medformer.
1 Introduction
Medical time-series classification matters for monitoring and diagnosis, but transformer-based approaches remain underexplored and existing tokenizations do not fully capture MedTS features. Medformer combines cross-channel, multi-timestamp, and multi-granularity design, and achieves the highest average ranking across five datasets and six metrics.
1 Introduction
- Existing MedTS classification relies largely on handcrafted biomarkers, CNNs, GNNs, or hybrid models, while transformer-based methods remain underexplored.The passage describes EEG and ECG as examples of medical signals used in neurological and heart assessment.Source: §1 · p. 1
- Prior tokenizations use single timestamps, whole channels, or single-channel patches, which can miss coarse or fine temporal features or cross-channel relationships.The cited comparison distinguishes vanilla Transformer, Autoformer, and Informer [30] [28] [29], iTransformer [31], and PatchTST and Crossformer [32, 33].Source: §1 · p. 2, Figure 1 · p. 2
- MedTS classification needs to capture local temporal dynamics, inter-channel correlations, and patterns at multiple temporal scales.Some disease indicators may appear only within specific frequency bands.Source: §1 · p. 2
- Medformer achieves the highest average ranking across five public datasets and six evaluation metrics against ten baselines.The experiments cover both subject-dependent and subject-independent setups.Source: §1 · p. 2
2 Related Work
Related work spans biomarker and deep-learning approaches to medical time-series classification, alongside transformer designs developed largely for general time-series tasks. Medformer combines cross-channel, multi-granularity token embedding with two-stage attention, and its components can be integrated into existing methods.
2 Related Work
- Medical time-series classification includes biomarker methods and deep-learning models, with EEG, ECG, EMG, and EOG serving distinct medical applications.Examples include EEG-based Alzheimer’s diagnosis using band features and models such as EEGNet, EEG-Conformer, and TCN [51] [13].Source: §2 · pp. 2–3
- Prior time-series transformers modify token embeddings, self-attention, or both; patching approaches commonly use sequences of single-channel timestamps [32].Multi-granularity methods such as Pyraformer, MTST, Pathformer [55], and Scaleformer [60] capture features at different scales.Source: §2 · p. 3
- Table 1 frames existing methods as not fully using the potential characteristics of medical time series.The related-work discussion identifies cross-channel relationships and multi-scale features among those characteristics.Source: Table 1 · p. 3
- Medformer combines novel token embedding with self-attention mechanisms, and its components can be incorporated into existing methods.The paper gives cross-channel multi-granularity patching with Autoformer [28] and Informer [29], and two-stage attention with MTST and Pathformer [55], as examples.Source: §2 · p. 3
3 Preliminaries and Problem Formulation
Medical time-series diagnosis assigns disease labels to samples associated with subjects, so evaluation splits affect whether results reflect performance on unseen people. The section distinguishes subject-dependent and subject-independent setups and formulates classification as encoding a multichannel sample into a representation for label prediction.
3 Preliminaries and Problem Formulation
- Disease-diagnosis samples carry a disease label and subject ID; a subject may need multiple labels when conditions co-occur.The text describes a subject’s medical or physiological state as relatively stable over time or short periods without significant change.Source: §3 · pp. 3–4
- Subject-dependent splitting assigns samples randomly, so samples from one subject may appear in training, validation, and test sets, potentially causing information leakage.The passage says this setup has limited application to real-world diagnosis and often produces higher results than subject-independent evaluation.Source: §3 · p. 4
- Subject-independent splitting keeps each subject and their samples exclusively in one split, enabling evaluation on unseen subjects and more closely simulating diagnosis settings.The passage notes that subject-independent classification is challenging because individual data distributions and noise can obscure features shared across subjects [62] [13] [63] [64].Source: §3 · p. 4
- MedTS classification encodes an input sample xin ∈ R^(T × C) into representation h to predict label y ∈ R^K, where T is timestamps, C channels, and K medically relevant classes.Classes can represent disease types or stages of a disease.Source: §3 · p. 4
- Medformer’s overview applies distinct patch lengths in parallel and combines augmented patch embeddings with positional and granularity embeddings.The fragmented overview also describes granularity-specific routers and intra- and inter-granularity self-attention.Source: Figure 3 · p. 5, §3 · p. 5
4 Method
Medformer uses cross-channel patches at multiple temporal scales to represent medical time series. Its router-based two-stage attention learns features within each scale and relationships across scales before producing a classification representation.
- Cross-channel patches at multiple patch lengths represent spatial-temporal features at different scales while retaining information across channels.The patch lengths define granularities, and zero padding makes the timestamp count divisible by each length.Source: §4 · pp. 5–6
- Masking and jittering augment patch embeddings; the authors assume this encourages granularities to learn complementary information during inter-granularity attention.Source: §4 · p. 6
- Each scale’s patch embeddings receive positional and learnable granularity embeddings, with the latter distinguishing granularities.The positional embedding uses the first Ni rows for a granularity with Ni patches.Source: §4 · p. 6
- Router-based intra- and inter-granularity self-attention captures features within each scale and correlations across scales.The router mechanism is proposed to reduce the time complexity of self-attention.Source: §4 · pp. 6–7
- After M attention layers, updated patch embeddings are concatenated into a representation used to predict the downstream class label.The method can also be adapted to single-granularity or repeated same-granularity variants.Source: §4 · p. 7
5 Experiments
Experiments compare Medformer with ten baselines across five EEG and ECG datasets under sample- and subject-based splits. In the subject-independent setup, Medformer achieves the best average rank across six metrics.
5 Experiments
- The benchmark covers five public datasets—three EEG and two ECG—and compares Medformer with ten transformer baselines under sample- and subject-based splits.The subject-dependent split is based on samples; the subject-independent split is based on subjects.Source: §5 · pp. 7–8
5.1 Results of Subject-Dependent
- 97.50% F1: Medformer achieves top-1 results on all six evaluations for ADFTD in the subject-dependent setup.The setup splits training, validation, and test sets by samples.Source: §5.1 · p. 8, Table 3 · p. 8
5.2 Results of Subject-Independent
- Medformer achieves the best average rank across six metrics, with 15 top-1 and 30 top-3 rankings across five subject-independent datasets.Lower average rank indicates better results.Source: Table 4 · p. 9, Figure 4 · p. 10, §5.2 · p. 10
5.3 Ablation Study and Additional Experiments
- The study includes module and patch-length ablations, plus additional experiments on two human-activity-recognition datasets.The additional datasets are used to assess learning on general time series with potential channel correlations.Source: §5.3 · p. 10
6 Conclusion and Limitations
Medformer combines cross-channel patching, multi-granularity embedding, and two-stage self-attention for medical time-series classification. Its patch-length flexibility requires tuning, and it lacks mechanisms specifically designed for subject-independent evaluation.
6 Conclusion and Limitations
- Medformer combines cross-channel patching, multi-granularity embedding, and two-stage self-attention to capture features within and across granularities.The mechanisms target channel correlations and features at multiple scales.Source: §6 · p. 10
- Across five datasets and ten baselines in the subject-independent setup, results support the method’s effectiveness and robustness.The authors describe its real-world application potential.Source: §6 · p. 10
- Some variable patch-length combinations perform worse than uniform lengths, so patch lengths require careful hyperparameter tuning.The authors identify automatic patch-length selection as future work.Source: §6 · p. 10
- Medformer has no mechanisms specifically designed for subject-independent evaluation; separating subject-specific from task-related features is proposed as future work.Source: §6 · p. 10
Appendix A Data Augmentation Banks
During training, each patch embedding randomly receives one augmentation from a bank of six techniques, chosen with equal probability.
Appendix A Data Augmentation Banks
- Each patch embedding selects one of six augmentation techniques with equal probability during training to support robustness and generalization.The bank can be expanded with additional choices.Source: Appendix A · p. 16
- Temporal flipping reverses time, channel shuffling reorders channels, and temporal masking hides timestamps across all channels.Default probabilities are 0.5 for flipping and shuffling; the default masked timestamp proportion is 0.1.Source: Appendix A · p. 16
- Frequency masking removes frequency bands, jittering adds random noise, and dropout randomly removes values.The default masked frequency-band proportion, jitter scale, and dropped-value proportion are each 0.1.Source: Appendix A · p. 16
Appendix B Data Preprocessing
The appendix describes preprocessing for three EEG and two ECG datasets, including signal preparation, segmentation, and dataset-specific subject split strategies.
B.1 APAVA Preprocessing
- APAVA trials are scaled, split into nine half-overlapping 1-second samples, and assigned to subject-independent training, validation, and test sets.The resulting 5,967 samples come from 23 subjects; validation and test subjects are specified separately.Source: §B.1 · p. 16
B.2 TDBrain Preprocessing
- TDBrain uses 1-second, non-overlapping samples from eye-closed trials for 25 Parkinson’s disease subjects and 25 healthy controls, with subject-independent splits.Samples shorter than one second are discarded, leaving 6,240 samples.Source: §B.2 · p. 16
B.3 ADFTD Preprocessing
- ADFTD trials are bandpass-filtered, downsampled to 256 Hz, and segmented into non-overlapping 1-second samples for both subject-dependent and subject-independent evaluation.The processing yields 69,752 samples across Alzheimer’s disease, frontotemporal dementia, and healthy-control subjects.Source: §B.3 · p. 17
B.4 PTB Preprocessing
- PTB ECG signals are downsampled to 250 Hz, normalized, and segmented into zero-padded heartbeats before subject-independent splitting.The selected subset contains 198 subjects and yields 64,356 samples.Source: §B.4 · p. 17
B.5 PTB-XL Preprocessing
- PTB-XL trials are downsampled from the 500 Hz version to 250 Hz, normalized, and divided into non-overlapping 1-second samples for subject-independent splits.Subjects with inconsistent diagnoses across trials are excluded, leaving 17,596 subjects and 191,400 samples.Source: §B.5 · p. 17
Appendix C Implementation Details
The appendix details a shared implementation and training protocol for Medformer and its transformer baselines, while the module study reports gains associated with each proposed component.
Appendix C Implementation Details
- All methods use a shared Time-Series-Library framework and training techniques, with ten transformer baselines included for comparison.The baselines are Autoformer, Crossformer, FEDformer, Informer, iTransformer, MTST, Nonformer, PatchTST, Reformer, and vanilla Transformer.Source: Appendix C · p. 17
- Models use six encoder layers, attention dimension 128, feed-forward dimension 256, Adam at 1e-4, and up to 100 epochs with validation-F1 early stopping.Each experiment runs with five random seeds and fixed train, validation, and test sets; six metrics are reported.Source: Appendix C · p. 18
- Medformer maps patches from dataset-specific patch-length lists into 1-D representations with a conv2d network and uses dataset-specific augmentations.Patch lengths include both repeated and varied granularities; augmentation choices include none, jitter, scale, and masking.Source: Appendix C · p. 18
D.1 Module Study
- 28 top-1 and 30 top-2 rankings across 30 evaluations went to full Medformer, with average F1 gains of 3.64% from inter-granularity attention, 4.46% from embedding augmentation, and 6.10% from multi-channel patching.Multi-channel patching was particularly beneficial on EEG data.Source: §D.1 · p. 19, Table 5 · p. 19
D.2 Patch Length Study
The patch-length study finds that one manually selected multi-granularity configuration performs best across the evaluated metrics, while repeated patch lengths generally help with an exception.
D.2 Patch Length Study
- Using five identical patch lengths generally improves performance over one length, except when L = 2.The authors suggest additional identical lengths may capture more information, analogously to multi-head attention.Source: §D.2 · pp. 19–20
- The {2, 2, 4, 16, 32} patch-length combination achieves the highest performance across all evaluated metrics, although mixed lengths do not guarantee improvement.The study evaluates different patch-length combinations on APAVA.Source: §D.2 · pp. 19–20, Table 6 · p. 20
Appendix E Additional Experiments
Additional experiments compare Medformer with six baselines on one existing dataset and two human activity recognition datasets, where it ranks first on two datasets and second on the third.
Appendix E Additional Experiments
- The comparison evaluates six methods on TDBrain, FLAAP, and UCI-HAR, with 6,240, 13,123, and 10,299 samples, respectively.The datasets have 2, 10, and 6 classes, respectively.Source: Table 7 · p. 20
- Medformer achieves the highest top-1 accuracy and F1 score on TDBrain and FLAAP, and ranks second-best on UCI-HAR.The comparison includes TCN, ModernTCN, Mamba, Crossformer, Reformer, and Transformer.Source: Appendix E · p. 20, Table 7 · p. 20
Appendix F Complexity Analysis
The supplied sections report vanilla-transformer-level complexity for Medformer’s two-stage attention, compare its multi-granularity design with related methods, and describe potential medical applications.
Appendix F Complexity Analysis
- O(T^2) is the total time complexity of the two-stage multi-granularity self-attention module, matching vanilla-transformer complexity without significant overhead.Intra-granularity attention operates over patch embeddings within a granularity and among routers.Source: Appendix F · pp. 20–21
G.1 Comparision with Other Multi-Granularity Methods
- Medformer uses multi-channel patching and inter-granularity attention, unlike MTST’s single-channel patching and Pathformer’s lack of inter-granularity attention; Scaleformer’s aims are largely orthogonal.Scaleformer’s downsampling and upsampling design is not straightforward to incorporate into patching methods and may yield sub-optimal patch representations.Source: §G.1 · p. 21
Appendix H Broader Impacts
- Medformer performs comparably to or surpasses state-of-the-art baselines; subject-dependent and subject-independent evaluations simulate real-world applications, including potential EEG-based neurological-disorder detection.The broader-impact discussion also anticipates further research into multi-scale information in medical time series.Source: Appendix H · p. 21