Darrell Hall














Sign up
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

Who's Awake Watching MeTV at 2am Like Me

Sleep disturbances occur for a number of reasons. Medical, psychiatric solutions work, but at what expense. You need to go to sleep but if you take an antihistamine, you might be to groggy for the meeting in the morning. Warm milk has always been the television way of doing things. And then there are over the counter remedies like Sominex and Melatonin. Then there are the pharmaceutical remedies, Benadryl (diphenhydramine), Ambien and others. Of course, the medical conditions, primarily looked at are psychiatric in nature and used to be settled with "mother's little helper". During the early sixties they were called neuroses, which were either attributed to or thought to be caused by things like insomnia, hypochondriasis, manic depression, etc. This was the realm of the least understood but not seriously thought to be health hazards. That was until large numbers of people had become dependendt on were strung out on Valium (diazepam). And, guess what? They we're all mothers or women.

And what of the physical complaints? People in pain have trouble sleeping long after surgeries. The way its done chills me to the bone and that's why we'll dip into the constant debate on pain management, pain medicine and opioid addiction. We'll survey this data and hopefully get a line on a few other topics of interest.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

sleep_data = pd.read_csv('data.csv') 
display(sleep_data)
display(sleep_data.info())
display(sleep_data.describe())
display(sleep_data.columns)
import matplotlib.pyplot as plt

occupation_duration = sleep_data.groupby('Occupation')['Sleep Duration'].mean()
sd_= sleep_data.columns
fig, ax = plt.subplots()
ax.bar(occupation_duration.index, occupation_duration.values)
ax.set_xlabel('Occupation')
ax.set_ylabel('Average Sleep Duration')
ax.set_title('Average Sleep Duration by Occupation')
plt.xticks(rotation=90)
plt.show()
sleep_data

sleep_data['Blood Pressure'] = sleep_data['Blood Pressure'].astype('str')

sleep_data

And away we go,...

Well from here I see a that Salespeople and Scientists get the least amount of sleep and get more sleep than anyone in this study. Wonder whats the reason for this? I'm not sure right now but maybe scientist are so busy creating, testing and so forth that sleep becomes a mute point. I just started working in the insurane product sector. I'm also Data Scientist and Machine Learning Scientist. I fell asleep while watching Perry Mason, when I woke up Alfred Hitchcock was starting. That's between 11:30p and 1:30a. Its going on 5pm EST. I started yesterday at 9am. That's 2 hours sleep, and there's still more I'd like to do.

sns.scatterplot(x= 'Age', y = 'Sleep Duration', data= sleep_data)

sns.scatterplot(x= 'Age', y = 'Sleep Duration', hue= "Occupation", data= sleep_data)
plt.xticks(rotation = 45)
plt.legend(loc='lower left', bbox_to_anchor=(1, -0.2), ncol=1, fontsize='small')
plt.show()

import seaborn as sns
import matplotlib.pyplot as plt
df = sleep_data
# Create the figure and axes
fig, axes = plt.subplots(nrows=2, ncols=2)

# Plot the first plot
sns.lineplot(x="Age", y="Sleep Duration", data=df, ax=axes[0, 0])

# Plot the second plot
sns.barplot(x="Age", y="Sleep Duration", data=df, ax=axes[0, 1])

# Plot the third plot
sns.scatterplot(x="Age", y="Sleep Duration", data=df, ax=axes[1, 0])

# Plot the fourth plot
sns.heatmap(df.corr(), ax=axes[1, 1])

# Show the figure
plt.show()


import seaborn as sns
import matplotlib.pyplot as plt
df= sleep_data
# Create the figure and axes

# Plot the third plot
sns.scatterplot(x="Age", y="Sleep Duration", hue= "Occupation" ,data=df, palette = "deep")
plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left')
plt.show()

The curse of dimensionality is real and because of this feature selection is a necessary component of machine learning. During the preprocessing stage there are a number of ways to get our data to conform by peforming some transformations. You'll note in the tables below that we can now use the occupation feature to look at the distribution of various values for each profession. The tables below give an idea by the groupings I've chosen.




  • AI Chat
  • Code