Workspace
Radoslav Gazenov/

Sleep Health and Lifestyle

0
Beta
Spinner

Sleep Health and Lifestyle

This synthetic dataset contains sleep and cardiovascular metrics as well as lifestyle factors of close to 400 fictive persons.

The workspace is set up with one CSV file, data.csv, with the following columns:

  • Person ID
  • Gender
  • Age
  • Occupation
  • Sleep Duration: Average number of hours of sleep per day
  • Quality of Sleep: A subjective rating on a 1-10 scale
  • Physical Activity Level: Average number of minutes the person engages in physical activity daily
  • Stress Level: A subjective rating on a 1-10 scale
  • BMI Category
  • Blood Pressure: Indicated as systolic pressure over diastolic pressure
  • Heart Rate: In beats per minute
  • Daily Steps
  • Sleep Disorder: One of None, Insomnia or Sleep Apnea

Check out the guiding questions or the scenario described below to get started with this dataset! Feel free to make this workspace yours by adding and removing cells, or editing any of the existing cells.

Source: Kaggle

🌎 Some guiding questions to help you explore this data:

  1. Which factors could contribute to a sleep disorder?
  2. Does an increased physical activity level result in a better quality of sleep?
  3. Does the presence of a sleep disorder affect the subjective sleep quality metric?

📊 Visualization ideas

  • Boxplot: show the distribution of sleep duration or quality of sleep for each occupation.
  • Show the link between age and sleep duration with a scatterplot. Consider including information on the sleep disorder.

🔍 Scenario: Automatically identify potential sleep disorders

This scenario helps you develop an end-to-end project for your portfolio.

Background: You work for a health insurance company and are tasked to identify whether or not a potential client is likely to have a sleep disorder. The company wants to use this information to determine the premium they want the client to pay.

Objective: Construct a classifier to predict the presence of a sleep disorder based on the other columns in the dataset.

Check out our Linear Classifiers course (Python) or Supervised Learning course (R) for a quick introduction to building classifiers.

You can query the pre-loaded CSV files using SQL directly. Here’s a sample query:

Unknown integration
DataFrameavailable as
df
variable
SELECT *
FROM 'data.csv'
LIMIT 10
This query is taking long to finish...Consider adding a LIMIT clause or switching to Query mode to preview the result.
import pandas as pd

sleep_data = pd.read_csv('data.csv')
sleep_data.head()

Ready to share your work?

Click "Share" in the upper right corner, copy the link, and share it! You can also easily add this workspace to your DataCamp Portfolio.

sleep_data.info()
from sklearn.linear_model import LinearRegression

X = sleep_data[['Age']]
y = sleep_data['Sleep Duration']

reg = LinearRegression()
reg.fit(X, y)

print('Intercept:', reg.intercept_)
print('Coefficient:', reg.coef_)

Investigating the Relationship between Physical Activity Level and Quality of Sleep

To determine whether an increased physical activity level results in a better quality of sleep, we can perform a correlation analysis between these two variables. Let's calculate the correlation coefficient and visualize the relationship using a scatter plot.

import seaborn as sns

# Calculate the correlation coefficient
correlation = sleep_data['Physical Activity Level'].corr(sleep_data['Quality of Sleep'])

# Create a scatter plot
sns.scatterplot(x='Physical Activity Level', y='Quality of Sleep', data=sleep_data)
plt.title('Physical Activity Level vs Quality of Sleep')
plt.xlabel('Physical Activity Level')
plt.ylabel('Quality of Sleep')
plt.show()

# Print the correlation coefficient
correlation
  • AI Chat
  • Code