Skip to content
Decoding the patterns of poor (or good) sleep
0
  • AI Chat
  • Code
  • Report
  • SleepInc: Helping you find better sleep 😴

    📖 Background

    Your client is SleepInc, a sleep health company that recently launched a sleep-tracking app called SleepScope. The app monitors sleep patterns and collects users' self-reported data on lifestyle habits. SleepInc wants to identify lifestyle, health, and demographic factors that strongly correlate with poor sleep quality. They need your help to produce visualizations and a summary of findings for their next board meeting! They need these to be easily digestible for a non-technical audience!

    💾 The data

    SleepInc has provided you with an anonymized dataset of sleep and lifestyle metrics for 374 individuals. This dataset contains average values for each person calculated over the past six months.

    The dataset includes 13 columns covering sleep duration, quality, disorders, exercise, stress, diet, demographics, and other factors related to sleep health.

    ColumnDescription
    Person IDAn identifier for each individual.
    GenderThe gender of the person (Male/Female).
    AgeThe age of the person in years.
    OccupationThe occupation or profession of the person.
    Sleep Duration (hours)The average number of hours the person sleeps per day.
    Quality of Sleep (scale: 1-10)A subjective rating of the quality of sleep, ranging from 1 to 10.
    Physical Activity Level (minutes/day)The average number of minutes the person engages in physical activity daily.
    Stress Level (scale: 1-10)A subjective rating of the stress level experienced by the person, ranging from 1 to 10.
    BMI CategoryThe BMI category of the person (e.g., Underweight, Normal, Overweight).
    Blood Pressure (systolic/diastolic)The average blood pressure measurement of the person, indicated as systolic pressure over diastolic pressure.
    Heart Rate (bpm)The average resting heart rate of the person in beats per minute.
    Daily StepsThe average number of steps the person takes per day.
    Sleep DisorderThe presence or absence of a sleep disorder in the person (None, Insomnia, Sleep Apnea).

    Acknowledgments: Laksika Tharmalingam, Kaggle: https://www.kaggle.com/datasets/uom190346a/sleep-health-and-lifestyle-dataset (this is a fictitious dataset)

    import pandas as pd
    raw_data = pd.read_csv('sleep_health_data.csv')
    raw_data

    💪 Challenge

    Leverage this sleep data to analyze the relationship between lifestyle, health, demographic factors, and sleep quality. Your goal is to identify factors that correlate with poor sleep health.

    Some examples:

    • Examine relationships between several factors like gender, occupation, physical activity, stress levels, and sleep quality/duration. Create visualizations to present your findings.
    • Produce recommendations on ways people can improve sleep health based on the patterns in the data.
    • Develop an accessible summary of study findings and recommendations for improving sleep health for non-technical audiences.

    Report: improving sleep health

    Executive Summary

    The objective of this analysis was to investigate the relationship between lifestyle, health, demographic factors, and sleep quality, with a focus on identifying factors correlated with poor sleep health. The following key findings and insights were derived from the data:

    Quality of Sleep correlation analysis: Correlation coefficients were calculated to quantify the strength and direction of relationships between variables and Quality of Sleep. Notable findings include: strong positive correlation with Sleep Duration, strong negative correlation with Stress Level, significant negative correlation with Heart Rate, moderate positive correlation with Age, moderate negative correlation with Sleep Disorderand BMI Category.

    Interactions between features: Further exploration revealed interactions between features, such as the negative correlation between Stress Level and Sleep Duration, suggesting that higher stress levels are associated with shorter sleep durations.

    Regression Modeling: Three regression models (Random Forest, Linear Regression, Gradient Boosting) were fitted to the data, with Gradient Boosting emerging as the best-performing model. The selected final model is Gradient Boosting, which incorporates Sleep Duration, Stress Level, and Heart Rate as predictor variables.

    The partial dependence analysis suggest that optimal sleep quality is associated with certain patterns in sleep duration, stress levels, and heart rate. Specifically, sleep duration between 7 to 9 hours correlates with higher sleep quality, while durations below 7 hours lead to a decrease in quality. Increasing stress levels are inversely related to sleep quality, underscoring the detrimental impact of stress on sleep. The heart rate has a more complex relationship with Quality of Sleep; while a lower resting heart rate typically suggests better sleep quality, the variability in the data suggests that other factors may also play a significant role.

    Recommendations:

    The analysis highlights the importance of factors like Sleep Duration, Stress Level, and Heart Rate for improving sleep quality.

    Improving Sleep Duration:

    • Consistent sleep schedule: Try to go to bed and wake up at the same time every day, even on weekends. This helps regulate your body's internal clock.
    • Create a relaxing bedtime routine: Engage in calming activities before bed, like reading, listening to soft music, or taking a warm bath.
    • Optimize your sleep environment: Ensure your bedroom is dark, quiet, and cool. Invest in a comfortable mattress and pillows.
    • Limit Exposure to Screens: Reduce blue light exposure from phones, computers, and TV screens before bedtime as it can interfere with your ability to fall asleep.
    • Watch your diet: Avoid large meals, caffeine, and alcohol before bedtime.

    Reducing Stress Levels:

    • Regular exercise: Physical activity can help reduce stress hormones and stimulate the production of endorphins, the body's natural mood elevators.
    • Mindfulness and meditation: Practices like meditation, deep breathing, and yoga can help quiet the mind and reduce stress.
    • Time management: Prioritize tasks and break up large projects into smaller, manageable steps to avoid feeling overwhelmed.
    • Social support: Stay connected with friends and family. Social interaction can provide a sense of belonging and self-worth, which can help in times of stress.
    • Seek professional Help: If stress becomes overwhelming, consider talking to a counselor or therapist.

    Maintaining a Healthy Heart Rate:

    • Regular cardiovascular exercise: Activities like brisk walking, running, cycling, or swimming can strengthen your heart and improve its efficiency.
    • Healthy diet: Focus on a balanced diet rich in fruits, vegetables, whole grains, and lean proteins. Limit the intake of saturated fats, sugar, and salt.
    • Avoid tobacco and limit alcohol: Smoking and excessive alcohol consumption can adversely affect heart health.
    • Manage stress: As mentioned, reducing stress is also crucial for heart health. Stress can increase heart rate and blood pressure.
    • Regular health check-ups: Monitor your heart rate and blood pressure regularly and consult with a healthcare professional for personalized advice.

    These are general guidelines. Individual needs may vary, and it's important to consult with healthcare professionals for personalized advice.

    References: https://www.healthline.com/nutrition/17-tips-to-sleep-better#6.-Take-a-melatonin-supplement https://www.healthline.com/nutrition/16-ways-relieve-stress-anxiety#1.-Get-more-physical-activity https://www.health.harvard.edu/blog/increase-in-resting-heart-rate-is-a-signal-worth-watching-201112214013 https://health.clevelandclinic.org/how-to-lower-your-resting-heart-rate

    Data analysis

    Data cleaning and preprocessing

    • Blood Pressure parsing: The 'Blood Pressure' column, which contains combined systolic and diastolic values, is split into two separate columns ('Systolic BP' and 'Diastolic BP').
    • BMI category standardization: In the 'BMI Category' column, the term 'Normal Weight' is replaced with 'Normal'.
    • Column removal: Two columns, 'Person ID' and 'Blood Pressure', are removed from the dataset.
    • Convert categorical columns to numeric: The columns 'Gender', 'BMI Category', 'Sleep Disorder', and 'Occupation' are converted into numeric format.
    df.describe()

    Sleep Quality relationship with other variables

    ‌
    ‌
    ‌