{"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":"This data set misalignment was reported by [@khahuras](https://www.kaggle.com/khahuras)\n\ndiscussion https://www.kaggle.com/competitions/tlvmc-parkinsons-freezing-gait-prediction/discussion/403470\n\nPlease upvote in the above discussion.\n\nPerhaps this misalignment will be more correctly corrected by the organizers.","metadata":{}},{"cell_type":"markdown","source":"updated[2023/04/27] fix daa4d27db4","metadata":{}},{"cell_type":"markdown","source":"updated[2023/05/05]The defog data was corrected by the organizer.\nSee discussion for details.","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport matplotlib.pyplot as plt\nimport glob\nfrom tqdm import tqdm\nimport os\nimport numpy as np","metadata":{"execution":{"iopub.status.busy":"2023-04-26T11:30:59.317666Z","iopub.execute_input":"2023-04-26T11:30:59.318334Z","iopub.status.idle":"2023-04-26T11:30:59.353501Z","shell.execute_reply.started":"2023-04-26T11:30:59.318288Z","shell.execute_reply":"2023-04-26T11:30:59.352007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_defog_sample(path, ax):\n    x = pd.read_csv(path)\n    ax.plot(x.AccV, label='AccV')\n    ax.plot(x.StartHesitation*(1/3), label='StartHe')\n    ax.plot(x.Turn*(2/3), label='Tur')\n    ax.plot(x.Walking, label='Walking')\n    ax.plot(x.Task*(-1), label='Task')\n    ax.plot(x.Valid*(-1)*(1/2), label='Valid')\n    ax.set_title(f'defog sample {os.path.basename(path)[:-4]}')\n    ax.legend()","metadata":{"execution":{"iopub.status.busy":"2023-04-26T11:59:16.307396Z","iopub.execute_input":"2023-04-26T11:59:16.307864Z","iopub.status.idle":"2023-04-26T11:59:16.317851Z","shell.execute_reply.started":"2023-04-26T11:59:16.307828Z","shell.execute_reply":"2023-04-26T11:59:16.316087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path_l = glob.glob(\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/defog/*\")\n\nn = len(path_l)\nncols = 2\nnrows = (n + ncols - 1) // ncols\n\nfig, axs = plt.subplots(nrows, ncols, figsize=(15, 5*nrows))\n\nfor i, path in tqdm(enumerate(path_l)):\n    row, col = i // ncols, i % ncols\n    plot_defog_sample(path, axs[row, col])\nfor j in range(i+1, nrows*ncols):\n    row, col = j // ncols, j % ncols\n    axs[row, col].axis('off')\n\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-04-26T10:25:32.601448Z","iopub.execute_input":"2023-04-26T10:25:32.601945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!mkdir -p train/defog","metadata":{"execution":{"iopub.status.busy":"2023-04-26T11:47:54.629837Z","iopub.execute_input":"2023-04-26T11:47:54.630601Z","iopub.status.idle":"2023-04-26T11:47:55.782832Z","shell.execute_reply.started":"2023-04-26T11:47:54.630535Z","shell.execute_reply":"2023-04-26T11:47:55.780880Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for path_ in tqdm(path_l):\n    df=pd.read_csv(path_)\n    df[\"event\"]=df[[\"StartHesitation\",\"Turn\",\"Walking\"]].max(axis=1)\n    arr=df[[\"event\",\"Valid\"]].astype(int).values\n    length = len(arr)\n    sum_event=arr[:,0].sum()\n    acc=[]\n\n    for i in range(len(arr[:,0])//2):\n        shifted_arr = np.roll(arr[:,0], -i)\n        shifted_arr[-(i + 1):] = 0\n\n        arr2=(shifted_arr*arr[:,1]).sum()\n\n        acc.append(arr2/sum_event)\n\n        ind=np.argmax(acc)\n        if acc[-1]==1:\n            break\n    df[[\"StartHesitation\",\"Turn\",\"Walking\"]]=df[[\"StartHesitation\",\"Turn\",\"Walking\"]].shift(-ind).fillna(0)\n    \n    file_name=os.path.basename(path_)\n    df.to_csv(f\"train/defog/{file_name}\",index=False)","metadata":{"execution":{"iopub.status.busy":"2023-04-26T11:58:03.276348Z","iopub.execute_input":"2023-04-26T11:58:03.276783Z","iopub.status.idle":"2023-04-26T11:59:10.734967Z","shell.execute_reply.started":"2023-04-26T11:58:03.276747Z","shell.execute_reply":"2023-04-26T11:59:10.732950Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path_l = glob.glob(\"train/defog/*\")\n\nn = len(path_l)\nncols = 2\nnrows = (n + ncols - 1) // ncols\n\nfig, axs = plt.subplots(nrows, ncols, figsize=(15, 5*nrows))\n\nfor i, path in tqdm(enumerate(path_l)):\n    row, col = i // ncols, i % ncols\n    plot_defog_sample(path, axs[row, col])\nfor j in range(i+1, nrows*ncols):\n    row, col = j // ncols, j % ncols\n    axs[row, col].axis('off')\n\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-04-26T11:59:22.686244Z","iopub.execute_input":"2023-04-26T11:59:22.686771Z","iopub.status.idle":"2023-04-26T12:00:12.483469Z","shell.execute_reply.started":"2023-04-26T11:59:22.686730Z","shell.execute_reply":"2023-04-26T12:00:12.481776Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}