{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport seaborn as sns\nimport pyarrow as pa\nimport pyarrow.parquet as pq\nfrom scipy import stats\n\nsns.set_style(\"whitegrid\", rc = {\"grid.color\": \".6\", \"grid.linestyle\": \"--\"})\n\nimport matplotlib.pyplot as plt\nplt.rcParams['lines.linestyle'] = '--'\n\nimport warnings\nwarnings.filterwarnings('ignore')\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-09-11T15:16:00.367147Z","iopub.execute_input":"2023-09-11T15:16:00.367553Z","iopub.status.idle":"2023-09-11T15:16:01.382069Z","shell.execute_reply.started":"2023-09-11T15:16:00.367521Z","shell.execute_reply":"2023-09-11T15:16:01.381141Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# read events data","metadata":{}},{"cell_type":"code","source":"\nschema = {'series_id':'string',\n         'night':'uint16',\n         'event':'string',\n         'step':'float32'\n         }\nevents_data = pd.read_csv('/kaggle/input/child-mind-institute-detect-sleep-states/train_events.csv',dtype = schema)\n\nevents_data['timestamp'] =pd.to_datetime(events_data['timestamp'],utc=True,errors='coerce')\n","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:01.384284Z","iopub.execute_input":"2023-09-11T15:16:01.385786Z","iopub.status.idle":"2023-09-11T15:16:01.582985Z","shell.execute_reply.started":"2023-09-11T15:16:01.385740Z","shell.execute_reply":"2023-09-11T15:16:01.581817Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# print('Number of unique users/ accelerometer in series data  :',  series_data.series_id.nunique())\nprint('Number of unique users/ accelerometer in event data :',  events_data.series_id.nunique())","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:01.584311Z","iopub.execute_input":"2023-09-11T15:16:01.584709Z","iopub.status.idle":"2023-09-11T15:16:01.591837Z","shell.execute_reply.started":"2023-09-11T15:16:01.584675Z","shell.execute_reply":"2023-09-11T15:16:01.590994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# only 37 series of events data have non null rows   \nevents_data.groupby('series_id')['step'].apply(lambda x:x.isnull().any()).value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:01.594306Z","iopub.execute_input":"2023-09-11T15:16:01.595397Z","iopub.status.idle":"2023-09-11T15:16:01.652561Z","shell.execute_reply.started":"2023-09-11T15:16:01.595336Z","shell.execute_reply":"2023-09-11T15:16:01.651410Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> ## Not all events for each series are null. we need to find out % of missing rows for each series and then keep/drop them accordingly ","metadata":{}},{"cell_type":"code","source":"null_series_id= events_data.groupby('series_id').agg({'step': lambda x : (x.isnull().sum() / (len(x)) *100)\n                                     }).reset_index()\n\nprint('Number of series which have 0% null rows are : ',len(null_series_id[null_series_id['step']==0]))\nprint('Number of series which have LT 25% null rows : ',len(null_series_id[null_series_id['step']<=25]))","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:01.653979Z","iopub.execute_input":"2023-09-11T15:16:01.654312Z","iopub.status.idle":"2023-09-11T15:16:01.712332Z","shell.execute_reply.started":"2023-09-11T15:16:01.654282Z","shell.execute_reply":"2023-09-11T15:16:01.711164Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> ### I will have to find a way to fill these 156 series which have less than 25 % null rows. I will do it later ","metadata":{}},{"cell_type":"code","source":"null_series_id = null_series_id[null_series_id['step']==0]['series_id'].to_list()","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:01.713569Z","iopub.execute_input":"2023-09-11T15:16:01.713878Z","iopub.status.idle":"2023-09-11T15:16:01.720716Z","shell.execute_reply.started":"2023-09-11T15:16:01.713851Z","shell.execute_reply":"2023-09-11T15:16:01.719119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# taking events which have atmost 25% null rows\nevents_data = events_data[events_data['series_id'].isin(null_series_id)]","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:01.722553Z","iopub.execute_input":"2023-09-11T15:16:01.722917Z","iopub.status.idle":"2023-09-11T15:16:01.736552Z","shell.execute_reply.started":"2023-09-11T15:16:01.722886Z","shell.execute_reply":"2023-09-11T15:16:01.735146Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Function to label nights as weekend or weekday\ndef is_weekend(row):\n    onset_day = row['timestamp'].weekday()  # 0 for monday, 6 for Sunday\n    if row['event'] == 'onset' and (onset_day == 4 or onset_day == 5):  # If it's a Friday or saturday then its a weekend night\n        return 1\n    else:\n        return 0\n\nevents_data['is_weekend'] = events_data.apply(is_weekend, axis=1)\nevents_data['is_weekend'] = events_data['is_weekend'].astype('uint8')","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:01.738380Z","iopub.execute_input":"2023-09-11T15:16:01.739279Z","iopub.status.idle":"2023-09-11T15:16:01.770995Z","shell.execute_reply.started":"2023-09-11T15:16:01.739240Z","shell.execute_reply":"2023-09-11T15:16:01.769996Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Forward-fill the 'is_weekend' column for 'wakeup' events on the same night\nevents_data['is_weekend'] = events_data.groupby(['series_id', 'night'])['is_weekend'].transform('max')","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:01.772829Z","iopub.execute_input":"2023-09-11T15:16:01.773160Z","iopub.status.idle":"2023-09-11T15:16:01.782999Z","shell.execute_reply.started":"2023-09-11T15:16:01.773134Z","shell.execute_reply":"2023-09-11T15:16:01.781668Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"events_data","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:01.787023Z","iopub.execute_input":"2023-09-11T15:16:01.787528Z","iopub.status.idle":"2023-09-11T15:16:01.808895Z","shell.execute_reply.started":"2023-09-11T15:16:01.787490Z","shell.execute_reply":"2023-09-11T15:16:01.807686Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# each step is 5 min ( checked from series_data ) , so converting to hours \nevents_data['sleep_duration'] = (( events_data.groupby(['series_id','night'])['step'].diff()*5 ) /3600)#.fillna(0)\n\nevents_data['sleep_duration'] = events_data.groupby(['series_id', 'night'])['sleep_duration'].transform('max')","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:01.810190Z","iopub.execute_input":"2023-09-11T15:16:01.810902Z","iopub.status.idle":"2023-09-11T15:16:01.823181Z","shell.execute_reply.started":"2023-09-11T15:16:01.810869Z","shell.execute_reply":"2023-09-11T15:16:01.822285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"events_data","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:01.824679Z","iopub.execute_input":"2023-09-11T15:16:01.825030Z","iopub.status.idle":"2023-09-11T15:16:01.852885Z","shell.execute_reply.started":"2023-09-11T15:16:01.825000Z","shell.execute_reply":"2023-09-11T15:16:01.851938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Average sleep time","metadata":{}},{"cell_type":"code","source":"mean_sleep_duration = events_data.dropna().groupby(['series_id'])['sleep_duration'].mean().sort_values().reset_index()\n\nplt.figure(figsize=(12, 4))\nplt.bar(mean_sleep_duration['series_id'], mean_sleep_duration['sleep_duration'])\nplt.xlabel('Series ID')\nplt.ylabel('Mean Sleep Duration')\nplt.title('Mean Sleep Duration by Series ID')\nplt.xticks(rotation=45) \nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:01.854178Z","iopub.execute_input":"2023-09-11T15:16:01.854744Z","iopub.status.idle":"2023-09-11T15:16:02.622795Z","shell.execute_reply.started":"2023-09-11T15:16:01.854711Z","shell.execute_reply":"2023-09-11T15:16:02.621715Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## do users sleep more on average on weekends ? ","metadata":{}},{"cell_type":"code","source":"sns.boxplot(data= events_data[events_data['event']=='wakeup'],x='is_weekend',y='sleep_duration')","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:02.624293Z","iopub.execute_input":"2023-09-11T15:16:02.625241Z","iopub.status.idle":"2023-09-11T15:16:02.900592Z","shell.execute_reply.started":"2023-09-11T15:16:02.625205Z","shell.execute_reply":"2023-09-11T15:16:02.899257Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"weekend_sleep = events_data[(events_data['is_weekend'] == 1) & (events_data['event']=='wakeup') ]['sleep_duration'].fillna(0)\nweekday_sleep = events_data[(events_data['is_weekend'] == 0) & (events_data['event']=='wakeup')]['sleep_duration'].fillna(0)\n\n# t-test\nt_stat, p_value = stats.ttest_ind(weekend_sleep, weekday_sleep)\n\n# significance level\nalpha = 0.05\n\nprint(f'T-statistic: {t_stat}')\nprint(f'P-value: {p_value}')\n\nif p_value < alpha:\n    print('Reject the null hypothesis: People sleep significantly more on weekends.')\nelse:\n    print('Fail to reject the null hypothesis: There is no significant difference in sleep duration between weekends and weekdays.')\n","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:02.902104Z","iopub.execute_input":"2023-09-11T15:16:02.902561Z","iopub.status.idle":"2023-09-11T15:16:02.919615Z","shell.execute_reply.started":"2023-09-11T15:16:02.902524Z","shell.execute_reply":"2023-09-11T15:16:02.918174Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## How many DAYTIME sleep cycles are present ?","metadata":{}},{"cell_type":"code","source":"events_data['hour'] = pd.to_datetime(events_data['timestamp']).dt.hour\n\nevents_data['is_daytime_sleeping'] = 'night'\nevents_data.loc[(events_data['hour']<7) &  (events_data['event']=='onset'),'is_daytime_sleeping'] = 'day'","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:02.921437Z","iopub.execute_input":"2023-09-11T15:16:02.921793Z","iopub.status.idle":"2023-09-11T15:16:02.935298Z","shell.execute_reply.started":"2023-09-11T15:16:02.921764Z","shell.execute_reply":"2023-09-11T15:16:02.934070Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"events_data","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:02.936738Z","iopub.execute_input":"2023-09-11T15:16:02.937107Z","iopub.status.idle":"2023-09-11T15:16:02.959485Z","shell.execute_reply.started":"2023-09-11T15:16:02.937076Z","shell.execute_reply":"2023-09-11T15:16:02.958466Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Create a count plot for day vs. night\nplt.figure(figsize=(10, 4))\nsns.countplot(data=events_data, x='is_daytime_sleeping')\nplt.title('Count of Day vs. Night Sleep')\nplt.xlabel('Day vs. Night')\nplt.ylabel('Count')\n\n# Create a box plot for daytime vs. nighttime sleep duration\nplt.figure(figsize=(10, 4))\nsns.boxplot(data=events_data[events_data['event'] == 'onset'], x='is_daytime_sleeping', y='sleep_duration')\nplt.title('Daytime vs. Nighttime Sleep Duration')\nplt.xlabel('Daytime vs. Nighttime')\nplt.ylabel('Sleep Duration')\n\n# Create a box plot for daytime vs. nighttime sleep duration\nplt.figure(figsize=(10, 4))\nsns.boxplot(data=events_data[events_data['event'] == 'onset'], x='is_daytime_sleeping', y='sleep_duration', hue='is_weekend')\nplt.title('Daytime vs. Nighttime Sleep Duration')\nplt.xlabel('Daytime vs. Nighttime')\nplt.ylabel('Sleep Duration')\n\nplt.show()\n\n","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:02.961214Z","iopub.execute_input":"2023-09-11T15:16:02.961587Z","iopub.status.idle":"2023-09-11T15:16:03.873464Z","shell.execute_reply.started":"2023-09-11T15:16:02.961554Z","shell.execute_reply":"2023-09-11T15:16:03.872619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# user sleeping less on average if it's a weekend night ","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:03.874640Z","iopub.execute_input":"2023-09-11T15:16:03.875621Z","iopub.status.idle":"2023-09-11T15:16:03.880447Z","shell.execute_reply.started":"2023-09-11T15:16:03.875584Z","shell.execute_reply":"2023-09-11T15:16:03.879307Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## series data","metadata":{}},{"cell_type":"code","source":"# for replacing seriesId with a uniqueID \nseries_id_map = {value: series_id for series_id,value in enumerate(events_data['series_id'].unique())}\n\nevents_data['series_id'] = events_data['series_id'].map(series_id_map)","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:03.881767Z","iopub.execute_input":"2023-09-11T15:16:03.882073Z","iopub.status.idle":"2023-09-11T15:16:03.897615Z","shell.execute_reply.started":"2023-09-11T15:16:03.882046Z","shell.execute_reply":"2023-09-11T15:16:03.896226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\nschema = pa.schema([('series_id',pa.string()),\n          ('step',pa.int32()),\n          ('timestamp',pa.timestamp('ms',tz='UTC')),\n          ('anglez',pa.float32()),\n          ('enmo',pa.float32())\n         ])\nseries_data = pq.read_table('/kaggle/input/child-mind-institute-detect-sleep-states/train_series.parquet',schema=schema)\n\nseries_data = series_data.to_pandas()","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:03.901546Z","iopub.execute_input":"2023-09-11T15:16:03.901979Z","iopub.status.idle":"2023-09-11T15:16:21.061941Z","shell.execute_reply.started":"2023-09-11T15:16:03.901944Z","shell.execute_reply":"2023-09-11T15:16:21.060943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n# series data should have same cases as events data \nseries_data = series_data[series_data['series_id'].isin(series_id_map.keys())]\n# map series_id with unique ID \nseries_data['series_id'] = series_data['series_id'].map(series_id_map)\n# space saving \nseries_data['series_id'] = series_data['series_id'].astype('int16')","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:21.063378Z","iopub.execute_input":"2023-09-11T15:16:21.064014Z","iopub.status.idle":"2023-09-11T15:16:30.438678Z","shell.execute_reply.started":"2023-09-11T15:16:21.063980Z","shell.execute_reply":"2023-09-11T15:16:30.437415Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Number of unique users/ accelerometer in series data  :',  series_data.series_id.nunique())\nprint('Number of unique users/ accelerometer in event data :',  events_data.series_id.nunique())","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:30.440395Z","iopub.execute_input":"2023-09-11T15:16:30.440859Z","iopub.status.idle":"2023-09-11T15:16:30.529326Z","shell.execute_reply.started":"2023-09-11T15:16:30.440817Z","shell.execute_reply":"2023-09-11T15:16:30.528082Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"unique_nights_per_series = events_data.groupby('series_id')['night'].nunique().sort_values()\n\n# Create a bar plot\nplt.figure(figsize=(8, 4))\nunique_nights_per_series.plot(kind='bar', color='blue', alpha=0.7)\nplt.xticks([])\nplt.xlabel('Series ID')\nplt.ylabel('Number of Unique Nights')\nplt.title('Number of Nights per Series')\nplt.grid(True)  # Add grid lines for the y-axis\nplt.tight_layout()\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:30.530794Z","iopub.execute_input":"2023-09-11T15:16:30.531148Z","iopub.status.idle":"2023-09-11T15:16:30.993359Z","shell.execute_reply.started":"2023-09-11T15:16:30.531117Z","shell.execute_reply":"2023-09-11T15:16:30.992184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Merge and clean","metadata":{}},{"cell_type":"code","source":"df = pd.merge(series_data,events_data[['series_id','step','event']],on = ['series_id','step'],how='left')","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:30.994679Z","iopub.execute_input":"2023-09-11T15:16:30.995025Z","iopub.status.idle":"2023-09-11T15:16:39.609707Z","shell.execute_reply.started":"2023-09-11T15:16:30.994996Z","shell.execute_reply":"2023-09-11T15:16:39.608305Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> ## I am assuming user sleeps between oneset and wakeup , so all the rows in between are sleep data","metadata":{}},{"cell_type":"markdown","source":"# dropping extra onset","metadata":{}},{"cell_type":"code","source":"# check if all series have equal wakeup and onset :\n\nfor i in df['series_id'].unique():\n    temp = pd.DataFrame(df[df['series_id']==i]['event'].value_counts()).reset_index()\n    if temp['count'].nunique() != 1:\n        print('series_id : ',i)\n        display(temp)","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:39.611445Z","iopub.execute_input":"2023-09-11T15:16:39.611995Z","iopub.status.idle":"2023-09-11T15:16:41.597436Z","shell.execute_reply.started":"2023-09-11T15:16:39.611945Z","shell.execute_reply":"2023-09-11T15:16:41.596053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# checking which index has extra onset\ndf[(df['event'].isin(['wakeup','onset'])) & (df['series_id']==15) ]","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:41.598915Z","iopub.execute_input":"2023-09-11T15:16:41.599383Z","iopub.status.idle":"2023-09-11T15:16:50.492680Z","shell.execute_reply.started":"2023-09-11T15:16:41.599337Z","shell.execute_reply":"2023-09-11T15:16:50.491454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> drop index = **'5918484'**","metadata":{}},{"cell_type":"code","source":"# checking which index has extra onset\n\ndf[(df['event'].isin(['wakeup','onset'])) & (df['series_id']==30) ]","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:50.498853Z","iopub.execute_input":"2023-09-11T15:16:50.499648Z","iopub.status.idle":"2023-09-11T15:16:59.316092Z","shell.execute_reply.started":"2023-09-11T15:16:50.499588Z","shell.execute_reply":"2023-09-11T15:16:59.314854Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> drop index = **'12168012'**","metadata":{}},{"cell_type":"code","source":"# dropping extra onset \n\ndf.drop(5918484,inplace=True)\ndf.drop(12168012,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:16:59.317490Z","iopub.execute_input":"2023-09-11T15:16:59.317929Z","iopub.status.idle":"2023-09-11T15:17:06.386646Z","shell.execute_reply.started":"2023-09-11T15:16:59.317893Z","shell.execute_reply":"2023-09-11T15:17:06.385460Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# new column 'is_asleep' \ndf['is_asleep'] = 0\n\ngroup_by_series = df.groupby('series_id')\n\n# For every series_id getting sleeping intervlas \nfor _, group_data in group_by_series:\n    onset_indices = group_data.index[group_data['event'] == 'onset']\n    wakeup_indices = group_data.index[group_data['event'] == 'wakeup']\n\n    cycle_boundaries = list(zip(onset_indices, wakeup_indices))\n\n    for cycle_start, cycle_end in cycle_boundaries:\n        df.loc[cycle_start : cycle_end - 1, 'is_asleep'] = 1","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:17:06.388231Z","iopub.execute_input":"2023-09-11T15:17:06.388745Z","iopub.status.idle":"2023-09-11T15:17:09.412910Z","shell.execute_reply.started":"2023-09-11T15:17:06.388696Z","shell.execute_reply":"2023-09-11T15:17:09.411631Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['is_asleep'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:17:09.414390Z","iopub.execute_input":"2023-09-11T15:17:09.414761Z","iopub.status.idle":"2023-09-11T15:17:09.563149Z","shell.execute_reply.started":"2023-09-11T15:17:09.414729Z","shell.execute_reply":"2023-09-11T15:17:09.562052Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(20, 8))\n\n# Plot the sleep data\nsns.lineplot(data = df[df['series_id']==15] ,x='step', y = 'anglez',hue='is_asleep', alpha=0.8)\nax.set_xlabel('timestamp')\nax.set_ylabel('anglez')\nax.set_title('Time Series of Sleep Data')\n\nax.grid(True)\nplt.tight_layout()\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:17:09.564918Z","iopub.execute_input":"2023-09-11T15:17:09.565651Z","iopub.status.idle":"2023-09-11T15:17:14.304964Z","shell.execute_reply.started":"2023-09-11T15:17:09.565607Z","shell.execute_reply":"2023-09-11T15:17:14.303737Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(20, 8))\nsns.lineplot(data = df[df['series_id']==15] ,x='step', y = 'enmo',hue='is_asleep', alpha=0.8)\nplt.xlabel('timestamp')\nplt.ylabel('enmo')\nplt.title('Time Series of Sleep Data')\n\nplt.grid(True)\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-09-11T15:17:14.306505Z","iopub.execute_input":"2023-09-11T15:17:14.307041Z","iopub.status.idle":"2023-09-11T15:17:17.050048Z","shell.execute_reply.started":"2023-09-11T15:17:14.307003Z","shell.execute_reply":"2023-09-11T15:17:17.048828Z"},"trusted":true},"execution_count":null,"outputs":[]}],"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}}