This repository contains the software implementation and scientific methodology for an automated sleep stage classification project based on EEG signals. This project was completed as part of the Machine Learning course at CentraleSupélec (Instructors: Arthur Tenenhaus, Hani Hamdan).
Grade obtained: A+
Note: For a comprehensive analysis of the methodological rationale, architectural decisions, and an in-depth evaluation of the experimental results, please refer to the technical report.
The objective is the automated classification of 30-second EEG epochs into 5 distinct sleep stages (Wake, N1, N2, N3, REM). The inherent challenges of this classification task include:
- Class Imbalance: Significant under-representation of the N1 transition stage.
- Weak Signatures: The N1 stage presents ambiguous EEG signatures, making inter-class separation intrinsically difficult.
- Physiological Constraints: Sleep architecture obeys strict transition rules (e.g., direct transition from Wake to N3 is physiologically impossible).
graph TD
A[Raw EEG Signals] --> B[Preprocessing and 0.1-45Hz Filtering]
B --> C[Massive Feature Extraction<br/>~8700 features]
C --> D[Temporal Context Integration<br/>Adjacency mapping]
D --> E[Progressive Feature Selection<br/>Variance, Corr, XGBoost, SHAP]
E --> F[Random Forest Classifier<br/>Bayesian Optimization]
F --> G[Hidden Markov Model HMM<br/>Viterbi Decoding]
G --> H[Final Hypnogram]
Extraction of ~8,700 features per epoch across multiple domains:
-
Time & Spectral: PSD (
$\delta, \theta, \alpha, \sigma, \beta$ bands),$1/f$ slope,hctsa,catch22. - Time-Frequency: STFT and Wavelet decompositions (Daubechies, Symlets).
- Non-linear: Hjorth parameters, fractal dimensions, permutation entropies.
-
Targeted & Spatial: EOG/EMG markers, N2 spindles (
$\sigma$ -bursts), inter-sensor ratios.
Sequential reduction to ~500 features:
- Heuristic Filter: Removal of zero-variance and highly correlated (>95%) variables.
- Supervised Filter: XGBoost Information Gain.
- Interpretability-Driven: Class-weighted SHAP analysis (heavy penalty applied to N1 misclassification).
- Model: Random Forest (selected over XGBoost, SVM, and MLP due to superior generalization on highly redundant feature spaces).
- Optimization: Bayesian Optimization for efficient hyperparameter tuning.
- Imbalance Handling: Strict class weight adjustments (N1 x2.5).
A Hidden Markov Model (HMM) with Viterbi decoding was applied to the classifier's probabilistic outputs to enforce physiological transition rules.
- Custom Smoothing: N1 outgoing transition probabilities were explicitly adjusted to prevent the model from erasing this sparse, transient state.
The final architecture demonstrated robust generalization capabilities:
- Accuracy: 86.18%
- Macro F1-Score: 0.822
- Weighted F1-Score: 0.866
N1 remains quantitatively challenging (Precision: 47.4%, Recall: 66.0%).
notebook_final.ipynb: Software implementation of the final selected model (production pipeline: preprocessing, training, evaluation).Rapport_Kaggle_ML_Fournier.pdf: Synthesis document detailing the methodology, scientific justification, and comprehensive analysis of all tested approaches.Consigne_Challenge data - Beacon 2025_2026.pdf: Project specifications and institutional context defining the framework and objectives.pyproject.toml/poetry.lock: Configuration and virtual environment lock files.
The project uses Poetry for dependency and virtual environment management.