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.
| Column | Description |
|---|---|
Person ID | An identifier for each individual. |
Gender | The gender of the person (Male/Female). |
Age | The age of the person in years. |
Occupation | The 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 Category | The 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 Steps | The average number of steps the person takes per day. |
Sleep Disorder | The 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)
# Importing Necessary Libraries
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as pltsleep_data = pd.read_csv('sleep_health_data.csv')
sleep_data.head()Executive Summary
Stress Sleep Connection
Sleep is an essential need for humanity, along with the fact that we spend around (1/3)rd of our life sleeping. Stress not only effects our active life in a negative way but also effects our sleep negatively. Stress Levels have a high negative correlation with Sleep Duration, and a very high negative correlation with Quality of Sleep.
Stress by Occupation
Salespeople have the highest Stress Levels as compared to all the other occupations, while engineers take the least amount of stress on an average.
Scientists rank the worst in quality of sleep, and have the lowest sleep duration on average.
BMI Impact
When a person's BMI category changes from Normal to Overweight, the chance of him/her having a sleep disorder jumps form 7.4% to a whopping 87.2%. All the people in the Obese category suffer with a sleep disorder, yes thats a 100% sleep disorder rate. Although, it is to be noted that only 10 people fall into the Obese category.
Physical activity might have a lesser impact on BMI than you think.
# Data Preprocessing
# Manual Encoding of Gender
gender_mapping = {'Male': 1, 'Female': 0}
sleep_data['Gender'] = sleep_data['Gender'].map(gender_mapping)
# Manual Encoding of BMI
bmi_mapping = {'Obese': 2, 'Overweight': 1, 'Normal': 0, 'Normal Weight': 0}
sleep_data['BMI Category'] = sleep_data['BMI Category'].map(bmi_mapping)
# Manual Encoding of Sleep Disorder
sleep_disorder_mapping = {'None': 0, 'Insomnia': 1, 'Sleep Apnea': 1}
sleep_data['Sleep Disorder'] = sleep_data['Sleep Disorder'].map(sleep_disorder_mapping)
# Preprocessing of the Blood Pressure column
# Splitting The Blood Pressure Column
sleep_data[['SBP', 'DBP']] = sleep_data['Blood Pressure'].str.split('/', expand=True)
# Converting from string values to numeric values
sleep_data['SBP'] = pd.to_numeric(sleep_data['SBP'])
sleep_data['DBP'] = pd.to_numeric(sleep_data['DBP'])# Checking if there are any null values
sleep_data.isnull().values.any()Sleep's Foe #1: Stress
Stress Level has a high negative correlation with Sleep Duration, and it has a very high negative correlation with Quality of Sleep, as illustrated below:
# Selecting the columns to correlate
stress_sleep_columns = ['Stress Level', 'Sleep Duration', 'Quality of Sleep']
stress_sleep_corr = sleep_data[stress_sleep_columns].corr()
# Correlation Heatmap
sns.heatmap(stress_sleep_corr, cmap = 'RdBu', vmax = 1, vmin = -1, annot = True)
plt.show()Stress Levels by Occupation
A breakdown of the average stress level taken by each occupation is given below:
โ
โ