{"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":"import numpy as np\nimport tensorflow as tf\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2023-11-11T05:45:29.030646Z","iopub.execute_input":"2023-11-11T05:45:29.032300Z","iopub.status.idle":"2023-11-11T05:45:44.056098Z","shell.execute_reply.started":"2023-11-11T05:45:29.032241Z","shell.execute_reply":"2023-11-11T05:45:44.054407Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"in_dir = \"/kaggle/input/child-mind-institute-detect-sleep-states/\"\ntrain = pd.read_csv(f\"{in_dir}train_events.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-11-11T05:45:44.058681Z","iopub.execute_input":"2023-11-11T05:45:44.059578Z","iopub.status.idle":"2023-11-11T05:45:44.112564Z","shell.execute_reply.started":"2023-11-11T05:45:44.059527Z","shell.execute_reply":"2023-11-11T05:45:44.111171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2023-11-11T05:45:44.116239Z","iopub.execute_input":"2023-11-11T05:45:44.116887Z","iopub.status.idle":"2023-11-11T05:45:44.148751Z","shell.execute_reply.started":"2023-11-11T05:45:44.116827Z","shell.execute_reply":"2023-11-11T05:45:44.147351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trainpq = pd.read_parquet(f\"{in_dir}train_series.parquet\")","metadata":{"execution":{"iopub.status.busy":"2023-11-11T05:45:44.151624Z","iopub.execute_input":"2023-11-11T05:45:44.152423Z","iopub.status.idle":"2023-11-11T05:47:08.952600Z","shell.execute_reply.started":"2023-11-11T05:45:44.152381Z","shell.execute_reply":"2023-11-11T05:47:08.879484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trainpq.head()","metadata":{"execution":{"iopub.status.busy":"2023-11-11T05:47:08.961516Z","iopub.execute_input":"2023-11-11T05:47:08.962019Z","iopub.status.idle":"2023-11-11T05:47:08.981243Z","shell.execute_reply.started":"2023-11-11T05:47:08.961981Z","shell.execute_reply":"2023-11-11T05:47:08.979598Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f\"\"\"There are {train[\"series_id\"].nunique()} unique ids.\"\"\")\nprint(f\"\"\"There are {train[\"night\"].nunique()} different nights.\"\"\")\nprint(f\"\"\"There are {train[\"event\"].nunique()} different events.\"\"\")\nprint(f\"\"\"There are {train[\"step\"].nunique()} unique steps.\"\"\")\nprint(f\"\"\"There are {train[\"timestamp\"].nunique()} different timestamps.\"\"\")","metadata":{"execution":{"iopub.status.busy":"2023-11-11T05:47:08.982757Z","iopub.execute_input":"2023-11-11T05:47:08.983514Z","iopub.status.idle":"2023-11-11T05:47:09.007123Z","shell.execute_reply.started":"2023-11-11T05:47:08.983471Z","shell.execute_reply":"2023-11-11T05:47:09.005895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train[\"event\"].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-11-11T05:47:09.009202Z","iopub.execute_input":"2023-11-11T05:47:09.010765Z","iopub.status.idle":"2023-11-11T05:47:09.031574Z","shell.execute_reply.started":"2023-11-11T05:47:09.010691Z","shell.execute_reply":"2023-11-11T05:47:09.029760Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trainpq[\"step\"].nunique(), trainpq[\"anglez\"].nunique(), trainpq[\"timestamp\"].nunique()","metadata":{"execution":{"iopub.status.busy":"2023-11-11T05:47:09.034417Z","iopub.execute_input":"2023-11-11T05:47:09.035745Z","iopub.status.idle":"2023-11-11T05:48:48.379772Z","shell.execute_reply.started":"2023-11-11T05:47:09.035613Z","shell.execute_reply":"2023-11-11T05:48:48.378219Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trainpq.query(\"step == 0\")[\"timestamp\"].value_counts().sort_values(ascending = False)","metadata":{"execution":{"iopub.status.busy":"2023-11-11T05:48:48.381804Z","iopub.execute_input":"2023-11-11T05:48:48.382289Z","iopub.status.idle":"2023-11-11T05:48:50.431825Z","shell.execute_reply.started":"2023-11-11T05:48:48.382250Z","shell.execute_reply":"2023-11-11T05:48:50.430516Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train","metadata":{"execution":{"iopub.status.busy":"2023-11-11T05:48:50.436014Z","iopub.execute_input":"2023-11-11T05:48:50.436548Z","iopub.status.idle":"2023-11-11T05:48:50.463947Z","shell.execute_reply.started":"2023-11-11T05:48:50.436503Z","shell.execute_reply":"2023-11-11T05:48:50.461640Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isnull().value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-11-11T05:48:50.466151Z","iopub.execute_input":"2023-11-11T05:48:50.467091Z","iopub.status.idle":"2023-11-11T05:48:50.493871Z","shell.execute_reply.started":"2023-11-11T05:48:50.467032Z","shell.execute_reply":"2023-11-11T05:48:50.492371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nullind = train[train.step.isna()].index\nnullind","metadata":{"execution":{"iopub.status.busy":"2023-11-11T05:48:50.495620Z","iopub.execute_input":"2023-11-11T05:48:50.496097Z","iopub.status.idle":"2023-11-11T05:48:50.511116Z","shell.execute_reply.started":"2023-11-11T05:48:50.496058Z","shell.execute_reply":"2023-11-11T05:48:50.509145Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trainc = train.drop(nullind)","metadata":{"execution":{"iopub.status.busy":"2023-11-11T05:48:50.512668Z","iopub.execute_input":"2023-11-11T05:48:50.513155Z","iopub.status.idle":"2023-11-11T05:48:50.522415Z","shell.execute_reply.started":"2023-11-11T05:48:50.513116Z","shell.execute_reply":"2023-11-11T05:48:50.521024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trainpq.isnull().value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-11-11T05:48:50.524111Z","iopub.execute_input":"2023-11-11T05:48:50.525147Z","iopub.status.idle":"2023-11-11T05:49:35.559507Z","shell.execute_reply.started":"2023-11-11T05:48:50.525105Z","shell.execute_reply":"2023-11-11T05:49:35.558091Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trainpq.query(\"timestamp == '2018-12-14T16:15:00-0500'\")","metadata":{"execution":{"iopub.status.busy":"2023-11-11T05:50:49.443380Z","iopub.execute_input":"2023-11-11T05:50:49.444190Z","iopub.status.idle":"2023-11-11T05:50:56.856261Z","shell.execute_reply.started":"2023-11-11T05:50:49.444140Z","shell.execute_reply":"2023-11-11T05:50:56.854626Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trainplt1 = trainpq.query(\"series_id == '3df0da2e5966'\")\ntrainplt = trainplt1[['2018-12-15' in c for c in trainplt1.timestamp]].sort_values(by = [\"timestamp\"])\n# trainplt[\"timestamp\"] = trainplt[\"timestamp\"].to_datetime()\ntimesplt = pd.to_datetime(trainplt[\"timestamp\"])\nenmoplt = trainplt[\"enmo\"]\nanglezplt = trainplt[\"anglez\"]","metadata":{"execution":{"iopub.status.busy":"2023-11-11T06:35:20.712766Z","iopub.execute_input":"2023-11-11T06:35:20.713400Z","iopub.status.idle":"2023-11-11T06:35:27.881589Z","shell.execute_reply.started":"2023-11-11T06:35:20.713357Z","shell.execute_reply":"2023-11-11T06:35:27.879983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax1 = plt.subplots()\nax1.plot(timesplt, enmoplt, color='blue', label='enmo')\nax1.set_xlabel('Timestamp')\nax1.set_ylabel('enmo', color='blue')\nax1.tick_params(axis='y', labelcolor='blue')\nvplt = trainc.query(\"series_id == '3df0da2e5966'\")\nvplt1 = vplt[['2018-12-15' in c for c in vplt.timestamp]]\nax1.vlines(vplt1[\"timestamp\"], ymin = 0, ymax = 2, color = 'red', linestyle = '--')\nplt.show()\n#ax2 = ax1.twinx()\n#ax2.plot(timesplt, anglezplt, color='green', label='anglez')\n#ax2.set_ylabel('anglez', color='green')\n#ax2.tick_params(axis='y', labelcolor='green')","metadata":{"execution":{"iopub.status.busy":"2023-11-11T06:36:56.568780Z","iopub.execute_input":"2023-11-11T06:36:56.570526Z","iopub.status.idle":"2023-11-11T06:36:57.255608Z","shell.execute_reply.started":"2023-11-11T06:36:56.570444Z","shell.execute_reply":"2023-11-11T06:36:57.252429Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig2, ax2 = plt.subplots()\nax2.plot(timesplt, anglezplt, color='green', label='anglez')\nax2.set_xlabel('Timestamp')\nax2.set_ylabel('anglez', color='green')\nax2.tick_params(axis='y', labelcolor='green')\nax2.vlines(vplt1[\"timestamp\"], ymin = -90, ymax = 90, color = 'red', linestyle = '--')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-11-11T06:39:25.213896Z","iopub.execute_input":"2023-11-11T06:39:25.215172Z","iopub.status.idle":"2023-11-11T06:39:25.872819Z","shell.execute_reply.started":"2023-11-11T06:39:25.215104Z","shell.execute_reply":"2023-11-11T06:39:25.871029Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trainplt2 = trainplt1[[('2018-12-15' in c or '2018-12-16' in c or '2018-12-17' in c) for c in trainplt1.timestamp]].sort_values(by = [\"timestamp\"])\ntimesplt2 = pd.to_datetime(trainplt2[\"timestamp\"])\nenmoplt2 = trainplt2[\"enmo\"]\nanglezplt2 = trainplt2[\"anglez\"]","metadata":{"execution":{"iopub.status.busy":"2023-11-11T07:02:02.165559Z","iopub.execute_input":"2023-11-11T07:02:02.166128Z","iopub.status.idle":"2023-11-11T07:02:03.414066Z","shell.execute_reply.started":"2023-11-11T07:02:02.166089Z","shell.execute_reply":"2023-11-11T07:02:03.412189Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig3, ax3 = plt.subplots()\nax3.plot(timesplt2, enmoplt2, color='blue', label='enmo')\nax3.set_xlabel('Timestamp')\nax3.set_ylabel('enmo', color='blue')\nax3.tick_params(axis='y', labelcolor='blue')\nvplt2 = vplt[[('2018-12-15' in c or '2018-12-16' in c or '2018-12-17' in c) for c in vplt.timestamp]]\nax3.vlines(vplt2[\"timestamp\"], ymin = 0, ymax = 2, color = 'red', linestyle = '--')\nplt.show()\nfig4, ax4 = plt.subplots()\nax4.plot(timesplt2, anglezplt2, color='green', label='anglez')\nax4.set_xlabel('Timestamp')\nax4.set_ylabel('anglez', color='green')\nax4.tick_params(axis='y', labelcolor='green')\nax4.vlines(vplt2[\"timestamp\"], ymin = -90, ymax = 90, color = 'red', linestyle = '--')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-11-11T07:06:05.406723Z","iopub.execute_input":"2023-11-11T07:06:05.407343Z","iopub.status.idle":"2023-11-11T07:06:08.039002Z","shell.execute_reply.started":"2023-11-11T07:06:05.407299Z","shell.execute_reply":"2023-11-11T07:06:08.037332Z"},"trusted":true},"execution_count":null,"outputs":[]}]}