Skip to content
0

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.
import seaborn as sns
import matplotlib.pyplot as plt

# Convert categorical variables to category type
categorical_columns = ['Gender', 'Occupation', 'Quality of Sleep', 'Physical Activity Level', 'Stress Level', 'Blood Pressure', 'BMI Category', 'Sleep Disorder']
for col in categorical_columns:
    raw_data[col] = raw_data[col].astype('category')

# Bar chart to examine relationships between Gender and Sleep Disorder
plt.figure(figsize=(10, 6))
sns.countplot(data=raw_data, x='Gender', hue='Sleep Disorder')
plt.title('Gender vs Sleep Disorder')
plt.xlabel('Gender')
plt.ylabel('Count')
plt.legend(title='Sleep Disorder')
plt.show()

# Histogram to examine relationships between Age and Sleep Disorder
plt.figure(figsize=(10, 6))
sns.histplot(data=raw_data, x='Age', hue='Sleep Disorder', multiple='stack', bins=20)
plt.title('Age vs Sleep Disorder')
plt.xlabel('Age')
plt.ylabel('Count')
plt.legend(title='Sleep Disorder')
plt.show()

# Bar chart to examine relationships between Occupation and Sleep Disorder
plt.figure(figsize=(10, 6))
sns.countplot(data=raw_data, x='Occupation', hue='Sleep Disorder')
plt.title('Occupation vs Sleep Disorder')
plt.xlabel('Occupation')
plt.ylabel('Count')
plt.xticks(rotation=90)
plt.legend(title='Sleep Disorder')
plt.show()

# Bar chart to examine relationships between Sleep Duration and Sleep Disorder
plt.figure(figsize=(10, 6))
sns.countplot(data=raw_data, x='Sleep Duration', hue='Sleep Disorder')
plt.title('Sleep Duration vs Sleep Disorder')
plt.xlabel('Sleep Duration')
plt.ylabel('Count')
plt.legend(title='Sleep Disorder')
plt.show()

# Bar chart to examine relationships between Quality of Sleep and Sleep Disorder
plt.figure(figsize=(10, 6))
sns.countplot(data=raw_data, x='Quality of Sleep', hue='Sleep Disorder')
plt.title('Quality of Sleep vs Sleep Disorder')
plt.xlabel('Quality of Sleep')
plt.ylabel('Count')
plt.legend(title='Sleep Disorder')
plt.show()

# Bar chart to examine relationships between Physical Activity Level and Sleep Disorder
plt.figure(figsize=(10, 6))
sns.countplot(data=raw_data, x='Physical Activity Level', hue='Sleep Disorder')
plt.title('Physical Activity Level vs Sleep Disorder')
plt.xlabel('Physical Activity Level')
plt.ylabel('Count')
plt.legend(title='Sleep Disorder')
plt.show()

# Bar chart to examine relationships between Stress Level and Sleep Disorder
plt.figure(figsize=(10, 6))
sns.countplot(data=raw_data, x='Stress Level', hue='Sleep Disorder')
plt.title('Stress Level vs Sleep Disorder')
plt.xlabel('Stress Level')
plt.ylabel('Count')
plt.legend(title='Sleep Disorder')
plt.show()

# Bar chart to examine relationships between Blood Pressure and Sleep Disorder
plt.figure(figsize=(10, 6))
sns.countplot(data=raw_data, x='Blood Pressure', hue='Sleep Disorder')
plt.title('Blood Pressure vs Sleep Disorder')
plt.xlabel('Blood Pressure')
plt.ylabel('Count')
plt.xticks(rotation=90)
plt.legend(title='Sleep Disorder')
plt.show()

# Bar chart to examine relationships between Heart Rate and Sleep Disorder
plt.figure(figsize=(10, 6))
sns.countplot(data=raw_data, x='Heart Rate', hue='Sleep Disorder')
plt.title('Heart Rate vs Sleep Disorder')
plt.xlabel('Heart Rate')
plt.ylabel('Count')
plt.legend(title='Sleep Disorder')
plt.show()

# Bar chart to examine relationships between Daily Steps and Sleep Disorder
plt.figure(figsize=(10, 6))
sns.countplot(data=raw_data, x='Daily Steps', hue='Sleep Disorder')
plt.title('Daily Steps vs Sleep Disorder')
plt.xlabel('Daily Steps')
plt.ylabel('Count')
plt.legend(title='Sleep Disorder')
plt.show()

# Bar chart to examine relationships between BMI Category and Sleep Disorder
plt.figure(figsize=(10, 6))
sns.countplot(data=raw_data, x='BMI Category', hue='Sleep Disorder')
plt.title('BMI Category vs Sleep Disorder')
plt.xlabel('BMI Category')
plt.ylabel('Count')
plt.legend(title='Sleep Disorder')
plt.show()