Skip to content

chieaid24/AI-Sleep-Analytics

Repository files navigation

🌝 Sleep Regression & Forecasting with Machine Learning

As someone with sleep apnea, I tracked and analyzed my CPAP data for 2 years. Here's what I found!.

🧠 Skills Used

Category Tools / Frameworks
Data Processing Python, Pandas, NumPy, Jupyter Notebooks
AWS Cloud Services SageMaker AI, S3, Glue
ML Models / Techniques Prophet, Scikit-learn, Random Forest Regression, Bayesian Optimization

✨ Overview

Every night, my CPAP (continuous positive airway pressure) uploads data like USAGE_HOURS, AHI, and LEAK, as well as an overall SLEEP_SCORE for the night—a range from 0 to 100.

  • So I made a regression model that predicts my SLEEP_SCORE for any given night
  • And a forecasting model that uses historical data to predict what my sleep will be like in the future
  • Leveraged SageMaker Studio Jupyter Notebooks for implementation, S3 for data and model storage, and Glue for generating metadata

📈 Regression Model

Purpose

  • Find the relationship between SLEEP_SCORE and the other metrics, by visualizing how each metric affects the overarching SLEEP_SCORE.

Model Comparison

  • Trained and compared several machine learning models, including Linear Regression, Random Forest, XGBoost, and a Neural Network Regressor on the same data.
  • Scikit-Learn Random Forest model performed the best.

Model Performance Table Model Performance Chart


Model Tuning

  • Picked this model, and fine-tuned its hyperparameters with Bayesian Optimization.
  • Resulted in a improvement of 8.95% in RMSE and 0.19% in R².

Final Result

  • The model is saved at models/rf_bayesian_tuned_model.pkl, and resulted in values of 0.99 R² and 0.28 RMSE.

Below are the listed features and their calculated weights on determining SLEEP_SCORE

image


💫 Forecasting Model

Purpose

  • Use time series modeling to extrapolate SLEEP_SCORE, AHI, MASK_SESSION, USAGE_HOURS, and LEAK metrics 7 days into the future.

Model Training

  • Used Meta's Prophet model to analyze each metric in the dataset, saving the last week for testing predictions
  • Achieved RMSE's of 0.83 SLEEP_SCORE points, 0.23 AHI events, 0.74 MASK_SESSION events, 0.52 USAGE_HOURS hours, and 1.9 LEAK L/h.
  • Analyzed weekly seasonality trends, for example my sleep score consistently being worse on Fridays (see below)

image

  • Example trend graph (this tracks the amount of air leaking from the mask)

image

Model Predictions

  • Loops through each of the Prophet models saved in my S3 bucket, and predicts the values for 7 days after the training data stops
  • Displayed tabularly and graphically
sleep_forecast_vid.mp4

About

Leveraged Random Forest Regression and Forecast models to analyze my sleep data from the past two years.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors