Manuscript Offprint

arXiv:2610.35484

Evaluating Bayesian deep learning for robust biomedical time-series classification under distribution shift: A sleep scoring case study

Mads Birch Sørensen, Ulrike Richter, Francois Gastambide, Michael Riis Andersen

Abstract

In biomedical time-series classification, machine learning models often suffer from deteriorating accuracy and calibration due to distribution shift. We investigate to what degree Bayesian-inspired deep learning improves robustness through Bayesian model averaging (BMA). Using rodent sleep scoring as a case study, we evaluate BMA under distribution shifts in genotype, laboratory, and species. We systematically compare nine approximate inference methods spanning single- and multi-basin approaches across two neural network backbones on in-distribution (ID) data and five out-of-distribution (OOD) datasets. In our results, multi-basin methods perform best, outperforming baselines and single-basin methods. Compared with point estimates, BMA generally improves OOD accuracy and calibration across both architectures, while yielding only modest ID gains. It also often improves selective prediction and OOD and artifact detection, but, interestingly, not inter-rater disagreement detection.

1 INTRODUCTION

Machine learning has demonstrated high predictive accuracy across a wide range of biomedical time-series classification tasks, including cardiac rhythm classification from electrocardiograms (Hannun et al., 2019), seizure detection and seizure-type classification from electroencephalographic recordings (Tang et al., 2022), and sleep staging from electrophysiological recordings (Miladinović et al., 2019; Perslev et al., 2021). However, in practical applications, models are often applied to data from different populations, recording sites, sensor types and placements, or annotation practices, resulting in distribution shift relative to the training data (Ovadia et al., 2019; Dockès et al., 2021; Wagh et al., 2022). Moreover, several of these factors may change simultaneously, producing structured shifts that may not be well represented by the synthetic corruptions commonly used to study distribution shift (Koh et al., 2021). Generalization beyond the training distribution is therefore critical for reliable deployment.

As both predictive accuracy and model confidence often degrade under distribution shift (Ovadia et al., 2019), reliable deployment necessitates well-calibrated probabilities to flag potential model errors. A well-calibrated classifier assigns confidence levels that match the observed frequency of correct predictions (Guo et al., 2017). Such probabilities can support risk-aware use of machine-learning models, including selective prediction, in which uncertain cases are deferred for expert review (Amodei et al., 2016; Geifman and El-Yaniv, 2017).

Bayesian neural networks represent model uncertainty by inferring a posterior distribution over the model parameters or the function space directly and form predictions by marginalizing over the corresponding posterior (Blundell et al., 2015; Rudner et al., 2022). Because exact Bayesian inference is generally intractable for neural networks, practical Bayesian model averaging (BMA) relies on scalable approximations. Many of these approaches characterize uncertainty within a single posterior basin, whereas deep ensembles (DEs) and related multi-basin methods average predictions across independent solutions (Lakshminarayanan et al., 2017; Wilson and Izmailov, 2020).

However, whether approximate BMA systematically improves reliability under distribution shift remains unsettled. Large-scale comparisons have found that model averaging, particularly DEs, can provide strong predictive performance and uncertainty estimates under increasing distribution shift (Ovadia et al., 2019). However, a more accurate approximation of the Bayesian posterior does not necessarily translate into greater robustness under covariate shift (Izmailov et al., 2021), and adding local posterior structure to DEs can improve out-of-distribution (OOD) performance while reducing in-distribution (ID) performance (Jordahn et al., 2025). At the same time, most prior work on Bayesian deep learning relies on standard benchmarks and vision applications (Papamarkou et al., 2024). Whether these findings extend to naturally occurring distribution shifts in biomedical time-series classification is therefore an open question.

We address this question using automated rodent sleep scoring from electrophysiological recordings as a case study. Several strong sleep-scoring models already exist (Miladinović et al., 2019; Liu et al., 2022; Brodersen et al., 2024), yet the task combines several challenges relevant to reliable deployment. Recordings vary across laboratories, acquisition systems, genotypes, experimental interventions, and species, with several factors varying simultaneously across cohorts (Miladinović et al., 2019). Moreover, rodent sleep scoring lacks universally accepted scoring conventions, and signal artifacts can complicate annotation (Rayan et al., 2024). These characteristics make rodent sleep scoring a useful test case for evaluating approximate BMA under structured, naturally occurring distribution shifts and for assessing whether predictive uncertainty identifies OOD recordings, artifacts, and disagreement between independent scorers. Although prior work has examined generalization across several of these shifts, to our knowledge no sleep-staging study has systematically compared a broad range of single- and multi-basin approximate BMA methods under natural distribution shift.

Our contributions are as follows:

• We conduct a systematic comparison of nine scalable posterior approximation and model-averaging methods across two complementary neural network architectures. The methods are the last-layer Laplace approximation (LLLA) (Kristiadi et al., 2020); stochastic weight averaging (SWA) and stochastic weight averaging-Gaussian (SWAG) (Izmailov et al., 2018; Maddox et al., 2019); variational gradient descent (VGD) and mean-field variational inference (MFVI) (Ghosh et al., 2025; Blundell et al., 2015); stochastic gradient Langevin dynamics (SGLD) (Welling and Teh, 2011); DEs, MultiSWA, and MultiSWAG (Lakshminarayanan et al., 2017; Wilson and Izmailov, 2020).

• We evaluate classification accuracy and calibration for a large in-the-wild dataset and five naturally shifted OOD cohorts spanning differences in genotype, laboratory and acquisition configuration, signal montage, and species.

• Beyond aggregate predictive performance and calibration, we assess whether predictive uncertainty supports OOD, artifact, and inter-scorer disagreement detection, as well as selective prediction.

References (49)

  • Concrete Problems in AI Safety
  • Scoring sleep with artificial intelligence enables quantification of sleep stage ambiguity: hypnodensity based on multiple expert scorers and auto-scoring
  • Robust, automated sleep scoring by a compact neural network with distributional shift correction
  • Weight Uncertainty in Neural Networks
  • Somnotate: A probabilistic sleep stage classifier for studying vigilance state transitions
  • Stochastic Gradient Hamiltonian Monte Carlo
  • Laplace redux - effortless bayesian deep learning
  • DeepSleepNet-Lite: A Simplified Automatic Sleep Stage Scoring Model With Uncertainty Estimates
  • Multi-scored sleep databases: how to exploit the multiple-labels in automated sleep scoring
  • Selective classification for deep neural networks
  • Bias-Reduced Uncertainty Estimation for Deep Neural Classifiers
  • Variational learning finds flatter solutions at the edge of stability
  • Dreem Open Datasets: Multi-Scored Sleep Datasets to Compare Human and Automated Sleep Staging
  • RobustSleepNet: Transfer Learning for Automated Sleep Staging at Scale
  • On Calibration of Modern Neural Networks
  • FlexSleepTransformer: a transformer-based sleep staging model with flexible input channel configurations
  • Cardiologist-level arrhythmia detection and classification in ambulatory electrocardiograms using a deep neural network
  • U-PASS: An uncertainty-guided deep learning pipeline for automated sleep staging
  • Averaging Weights Leads to Wider Optima and Better Generalization
  • What Are Bayesian Neural Network Posteriors Really Like? In Proceedings of the 38th International Conference on Machine Learning, pages 4629–4640
  • On Local Posterior Structure in Deep Ensembles
  • What Uncertainties Do We Need in Bayesian Deep Learning for Computer Vision? In Advances in Neural Information Processing Systems, volume 30
  • WILDS: A Benchmark of in-the-Wild Distribution Shifts
  • Being Bayesian, Even Just a Bit, Fixes Overconfidence in
  • Simple and Scalable Predictive Uncertainty Estimation using Deep Ensembles
  • An attention-based temporal convolutional network for rodent sleep stage classification across species, mutants and experimental environments with single-channel electroencephalogram
  • A Simple Baseline for Bayesian Uncertainty in Deep Learning
  • Stochastic Gradient Descent as Approximate Bayesian Inference
  • SPINDLE: End-to-end learning from EEG/EMG to extrapolate animal sleep scoring across experimental settings, labs and species
  • Automatic sleep stage classification with deep residual networks in a mixed-cohort setting
  • Can you trust your model's uncertainty? Evaluating predictive uncertainty under dataset shift
  • Position: Bayesian Deep Learning is Needed in the Age of Large-Scale AI. In Proceedings of the 41st International Conference on Machine Learning, pages 39556–39586
  • U-Sleep: resilient high-frequency sleep staging
  • SleepTransformer: Automatic Sleep Staging With Interpretability and Uncertainty Quantification
  • The pros and cons of using automated sleep scoring in sleep research: Comparative analysis of automated sleep scoring in human and rodents: advantages and limitations
  • d., Schmidt, M. H., Bassetti, C. L. A., Tzovara, A., Faraci, F. D., and Fiorillo, L
  • Tractable Function-Space Variational Inference in Bayesian Neural Networks
  • Beyond Deep Ensembles: A Large-Scale Evaluation of Bayesian Deep Learning under Distribution Shift
  • A deep learning software tool for automated sleep staging in rats via single channel EEG. NPP—Digital Psychiatry and Neuroscience, 3(1):20
  • Neural network analysis of sleep stages enables efficient diagnosis of narcolepsy
  • Deep-SleepNet: A Model for Automatic Sleep Stage Scoring Based on Raw Single-Channel EEG. IEEE Transactions on Neural Systems and Rehabilitation Engineering, 25(11):1998–2008
  • A multimodal sleep foundation model for disease prediction
  • Direct Quantification of Uncertainty in Deep Learning-Based Automatic Sleep Staging
  • Certainty about uncertainty in sleep staging: a theoretical framework
  • Evaluating Latent Space Robustness and Uncertainty of EEG-ML Models under Realistic Distribution Shifts
  • Bayesian Learning via Stochastic Gradient Langevin Dynamics
  • Bayesian Deep Learning and a Probabilistic Perspective of Generalization
  • MC-SleepNet: Large-scale Sleep Stage Scoring in Mice by Deep Neural Networks
  • Efficient Sleep Staging With Bayesian Uncertainty-Guided Active Learning