{"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":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\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-10-05T10:40:34.498165Z","iopub.execute_input":"2023-10-05T10:40:34.498778Z","iopub.status.idle":"2023-10-05T10:40:34.942593Z","shell.execute_reply.started":"2023-10-05T10:40:34.498744Z","shell.execute_reply":"2023-10-05T10:40:34.941247Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2023-10-05T11:22:57.091815Z","iopub.execute_input":"2023-10-05T11:22:57.092332Z","iopub.status.idle":"2023-10-05T11:22:58.426959Z","shell.execute_reply.started":"2023-10-05T11:22:57.092292Z","shell.execute_reply":"2023-10-05T11:22:58.425665Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Reading Data ","metadata":{}},{"cell_type":"code","source":"path = '/kaggle/input/child-mind-institute-detect-sleep-states/'\ntrain_events = pd.read_csv(path + 'train_events.csv')\ntrain_series = pd.read_parquet(path + 'train_series.parquet')\ntest_series = pd.read_parquet(path + 'test_series.parquet')\nsample_submission = pd.read_csv(path + 'sample_submission.csv')\nprint('Reading Data done!')","metadata":{"execution":{"iopub.status.busy":"2023-10-05T10:40:34.945629Z","iopub.execute_input":"2023-10-05T10:40:34.946487Z","iopub.status.idle":"2023-10-05T10:41:32.468310Z","shell.execute_reply.started":"2023-10-05T10:40:34.946438Z","shell.execute_reply":"2023-10-05T10:41:32.467103Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Things to remember\n- A single sleep period must be at least 30 minutes in length\n- A single sleep period can be interrupted by bouts of activity that do not exceed 30 consecutive minutes\n- No sleep windows can be detected unless the watch is deemed to be worn for the duration (elaborated upon, below)\n- The longest sleep window during the night is the only one which is recorded\n- If no valid sleep window is identifiable, neither an onset nor a wakeup event is recorded for that night.\n- Sleep events do not need to straddle the day-line, and therefore there is no hard rule defining how many may occur within a given period. However, no more than one window should be assigned per night. For example, it is valid for an individual to have a sleep window from 01h00–06h00 and 19h00–23h30 in the same calendar day, though assigned to consecutive nights\n- There are roughly as many nights recorded for a series as there are 24-hour periods in that series.","metadata":{}},{"cell_type":"code","source":"train_events.info()","metadata":{"execution":{"iopub.status.busy":"2023-10-05T10:45:28.568723Z","iopub.execute_input":"2023-10-05T10:45:28.569387Z","iopub.status.idle":"2023-10-05T10:45:28.592742Z","shell.execute_reply.started":"2023-10-05T10:45:28.569354Z","shell.execute_reply":"2023-10-05T10:45:28.591499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_events.dropna(ignore_index=True,axis=0,inplace=True)\ntrain_events.info()","metadata":{"execution":{"iopub.status.busy":"2023-10-05T10:48:12.594456Z","iopub.execute_input":"2023-10-05T10:48:12.594849Z","iopub.status.idle":"2023-10-05T10:48:12.616635Z","shell.execute_reply.started":"2023-10-05T10:48:12.594821Z","shell.execute_reply":"2023-10-05T10:48:12.615422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"unique_series = list(train_series[\"series_id\"].unique())\nprint(\"Total number of unique series ids are : {}\".format(len(unique_series)))","metadata":{"execution":{"iopub.status.busy":"2023-10-05T11:25:34.446603Z","iopub.execute_input":"2023-10-05T11:25:34.446984Z","iopub.status.idle":"2023-10-05T11:25:41.887542Z","shell.execute_reply.started":"2023-10-05T11:25:34.446954Z","shell.execute_reply":"2023-10-05T11:25:41.886370Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(13,5))\nax2 = {}\n\nid = unique_series[2]\n\nax.set_title('series_id: ' + id, loc='left', fontsize=10)\nx = test_series[test_series['series_id']==id]['step']\ny_enmo = test_series[test_series['series_id']==id]['enmo']\ny_anglez = test_series[test_series['series_id']==id]['anglez']\nax.plot(x, y_enmo, label='enmo', color='magenta', lw=1, alpha=0.9)\nax.set_ylabel('enmo', fontsize=9)\nax.tick_params(labelsize=9)\nax2 = ax.twinx()\nax2.plot(x, y_anglez, label='anglez', color='lime', lw=1, alpha=0.9)\nax2.set_ylabel('anglez', fontsize=9)\n\nh1, l1 = ax.get_legend_handles_labels()\nh2, l2 = ax2.get_legend_handles_labels()\nplt.figlegend(h1+h2, l1+l2, loc='upper left', bbox_to_anchor=(0.12, 0.97, 0.0, 0.0), ncols=2)\nax.set_xlabel('step')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-10-05T11:33:38.181147Z","iopub.execute_input":"2023-10-05T11:33:38.181593Z","iopub.status.idle":"2023-10-05T11:33:38.586654Z","shell.execute_reply.started":"2023-10-05T11:33:38.181562Z","shell.execute_reply":"2023-10-05T11:33:38.585423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}