mtslearn: Machine Learning in Python for Medical Time Series
Authors: Zhongheng Jiang, Yuechao Zhao, Donglin Xie, Chenxi Sun, Rongchen Lu, Silu Luo, Zisheng Liang, Shenda Hong
Organizations: Nanjing University of Information Science and Technology, Nanjing, China · National Institute of Health Data Science, Peking University, Beijing, China · School of Health Humanities, Peking University Health Science Center, Beijing, China · Institute of Medical Technology, Peking University Health Science Center, Beijing, China · Harvard Medical School, Boston, US · Beth Israel Deaconess Medical Center, Boston, US · School of Business English, Sichuan International Studies University, Chongqing, China · School of Clinical Medicine, Chengdu Medical College, Chengdu, Sichuan, China · Institute for Artificial Intelligence, Peking University, Beijing, China · State Key Laboratory of Vascular Homeostasis and Remodeling, NHC Key Laboratory of Cardiovascular Molecular Biology and Regulatory Peptides, Peking University, Beijing, China
Medical time-series data captures the dynamic progression of patient conditions, playing a vital role in modern clinical decision support systems. However, real-world clinical data is highly heterogeneous and inconsistently formatted. Furthermore, existing machine learning tools often have steep learning curves and fragmented workflows. Consequently, a significant gap remains between cutting-edge AI technologies and clinical application. To address this, we introduce mtslearn, an end-to-end integrated toolkit specifically designed for medical time-series data. First, the framework provides a unified data interface that automates the parsing and alignment of wide, long, and flat data formats. This design significantly reduces data cleaning overhead. Building on this, mtslearn provides a complete pipeline from data reading and feature engineering to model training and result visualization. Furthermore, it offers flexible interfaces for custom algorithms. Through a modular design, mtslearn simplifies complex data engineering tasks into a few lines of code. This significantly lowers the barrier to entry for clinicians with limited programming experience, empowering them to focus more on exploring medical hypotheses and accelerating the translation of advanced algorithms into real-world clinical practice. mtslearn is publicly available at https://github.com/PKUDigitalHealth/mtslearn.
Figures & tables
Figure 1: Evolutionary paradigm of clinical prediction modeling. Rather than introducing complex deep learning algorithms for time-series data, this study builds upon traditional statistical methods and classic deep learning algorithms. We integrated established AI medical tools into a unified framework to simplify workflows for clinicians.
Figure 2: Structural representations of heterogeneous clinical data. The schematic illustrates the three most common tabular formats encountered in clinical records: Wide format, Long format, and Flattened format. mtslearn standardizes these diverse inputs into a unified representation to significantly reduce manual preprocessing overhead.
Name
Preprocessing
Predict
End-to-End
Data cleaning
Time-series resampling
Feature Stats
Static model
Time-series model
Pipelining
TemporAI 19
✓
×
×
✓
✓
✓
Clairvoyance 8
✓
✓
×
✓
✓
✓
NeuroKit2 14
✓
✓
✓
×
×
×
Talent 12
✓
×
×
✓
×
✓
scikit-learn 17
✓
×
×
✓
×
✓
Table 1: Functional comparison of existing machine learning toolkits versus mtslearn. The table highlights capabilities across data preprocessing and model prediction, which shows that most existing toolkits focus on specific stages. ("End-to-End Pipeline" denotes a unified workflow integrating the entire lifecycle, from raw data processing to model evaluation.)
Medical time series are central to healthcare, enabling continuous monitoring and supporting timely clinical decisions. Despite recent progress, existing methods struggle to jointly model local-global dynamics and handle nonstationarities like baseline drift, while often failing to capture latent channel interactions. To address these challenges, we propose MedMamba, an end-to-end architecture that integrates state space models with domain-specific inductive biases. Specifically, MedMamba first employs multi-scale convolutional embeddings to capture discriminative local morphology. Second, to mitigate nonstationarity, we introduce a tri-branch differential state space encoder that processes raw, temporal-difference, and frequency-domain views, fusing them to emphasize informative patterns while suppressing drift. Furthermore, to uncover latent channel correlations, we design a spatial graph Mamba module that learns a directed dependency structure regularized toward sparsity and acyclicity, which obviates the need for predefined graphs. Extensive experiments on five real-world datasets demonstrate that MedMamba achieves state-of-the-art performance while maintaining linear computational complexity, and ablation studies validate each component's contribution.Code is available at https://github.com/zhangda1018/MedMamba.
Da Zhang, Bingyu Li, Zhiyuan Zhao +3
Northwest Polytechnical University · TeleAI, China Telecom · TeleAI +1
Medical time series (MedTS) signals such as electroencephalography (EEG) and electrocardiography (ECG) support many clinical applications. However, substantial subject-level heterogeneity often induces subject-level distribution shift, causing a fixed parameter set to generalize poorly to unseen individuals. Compared with domain adaptation methods that often depend on extra adaptation components or target-batch statistics, Test-Time Training (TTT) provides a more practical solution for sequential clinical data by enabling online adaptation from unlabeled test samples. However, many representative TTT methods require iterative inner-loop optimization, increasing test-time overhead. In this paper, we propose MedTS-TTT, a test-time training framework for medical time series modeling. MedTS-TTT is built upon Closed-Loop Self-Alignment Test-Time Training (CLSA-TTT) and a Gated Convolutional Backbone (GCB). CLSA-TTT constructs a token-level self-supervised target and performs a single-step fast-weight update for intra-layer closed-loop alignment, enabling rapid sample-wise adaptation without iterative inner-loop optimization. GCB combines CLSA-TTT-based fast adaptation and token-level fusion with a gated convolutional branch to balance local dynamic modeling and information-flow control. On 4 public datasets (2 EEG and 2 ECG) with subject-independent splits, MedTS-TTT achieves 11 top-1 rankings out of 12 evaluations across 9 baselines and 3 metrics. The code is publicly available at https://github.com/mingzhi-c/MedTS-TTT.
Mingzhi Chen, Yiyu Gui, Guibo Luo
Guangdong Provincial Key Laboratory of Ultra High Definition Immersive Media Technology, Shenzhen Graduate School, Peking University, Shenzhen, China
Clinical machine learning (ML) has the potential to support high-stakes medical decision-making, but reliable deployment is often constrained by scarce, heterogeneous, and temporal complexity. Developing effective ML pipelines for such data remains time-consuming and error-prone, while existing automated machine learning (AutoML) systems only partially address this challenge because they largely rely on brute-force search over predefined spaces and lack explicit reasoning and memory. We therefore reformulate AutoML for small clinical data from exhaustive search to reasoning-driven refinement. We propose DoctorAgents, an agentic AI framework that autonomously constructs and optimizes end-to-end ML pipelines through specialized large language model (LLM) agents for generation, validation, and refinement. DoctorAgents backpropagates natural-language feedback through textual gradient descent to perform targeted updates without exhaustive search. Experiments across diverse clinical tasks show that DoctorAgents consistently outperforms established AutoML baselines while producing more interpretable task-specific representations.
Ruilin Wang, Bo-Hong Wang, Elizabeth Kourbatski +6
School of Computer Science, McGill University, Montreal, Canada · Mila – Quebec AI Institute, Montreal, Canada · Centre intégré universitaire de santé et de services sociaux de l’Estrie – Centre hospitalier universitaire de Sherbrooke (CIUSSSE-CHUS), Sherbrooke, Canada +2