{"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-08T15:07:49.113451Z","iopub.execute_input":"2023-10-08T15:07:49.113848Z","iopub.status.idle":"2023-10-08T15:07:49.507576Z","shell.execute_reply.started":"2023-10-08T15:07:49.113815Z","shell.execute_reply":"2023-10-08T15:07:49.506443Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\ntrain_series = pd.read_parquet('../input/child-mind-institute-detect-sleep-states/train_series.parquet')\ntrain_series","metadata":{"execution":{"iopub.status.busy":"2023-10-08T15:07:49.509777Z","iopub.execute_input":"2023-10-08T15:07:49.510955Z","iopub.status.idle":"2023-10-08T15:08:43.583186Z","shell.execute_reply.started":"2023-10-08T15:07:49.510908Z","shell.execute_reply":"2023-10-08T15:08:43.581781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"n = pd.unique(train_series['series_id'])\nlen(n) #number of subjects","metadata":{"execution":{"iopub.status.busy":"2023-10-08T15:08:43.585000Z","iopub.execute_input":"2023-10-08T15:08:43.585815Z","iopub.status.idle":"2023-10-08T15:08:51.229114Z","shell.execute_reply.started":"2023-10-08T15:08:43.585770Z","shell.execute_reply":"2023-10-08T15:08:51.228148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_events = pd.read_csv('../input/child-mind-institute-detect-sleep-states/train_events.csv')\ntrain_events","metadata":{"execution":{"iopub.status.busy":"2023-10-08T15:08:51.230450Z","iopub.execute_input":"2023-10-08T15:08:51.230780Z","iopub.status.idle":"2023-10-08T15:08:51.281788Z","shell.execute_reply.started":"2023-10-08T15:08:51.230751Z","shell.execute_reply":"2023-10-08T15:08:51.280529Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(pd.unique(train_events['series_id']))","metadata":{"execution":{"iopub.status.busy":"2023-10-08T15:08:51.285487Z","iopub.execute_input":"2023-10-08T15:08:51.285857Z","iopub.status.idle":"2023-10-08T15:08:51.293915Z","shell.execute_reply.started":"2023-10-08T15:08:51.285829Z","shell.execute_reply":"2023-10-08T15:08:51.292936Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# select first subject\nseries_1 = train_series[train_series['series_id'] == '038441c925bb']\nseries_1","metadata":{"execution":{"iopub.status.busy":"2023-10-08T15:08:51.295271Z","iopub.execute_input":"2023-10-08T15:08:51.296030Z","iopub.status.idle":"2023-10-08T15:09:01.905843Z","shell.execute_reply.started":"2023-10-08T15:08:51.295998Z","shell.execute_reply":"2023-10-08T15:09:01.904652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# see events of first subject\nevents_1 = train_events[train_events['series_id'] == '038441c925bb']\nevents_1","metadata":{"execution":{"iopub.status.busy":"2023-10-08T15:09:01.907159Z","iopub.execute_input":"2023-10-08T15:09:01.907546Z","iopub.status.idle":"2023-10-08T15:09:01.932097Z","shell.execute_reply.started":"2023-10-08T15:09:01.907518Z","shell.execute_reply":"2023-10-08T15:09:01.930881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# see series data around the event of sleep\nseries_1[4982:5002]","metadata":{"execution":{"iopub.status.busy":"2023-10-08T15:09:01.933528Z","iopub.execute_input":"2023-10-08T15:09:01.933984Z","iopub.status.idle":"2023-10-08T15:09:01.948712Z","shell.execute_reply.started":"2023-10-08T15:09:01.933946Z","shell.execute_reply":"2023-10-08T15:09:01.947901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# see series data around the event of wakeup\nseries_1[10922:10942]","metadata":{"execution":{"iopub.status.busy":"2023-10-08T15:09:01.950039Z","iopub.execute_input":"2023-10-08T15:09:01.950344Z","iopub.status.idle":"2023-10-08T15:09:01.969890Z","shell.execute_reply.started":"2023-10-08T15:09:01.950319Z","shell.execute_reply":"2023-10-08T15:09:01.968347Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\nx = series_1['step']\ny = series_1['enmo']\n\nplt.plot(x, y, color=\"k\")\nplt.vlines(x=events_1['step'], ymin=0, ymax = 3.0)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-10-08T15:09:01.971469Z","iopub.execute_input":"2023-10-08T15:09:01.972336Z","iopub.status.idle":"2023-10-08T15:09:02.347029Z","shell.execute_reply.started":"2023-10-08T15:09:01.972303Z","shell.execute_reply":"2023-10-08T15:09:02.345851Z"},"trusted":true},"execution_count":null,"outputs":[]}]}