JuliaCon 2025

Sleep Stage Classification in Julia
2025-07-24 , Lawrence Room 104 - Function Room

We present a Julia-based machine learning pipeline for sleep stage classification using the DREAMT wearable-PSG paired dataset. Our models, leveraging features from the Empatica E4 wristband, achieve AUC up to 0.92 in Wake/NREM/REM stage classification, with Random Forests matching Python benchmarks. Results establish Julia as a viable platform for biosignal processing and sleep research.


Sleep is essential for physical and cognitive well-being, yet disorders like insomnia and sleep apnea frequently go undiagnosed. The current clinical standard for detecting sleep stages, polysomnography (PSG), is accurate but resource-intensive, requiring complex sensor setups and manual annotations. Recent advances in wearable technology and machine learning provide a promising alternative by enabling more scalable and passive sleep monitoring. However, most work in this area is conducted in Python, with limited exploration of Julia, a high-performance language suited for scientific computing.

This study presents a full machine learning pipeline for classifying sleep into three broad stages, Wake, NREM, and REM, using wearable-derived data, entirely implemented in Julia. We use the DREAMT dataset, which includes synchronized PSG and wristband signals (BVP, EDA, skin temperature, accelerometry) from 100 subjects. Standard signal preprocessing and feature extraction techniques were applied, and class imbalance was addressed using SMOTE, implemented in Julia. We trained three models: Logistic Regression, LASSO Regression, and Random Forests, using leave-one-subject-out cross-validation to evaluate generalizability.

The Random Forest model achieved the best overall performance, reaching an AUC of 0.92 and F1-scores of 0.88 (Wake), 0.87 (NREM), and 0.83 (REM), comparable to existing Python-based pipelines. LASSO provided useful feature interpretability, highlighting the importance of heart rate variability, movement, and circadian trends. REM was the most difficult stage to distinguish, likely due to its autonomic overlap with wake periods. Julia’s performance proved comparable or superior in runtime efficiency for key steps such as cross-validation and numerical processing.

To our knowledge, this is the first end-to-end wearable-based sleep classification study conducted in Julia. Beyond benchmarking Julia’s feasibility in biosignal analysis, our work offers a reusable template for health researchers and developers seeking alternatives to Python. Future work includes deep learning implementation via Flux.jl and tailoring models for personalized sleep tracking.

Shaurya is a high schooler from Northern Virginia interested in machine learning and computational techniques to improve human welfare, particularly interested in signal processing, feature engineering, and optimizing sleep.