{"metadata":{"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"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"### Hello, This Notebook is a Beginner Friendly Guide for Visualization. \n\n#### Showcasing the Interactive Analysis per Subject which includes:-\n     1. Single Night\n         a.Anglez\n         b.Enmo\n     2. Full series of the subject\n\n#### I hope this notebook will help you analyse the Data and would prompt you to reuse my work. Please Upvote if it does. Thanks and Happy Kaggling.","metadata":{"_uuid":"74463933-5afe-4b15-adad-d54c135b966c","_cell_guid":"b6b75c9c-f209-4c1e-9dec-3e7f7e52210c","trusted":true}},{"cell_type":"markdown","source":"## Importing Lib","metadata":{"_uuid":"b1ba6f79-6122-4afb-b002-b65a9d7142f6","_cell_guid":"f3fcb7b7-5523-4fdf-a79f-150f28c0440e","trusted":true}},{"cell_type":"code","source":"import numpy as np \nimport pandas as pd\nimport os\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nsns.set()","metadata":{"_uuid":"30011417-a6ae-4ac7-8a04-c3f46abdd206","_cell_guid":"1f916b94-e1af-4719-b502-e9b40a83a52f","_kg_hide-input":false,"_kg_hide-output":false,"execution":{"iopub.status.busy":"2023-10-18T10:30:59.832925Z","iopub.execute_input":"2023-10-18T10:30:59.833363Z","iopub.status.idle":"2023-10-18T10:31:01.036416Z","shell.execute_reply.started":"2023-10-18T10:30:59.833334Z","shell.execute_reply":"2023-10-18T10:31:01.035066Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import dask.dataframe as dd\n# Scaling Pandas for Big Data\n# Dask is a library which have same syntax as Pandas. Support almost all Pandas function","metadata":{"_uuid":"aaef304b-e607-4806-b2b5-2ef04ca7ca71","_cell_guid":"dcc854f3-a20b-48d4-b67b-79943a0b7b6d","execution":{"iopub.status.busy":"2023-10-18T10:31:01.038419Z","iopub.execute_input":"2023-10-18T10:31:01.039664Z","iopub.status.idle":"2023-10-18T10:31:01.684851Z","shell.execute_reply.started":"2023-10-18T10:31:01.039621Z","shell.execute_reply":"2023-10-18T10:31:01.683583Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Reference**\nhttps://pandas.pydata.org/docs/user_guide/scale.html#scale-other-libraries","metadata":{"_uuid":"4859b052-c1ca-4e52-9f6d-181874ae8cad","_cell_guid":"57deb2d6-09b2-4b1a-9173-ccf03050c817","trusted":true}},{"cell_type":"markdown","source":"## Reading Data","metadata":{"_uuid":"062d8223-7a46-49af-9a7e-4bea32bd46b7","_cell_guid":"5e37d1e6-3295-441b-bd66-0e287b10b8f7","trusted":true}},{"cell_type":"markdown","source":"### Importing Reduced Memory Dataset from https://www.kaggle.com/datasets/andradaolteanu/detect-sleep-states-memory-decrease","metadata":{"_uuid":"b2f4eca2-ff36-4194-b13e-6658b0febdf2","_cell_guid":"be880423-083e-461c-877b-b41121ef6a3b","_kg_hide-input":false,"_kg_hide-output":false,"trusted":true}},{"cell_type":"markdown","source":"#### 1. Reading train_events File","metadata":{"_uuid":"85c10bd6-21c3-4197-82f5-fa739d9b1a6e","_cell_guid":"9b071181-26e2-4bd2-bcb4-33a429f24f93","trusted":true}},{"cell_type":"code","source":"train_events = dd.read_parquet(\"/kaggle/input/detect-sleep-states-memory-decrease/train_events.parquet\")\ntrain_events.head()","metadata":{"_uuid":"b5c65ac9-4c2b-4139-a386-a4777813ef40","_cell_guid":"2ac2ddba-cf63-48f9-86ad-60f77293b5b2","execution":{"iopub.status.busy":"2023-10-18T10:31:07.602927Z","iopub.execute_input":"2023-10-18T10:31:07.603670Z","iopub.status.idle":"2023-10-18T10:31:08.482364Z","shell.execute_reply.started":"2023-10-18T10:31:07.603632Z","shell.execute_reply":"2023-10-18T10:31:08.481332Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_events.dtypes\n\nprint(len(train_events))\n\n#As steps have some float values\ntrain_events[\"step\"] = train_events[\"step\"].astype(\"float\")","metadata":{"_uuid":"8751206b-e730-46ab-b935-977becb3aa01","_cell_guid":"f66649a2-e022-4301-90ff-ada1c17570c8","execution":{"iopub.status.busy":"2023-10-18T10:31:19.572967Z","iopub.execute_input":"2023-10-18T10:31:19.573368Z","iopub.status.idle":"2023-10-18T10:31:19.601141Z","shell.execute_reply.started":"2023-10-18T10:31:19.573339Z","shell.execute_reply":"2023-10-18T10:31:19.600301Z"},"_kg_hide-input":false,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_events.describe().compute()","metadata":{"_uuid":"de46a069-0a52-4c35-af57-cb3b92da6ef3","_cell_guid":"a6a1c206-ade1-476f-ab3c-811dcd762c21","execution":{"iopub.status.busy":"2023-10-18T10:31:23.144694Z","iopub.execute_input":"2023-10-18T10:31:23.145090Z","iopub.status.idle":"2023-10-18T10:31:23.323906Z","shell.execute_reply.started":"2023-10-18T10:31:23.145062Z","shell.execute_reply":"2023-10-18T10:31:23.323052Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **Steps** have not recorded properly* and contain **Missing values**\n*-Will come back to this later, So lets move-on*","metadata":{"_uuid":"9efc3bf9-7cf2-4d2d-a4bc-82aa1ced7cac","_cell_guid":"368f29f8-191f-4cba-9277-ab9e6c7b398d","trusted":true}},{"cell_type":"code","source":"#Number of User_ids in train_series\ntrain_events[\"id_map\"].nunique().compute()","metadata":{"_uuid":"229c056c-dfd0-4302-8376-4adebdc63542","_cell_guid":"2c2b9a43-d348-4c4e-a737-6292294b84e9","execution":{"iopub.status.busy":"2023-10-18T10:31:48.187573Z","iopub.execute_input":"2023-10-18T10:31:48.187977Z","iopub.status.idle":"2023-10-18T10:31:48.211624Z","shell.execute_reply.started":"2023-10-18T10:31:48.187949Z","shell.execute_reply":"2023-10-18T10:31:48.210242Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### 2. Reading Parquet File","metadata":{"_uuid":"10e4d995-18f1-44b7-bd64-c32ddbe4e2e6","_cell_guid":"cb8ea8ed-f3ab-495d-ac30-f22aa3133651","trusted":true}},{"cell_type":"code","source":"train_series = dd.read_parquet(\"/kaggle/input/detect-sleep-states-memory-decrease/train_series.parquet\")\ntrain_series.head()","metadata":{"_uuid":"d4ac9848-d0a8-4977-9081-8b495666af1c","_cell_guid":"f9e5f6d5-9c55-4f97-a1a6-42f0522d35dd","_kg_hide-input":false,"_kg_hide-output":false,"execution":{"iopub.status.busy":"2023-10-18T10:31:51.026444Z","iopub.execute_input":"2023-10-18T10:31:51.026907Z","iopub.status.idle":"2023-10-18T10:32:10.958047Z","shell.execute_reply.started":"2023-10-18T10:31:51.026874Z","shell.execute_reply":"2023-10-18T10:32:10.956868Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_series.drop(columns=[\"timestamp\"]).describe().round().compute()","metadata":{"_uuid":"3896d9cc-baa4-49ce-83d5-ee62f5dc07dc","_cell_guid":"e6c000eb-0083-48bd-8967-d184de8750fa","execution":{"iopub.status.busy":"2023-10-18T10:32:10.960291Z","iopub.execute_input":"2023-10-18T10:32:10.961020Z","iopub.status.idle":"2023-10-18T10:33:06.817344Z","shell.execute_reply.started":"2023-10-18T10:32:10.960977Z","shell.execute_reply":"2023-10-18T10:33:06.815618Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* **anglez** have value ranging from -90 to 90\n* **enmo** have value ranging from 0 to 11","metadata":{"_uuid":"a5f17c6f-173b-4061-9fb3-d61d57e2da1f","_cell_guid":"e5665fd7-153d-401e-b1ba-012c1fc822a2","execution":{"iopub.status.busy":"2023-09-22T04:02:35.438462Z","iopub.execute_input":"2023-09-22T04:02:35.438804Z","iopub.status.idle":"2023-09-22T04:02:35.446565Z","shell.execute_reply.started":"2023-09-22T04:02:35.438777Z","shell.execute_reply":"2023-09-22T04:02:35.444524Z"},"_kg_hide-input":false,"_kg_hide-output":false,"trusted":true}},{"cell_type":"markdown","source":"As Working with ***(Big Data)train_series.parquet*** file is Computationally heavy and sloww. We will work on Memory Reduction Technique.\n\n**80% Memory Reduction**: https://www.kaggle.com/code/andradaolteanu/zzz-good-night-sleep-with-80-memory-reduction/notebook","metadata":{"_uuid":"9cb4a5fc-038c-4f57-833a-7e2903b3cce6","_cell_guid":"11e2d102-0800-4e08-b204-e9bd891ae283","_kg_hide-input":false,"_kg_hide-output":false,"trusted":true}},{"cell_type":"markdown","source":"### ID Mapping File","metadata":{"_uuid":"4e93a456-0b6e-4fef-8b78-f0022631b303","_cell_guid":"a974c1e5-8ef1-4310-9960-9448be5f06a1","trusted":true}},{"cell_type":"code","source":"id_map = dd.read_parquet(\"/kaggle/input/detect-sleep-states-memory-decrease/train_id_map.parquet\")\nid_map.head()","metadata":{"_uuid":"032ada37-a356-4a4a-aa49-388f2ed01686","_cell_guid":"89a34a98-f23a-49fa-86b9-aaa45b30a1ea","execution":{"iopub.status.busy":"2023-10-18T10:33:06.819206Z","iopub.execute_input":"2023-10-18T10:33:06.819542Z","iopub.status.idle":"2023-10-18T10:33:06.866505Z","shell.execute_reply.started":"2023-10-18T10:33:06.819516Z","shell.execute_reply":"2023-10-18T10:33:06.865281Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Test Series","metadata":{"_uuid":"e1db61dc-ed41-42b8-a376-49b568c47fbd","_cell_guid":"8e66018b-93b2-4bb4-be8a-23965c47970d","trusted":true}},{"cell_type":"code","source":"test_series = dd.read_parquet(\"/kaggle/input/child-mind-institute-detect-sleep-states/test_series.parquet\")\ntest_series.head()","metadata":{"_uuid":"99eae076-8dcc-43df-b82c-f044a3b3f0f9","_cell_guid":"5dd17355-b70f-40ea-ab81-ff727eef3313","execution":{"iopub.status.busy":"2023-10-18T10:33:06.869267Z","iopub.execute_input":"2023-10-18T10:33:06.869719Z","iopub.status.idle":"2023-10-18T10:33:06.909361Z","shell.execute_reply.started":"2023-10-18T10:33:06.869679Z","shell.execute_reply":"2023-10-18T10:33:06.908119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_sub = pd.read_csv(\"/kaggle/input/child-mind-institute-detect-sleep-states/sample_submission.csv\")\nsample_sub.head()","metadata":{"_uuid":"4034184b-2ad1-421d-8768-14ae3d848f88","_cell_guid":"ff20ba0b-8a26-4be7-a083-960e75852cfc","execution":{"iopub.status.busy":"2023-10-18T10:33:06.911371Z","iopub.execute_input":"2023-10-18T10:33:06.911681Z","iopub.status.idle":"2023-10-18T10:33:06.931635Z","shell.execute_reply.started":"2023-10-18T10:33:06.911656Z","shell.execute_reply":"2023-10-18T10:33:06.930487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Analysis and Data Alignment","metadata":{"_uuid":"bc5dbae4-b21c-44c7-9185-25193815e39c","_cell_guid":"3cd7b73f-9dda-4db1-ba02-03a0367d2db0","trusted":true}},{"cell_type":"markdown","source":"# For One Subject\nThe code selects data for a specific subject (in this case, subject 0) for further analysis.","metadata":{"_uuid":"72d78018-3059-4f26-a1de-7c33c2fa1a39","_cell_guid":"5b712f60-5fec-44b3-998f-4d63ea554d70","trusted":true}},{"cell_type":"markdown","source":"> #### You can change and Analyse the Subject that which are of your Interest. Just change \"id_map\" for the same","metadata":{"_uuid":"ec5df744-030c-4710-9fad-50ae5a26d2c3","_cell_guid":"01ae9023-e804-4c37-96ef-f2bd7f9385e2","trusted":true}},{"cell_type":"code","source":"sub_sample0_events = train_events[train_events[\"id_map\"] == 0].reset_index(drop=True).compute()\n\nsub_sample0_series = train_series[train_series[\"id_map\"] == 0].reset_index(drop=True).compute()","metadata":{"_uuid":"94bc4e47-119a-48b7-9296-d4c627f7d374","_cell_guid":"507e8f51-1a5a-4d35-907f-c717c28beadf","execution":{"iopub.status.busy":"2023-10-18T10:33:16.674241Z","iopub.execute_input":"2023-10-18T10:33:16.674659Z","iopub.status.idle":"2023-10-18T10:33:38.854769Z","shell.execute_reply.started":"2023-10-18T10:33:16.674626Z","shell.execute_reply":"2023-10-18T10:33:38.853686Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Length of data present of Subject \"0\"\nlen(sub_sample0_events),len(sub_sample0_series)","metadata":{"_uuid":"4db68e7f-6a99-47d5-a51f-f4879b9b9e27","_cell_guid":"4483ae39-58c6-4846-aa91-ab0c21fa93a8","execution":{"iopub.status.busy":"2023-10-18T10:33:38.856432Z","iopub.execute_input":"2023-10-18T10:33:38.857031Z","iopub.status.idle":"2023-10-18T10:33:38.865570Z","shell.execute_reply.started":"2023-10-18T10:33:38.856980Z","shell.execute_reply":"2023-10-18T10:33:38.864177Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_sample0_events.head()","metadata":{"_uuid":"699ec1e6-8994-4877-a0ea-df24538fcb1c","_cell_guid":"4f3c2875-ef4a-43a5-a492-a9be915598ff","execution":{"iopub.status.busy":"2023-10-18T10:33:38.867153Z","iopub.execute_input":"2023-10-18T10:33:38.867485Z","iopub.status.idle":"2023-10-18T10:33:38.887883Z","shell.execute_reply.started":"2023-10-18T10:33:38.867459Z","shell.execute_reply":"2023-10-18T10:33:38.886663Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_sample0_series.head()","metadata":{"_uuid":"965973ad-107b-4e26-9ac3-c7663f2dd330","_cell_guid":"2cd0170d-b13b-4468-8cf9-c97fc792159a","execution":{"iopub.status.busy":"2023-10-18T10:33:38.890449Z","iopub.execute_input":"2023-10-18T10:33:38.891673Z","iopub.status.idle":"2023-10-18T10:33:38.906477Z","shell.execute_reply.started":"2023-10-18T10:33:38.891639Z","shell.execute_reply":"2023-10-18T10:33:38.905531Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 1. For Night 1\n* It filters the data to include only events and series data for a specific night (night 1) for the selected subject.\n* It extracts the start and end dates for night 1. **Need to filter using 2 dates**\n* It creates a DataFrame (night1_series) containing the series data for night 1.","metadata":{"_uuid":"c13f8a1f-eee9-435a-87e1-75d11f8cb633","_cell_guid":"975022dc-0b26-4242-a920-4d7fa4aa6a6e","trusted":true}},{"cell_type":"code","source":"start_date = sub_sample0_events[sub_sample0_events[\"night\"] == 1][\"timestamp\"].dt.date.unique()[0]\nend_date = sub_sample0_events[sub_sample0_events[\"night\"] == 1][\"timestamp\"].dt.date.unique()[1]\n\n# Use boolean indexing to filter the DataFrame\nnight1_series = sub_sample0_series[(sub_sample0_series['timestamp'].dt.date >= start_date) & (sub_sample0_series['timestamp'].dt.date <= end_date)]\n\nnight1_series.head()","metadata":{"_uuid":"21e159a8-b6b5-482f-8ae3-b392faf1679f","_cell_guid":"317c99f6-1eb2-4667-879d-fd9fdae27266","execution":{"iopub.status.busy":"2023-10-18T10:34:07.776075Z","iopub.execute_input":"2023-10-18T10:34:07.776519Z","iopub.status.idle":"2023-10-18T10:34:08.078007Z","shell.execute_reply.started":"2023-10-18T10:34:07.776488Z","shell.execute_reply":"2023-10-18T10:34:08.076801Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"night1_events = sub_sample0_events[sub_sample0_events[\"night\"] == 1]\nnight1_events","metadata":{"_uuid":"b88a6df5-3d59-4839-8843-7b19cad718aa","_cell_guid":"1ab231be-6c83-454d-adb7-11e3ef5b8a0e","execution":{"iopub.status.busy":"2023-10-18T10:34:11.940170Z","iopub.execute_input":"2023-10-18T10:34:11.940629Z","iopub.status.idle":"2023-10-18T10:34:11.954170Z","shell.execute_reply.started":"2023-10-18T10:34:11.940594Z","shell.execute_reply":"2023-10-18T10:34:11.953241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### **Visualization - Anglez:**\n\n* It creates an interactive line plot for the 'anglez' column, showing the changes in 'anglez' over time.\n* It adds shaded regions to represent sleep and wake-up events.","metadata":{}},{"cell_type":"code","source":"import plotly.express as px\n\nfig = px.line(night1_series, x='timestamp', y='anglez', title='Table 1 Time Series Data - Night 1')\nfig.update_xaxes(title_text='Timestamp')\nfig.update_yaxes(title_text='Anglez')\n\n# Add shaded regions for Table 2 events\nfor _, event_row in night1_events.iterrows():\n    state = \"Sleep\" if event_row[\"event\"] == 1 else \"Wakeup\"\n    fig.add_vrect(x0=event_row['timestamp'], x1=event_row['timestamp'], fillcolor='rgba(255, 0, 0, 0.3)', annotation_text=f'{state}')\n\n    fig.add_shape(type=\"rect\",\n                  x0=night1_events[\"timestamp\"][0],\n                  x1=night1_events[\"timestamp\"][1],\n                  y0=-500,  # Set this to a large negative number\n                  y1=500,   # Set this to a large positive number\n                  fillcolor=\"LightSalmon\",\n                  opacity=0.5,\n                  layer=\"below\",\n                  line_width=0,\n                  )\n# Show the interactive plot\nfig.show()","metadata":{"_uuid":"b429e81d-9a9e-4f62-b276-777344fc274f","_cell_guid":"a017864a-0505-40d4-bfec-bbb0edd0ace7","execution":{"iopub.status.busy":"2023-10-18T10:34:34.975611Z","iopub.execute_input":"2023-10-18T10:34:34.976039Z","iopub.status.idle":"2023-10-18T10:34:38.056262Z","shell.execute_reply.started":"2023-10-18T10:34:34.976006Z","shell.execute_reply":"2023-10-18T10:34:38.054443Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### **Visualization - Enmo:**\n\n* It creates an interactive line plot for the 'enmo' column, displaying the changes in 'enmo' over time.\n* Similar to the 'anglez' plot, it highlights sleep and wake-up events with shaded regions.","metadata":{}},{"cell_type":"code","source":"fig = px.line(night1_series, x='timestamp', y='enmo', title='Table 1 Time Series Data - Night 1')\nfig.update_xaxes(title_text='Timestamp')\nfig.update_yaxes(title_text='enmo')\n\n# Add shaded regions for Table 2 events\nfor _, event_row in night1_events.iterrows():\n    state = \"Sleep\" if event_row[\"event\"] == 1 else \"Wakeup\"\n    fig.add_vrect(x0=event_row['timestamp'], x1=event_row['timestamp'], fillcolor='rgba(255, 0, 0, 0.3)', annotation_text=f'{state}')\n\n    fig.add_shape(type=\"rect\",\n                  x0=night1_events[\"timestamp\"][0],\n                  x1=night1_events[\"timestamp\"][1],\n                  #y0=-500,  # Set this to a large negative number\n                  #y1=500,   # Set this to a large positive number\n                  fillcolor=\"LightSalmon\",\n                  opacity=0.5,\n                  layer=\"below\",\n                  line_width=0,\n                  )\n# Show the interactive plot\nfig.show()","metadata":{"_uuid":"061368b6-e0a7-4bec-8bb8-7e66436997e2","_cell_guid":"5940f3aa-79b0-470b-a191-7612b4511fce","execution":{"iopub.status.busy":"2023-10-18T10:34:49.567632Z","iopub.execute_input":"2023-10-18T10:34:49.568533Z","iopub.status.idle":"2023-10-18T10:34:49.893253Z","shell.execute_reply.started":"2023-10-18T10:34:49.568492Z","shell.execute_reply":"2023-10-18T10:34:49.891877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 2.For All Nights","metadata":{"_uuid":"88caf870-6068-4f12-a227-6477b065d01b","_cell_guid":"31a88870-d9ab-474d-b507-2b87fd8043b0","trusted":true}},{"cell_type":"markdown","source":"### **For All Nights:**\n\n* The code checks for and handles null values in the data, ensuring data quality.\n* It creates interactive time series plots for all nights for the selected subject, displaying the 'anglez' and 'enmo' data.\n* Similar to the night 1 plot, it highlights sleep and wake-up events with colored lines.","metadata":{}},{"cell_type":"markdown","source":"##### Handling Null Values","metadata":{"_uuid":"33f706f5-4327-4902-98e3-b3de00de2f81","_cell_guid":"5124aa42-6844-4352-825e-91adde1951b8","trusted":true}},{"cell_type":"code","source":"#Checking for null values in series data\nsub_sample0_series.isnull().sum()","metadata":{"_uuid":"b1511740-5be0-4a71-bfe9-52efc3b213ed","_cell_guid":"33bdd3e8-2db1-430f-8f3d-e80fd7064409","execution":{"iopub.status.busy":"2023-10-18T10:34:57.637647Z","iopub.execute_input":"2023-10-18T10:34:57.638087Z","iopub.status.idle":"2023-10-18T10:34:57.649849Z","shell.execute_reply.started":"2023-10-18T10:34:57.638056Z","shell.execute_reply":"2023-10-18T10:34:57.648958Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Checking for null values in events data\nsub_sample0_events.isnull().sum()","metadata":{"_uuid":"342131cc-0e94-4e4d-bce2-0105614c48a4","_cell_guid":"79f8778b-6529-40d6-a937-8cce4c8358a1","execution":{"iopub.status.busy":"2023-10-18T10:35:00.342417Z","iopub.execute_input":"2023-10-18T10:35:00.342938Z","iopub.status.idle":"2023-10-18T10:35:00.353349Z","shell.execute_reply.started":"2023-10-18T10:35:00.342898Z","shell.execute_reply":"2023-10-18T10:35:00.351732Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Droping Null Values\nsub_sample0_events = sub_sample0_events.dropna().reset_index(drop=True)","metadata":{"_uuid":"8cf3a487-427d-4bb6-9f05-1b7607f2341c","_cell_guid":"dca7986d-2d76-4034-bb1d-657d3ef68ab7","execution":{"iopub.status.busy":"2023-10-18T10:35:10.303307Z","iopub.execute_input":"2023-10-18T10:35:10.303753Z","iopub.status.idle":"2023-10-18T10:35:10.311526Z","shell.execute_reply.started":"2023-10-18T10:35:10.303721Z","shell.execute_reply":"2023-10-18T10:35:10.310214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### **Visualization - Anglez:**","metadata":{"_uuid":"9d7cb0ab-995f-4b2b-9189-d3cc4a084cc8","_cell_guid":"0155056e-1512-48a1-b047-9f081325272d","trusted":true}},{"cell_type":"code","source":"import pandas as pd\nimport plotly.express as px\nimport plotly.graph_objects as go\n\n# Create an interactive time series plot using Plotly Express\nfig = px.line(sub_sample0_series, x='timestamp', y='anglez', title='Interactive Time Series Plot - Anglez')\nfig.update_xaxes(title_text='Timestamp')\nfig.update_yaxes(title_text='Anglez')\n\n# Create lines for events with different colors\nfor index, row in sub_sample0_events.iterrows():\n    state = \"Sleep\" if row[\"event\"] == 1 else \"Wakeup\"\n    color = 'red' if row['event'] == 1 else 'green'\n    fig.add_shape(\n        go.layout.Shape(\n            type=\"line\",\n            x0=row['timestamp'],\n            x1=row['timestamp'],\n            y0=-500,\n            y1=500,  # Adjust this value to match your Y-axis range\n            line=dict(color=color),\n            name=f'{state}',\n        )\n    )\n\n# Adjust the figure size\nfig.update_layout(\n    width=7000,  # Set the width of the figure\n    height=400,  # Set the height of the figure\n)\n\n# Show the interactive Plotly plot\nfig.show()","metadata":{"_uuid":"e435518c-61ce-4a98-b913-d421b5e4b2ad","_cell_guid":"4dada43f-3ff5-4b60-b38c-a97136035048","execution":{"iopub.status.busy":"2023-10-18T10:39:46.628612Z","iopub.execute_input":"2023-10-18T10:39:46.629055Z","iopub.status.idle":"2023-10-18T10:39:51.145890Z","shell.execute_reply.started":"2023-10-18T10:39:46.629019Z","shell.execute_reply":"2023-10-18T10:39:51.143898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### **Visualization - ENMO:**","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport plotly.express as px\nimport plotly.graph_objects as go\n\n# Create an interactive time series plot using Plotly Express\nfig = px.line(sub_sample0_series, x='timestamp', y='enmo', title='Interactive Time Series Plot-ENMO')\nfig.update_xaxes(title_text='Timestamp')\nfig.update_yaxes(title_text='enmo')\n\n# Create lines for events with different colors\nfor index, row in sub_sample0_events.iterrows():\n    state = \"Sleep\" if row[\"event\"] == 1 else \"Wakeup\"\n    color = 'red' if row['event'] == 1 else 'green'\n    fig.add_shape(\n        go.layout.Shape(\n            type=\"line\",\n            x0=row['timestamp'],\n            x1=row['timestamp'],\n            #y0=-500,\n            #y1=500,  # Adjust this value to match your Y-axis range\n            line=dict(color=color),\n            name=f'{state}',\n        )\n    )\n\n# Adjust the figure size\nfig.update_layout(\n    width=7000,  # Set the width of the figure\n    height=400,  # Set the height of the figure\n)\n\n# Show the interactive Plotly plot\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2023-10-18T10:39:52.979513Z","iopub.execute_input":"2023-10-18T10:39:52.979929Z","iopub.status.idle":"2023-10-18T10:39:57.362572Z","shell.execute_reply.started":"2023-10-18T10:39:52.979898Z","shell.execute_reply":"2023-10-18T10:39:57.355289Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# THE END","metadata":{}}]}