{"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":"# Time Series EDA","metadata":{}},{"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)\nfrom pathlib import Path\nimport matplotlib.pyplot as plt\nimport os\nimport gc\n\nDATA_DIR = Path(\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/\")","metadata":{"execution":{"iopub.status.busy":"2023-04-05T16:44:13.457363Z","iopub.execute_input":"2023-04-05T16:44:13.458106Z","iopub.status.idle":"2023-04-05T16:44:13.493720Z","shell.execute_reply.started":"2023-04-05T16:44:13.458049Z","shell.execute_reply":"2023-04-05T16:44:13.492244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"defog = pd.read_csv(DATA_DIR / \"defog_metadata.csv\")\ndaily = pd.read_csv(DATA_DIR / \"daily_metadata.csv\")\ntdcsfog = pd.read_csv(DATA_DIR / \"tdcsfog_metadata.csv\")\ndatasets = {\n    \"defog\" : defog,\n    \"daily\" : daily,\n    \"tdcsfog\" : tdcsfog,\n}","metadata":{"execution":{"iopub.status.busy":"2023-04-05T16:44:13.496385Z","iopub.execute_input":"2023-04-05T16:44:13.496915Z","iopub.status.idle":"2023-04-05T16:44:13.530371Z","shell.execute_reply.started":"2023-04-05T16:44:13.496859Z","shell.execute_reply":"2023-04-05T16:44:13.528942Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"events = pd.read_csv(DATA_DIR / \"events.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-04-05T16:44:13.531752Z","iopub.execute_input":"2023-04-05T16:44:13.532487Z","iopub.status.idle":"2023-04-05T16:44:13.546381Z","shell.execute_reply.started":"2023-04-05T16:44:13.532444Z","shell.execute_reply":"2023-04-05T16:44:13.544887Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def ith_patient(dataset_name, dataset, index):\n    if dataset_name == 'daily':\n        return pd.read_parquet(DATA_DIR / 'unlabeled' / (dataset[index].Id + \".parquet\"))\n    return pd.read_csv(DATA_DIR / 'train'/ dataset_name / (dataset[index].Id + \".csv\"))","metadata":{"execution":{"iopub.status.busy":"2023-04-05T16:47:17.190378Z","iopub.execute_input":"2023-04-05T16:47:17.190820Z","iopub.status.idle":"2023-04-05T16:47:17.198541Z","shell.execute_reply.started":"2023-04-05T16:47:17.190764Z","shell.execute_reply":"2023-04-05T16:47:17.196970Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Set `dataset_name` as one of `['daily','defog','tdcsfog']`. \nGreen lines mark beginning of an event, and red lines mark end of an event. Daily is huge so be I hardcoded a cutoff.","metadata":{}},{"cell_type":"code","source":"def display_data(dataset_name):\n    dataset = datasets[dataset_name]\n    if dataset_name == 'daily':\n        train = os.listdir(DATA_DIR / 'unlabeled')\n    else:\n        train = os.listdir(DATA_DIR / 'train' / dataset_name)\n\n    train_ids = [u.split('.')[0] for u in train]\n    if dataset_name == 'daily':\n        train_metadata = list(dataset.itertuples())\n    else:\n        train_metadata = list(filter(lambda u: u.Id in train_ids, dataset.itertuples()))\n\n    for i in range(10):\n        print(\"*****************************************************************************\")\n        if (not dataset_name == 'daily'):\n            pat_events = events[events['Id'] == train_metadata[i].Id]\n        pat = ith_patient(dataset_name, train_metadata,i)\n        gc.collect()\n        print(\"ML Standard Deviation\", pat[\"AccML\"].std())\n        print(\"ML Mean: \", pat[\"AccML\"].mean())\n        print(\"V Standard Deviation\", pat[\"AccV\"].std())\n        print(\"V Mean: \", pat[\"AccV\"].mean())\n        print(\"AP Standard Deviation\", pat[\"AccAP\"].std())\n        print(\"AP Mean: \", pat[\"AccAP\"].mean())\n\n        fig, ax = plt.subplots(figsize = (15,5))\n\n        if dataset_name == 'daily':\n            pat[[\"AccV\", \"AccAP\", \"AccML\"]][:1000000].plot(legend=True, ax=ax)# HARDCODED CUTOFF FOR DAILY\n        else:\n            pat[[\"AccV\", \"AccAP\", \"AccML\"]].plot(legend=True, ax=ax)\n\n        for l in ax.get_lines():\n            l.set_linewidth(0.3)\n\n        if not dataset_name == 'daily':\n            for e in pat_events.itertuples():\n                plt.axvline(x=e.Init*100, color=\"green\", alpha=0.5, zorder=0)\n                plt.axvline(x=e.Completion*100, color=\"red\", alpha=0.5, zorder=0)\n\n        plt.show()\n\n    ","metadata":{"execution":{"iopub.status.busy":"2023-04-05T16:47:07.810231Z","iopub.execute_input":"2023-04-05T16:47:07.810688Z","iopub.status.idle":"2023-04-05T16:47:07.825510Z","shell.execute_reply.started":"2023-04-05T16:47:07.810648Z","shell.execute_reply":"2023-04-05T16:47:07.824112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Defog Time Series","metadata":{}},{"cell_type":"code","source":"display_data(\"defog\")","metadata":{"execution":{"iopub.status.busy":"2023-04-05T16:46:01.882514Z","iopub.execute_input":"2023-04-05T16:46:01.882942Z","iopub.status.idle":"2023-04-05T16:46:20.900691Z","shell.execute_reply.started":"2023-04-05T16:46:01.882901Z","shell.execute_reply":"2023-04-05T16:46:20.899372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## TDCSFog Time Series","metadata":{}},{"cell_type":"code","source":"display_data(\"tdcsfog\")","metadata":{"execution":{"iopub.status.busy":"2023-04-05T16:47:22.003669Z","iopub.execute_input":"2023-04-05T16:47:22.004075Z","iopub.status.idle":"2023-04-05T16:47:26.230579Z","shell.execute_reply.started":"2023-04-05T16:47:22.004041Z","shell.execute_reply":"2023-04-05T16:47:26.229076Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Daily Time Series","metadata":{}},{"cell_type":"code","source":"display_data(\"daily\")","metadata":{"execution":{"iopub.status.busy":"2023-04-05T16:47:30.552729Z","iopub.execute_input":"2023-04-05T16:47:30.553254Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}