{"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":"# EDA of Parkinson's FOG 🌈\n## [Objective]\n### - Load data and cultivate a better understanding　using pandas, poilars and plotly, matplotlib\n    - 0. Metadata\n    - 1. tdcsfog\n    - 2. defog\n    - 3. notype\n    - 4. test data","metadata":{}},{"cell_type":"code","source":"# =========================\n# Import libraries\n# =========================\n# default\nimport gc, os, glob, random\nfrom os import path\nfrom pathlib import Path\n# make data\nimport polars as pl\nimport pandas as pd\npd.set_option('display.max_columns', None); # pd.set_option('display.max_rows', None)\nimport numpy as np\nfrom tqdm.auto import tqdm\nimport ydata_profiling as pdp","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-06-08T23:32:13.622200Z","iopub.execute_input":"2023-06-08T23:32:13.622749Z","iopub.status.idle":"2023-06-08T23:32:18.042676Z","shell.execute_reply.started":"2023-06-08T23:32:13.622700Z","shell.execute_reply":"2023-06-08T23:32:18.041127Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def show_df(df, num=3, tail=True):\n    print(df.shape)\n    display(df.head(num))\n    if tail:\n        display(df.tail(num))","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:32:18.045011Z","iopub.execute_input":"2023-06-08T23:32:18.046055Z","iopub.status.idle":"2023-06-08T23:32:18.052750Z","shell.execute_reply.started":"2023-06-08T23:32:18.046014Z","shell.execute_reply":"2023-06-08T23:32:18.051271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"defog_path = glob.glob(\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/defog/*.csv\")\ntdcsfog_path = glob.glob(\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/tdcsfog/*.csv\")\nnotype_path = glob.glob(\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/notype/*.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:32:18.054591Z","iopub.execute_input":"2023-06-08T23:32:18.055041Z","iopub.status.idle":"2023-06-08T23:32:18.183216Z","shell.execute_reply.started":"2023-06-08T23:32:18.055004Z","shell.execute_reply":"2023-06-08T23:32:18.182086Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"-\"*80);print(\"Data num of each_path\");print(\"-\"*80)\nprint(f\"defog_path: {len(defog_path)}\")\nprint(f\"tdcsfog_path: {len(tdcsfog_path)}\")\nprint(f\"notype_path: {len(notype_path)}\")\nprint(\"-\"*80)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:32:18.186273Z","iopub.execute_input":"2023-06-08T23:32:18.186640Z","iopub.status.idle":"2023-06-08T23:32:18.193642Z","shell.execute_reply.started":"2023-06-08T23:32:18.186610Z","shell.execute_reply":"2023-06-08T23:32:18.192446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 0. Metadata","metadata":{}},{"cell_type":"code","source":"# =========================================\n# Subjects -infomation about patients-\n# =========================================\nsubjects = pd.read_csv(\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/subjects.csv\")\nsubjects.loc[subjects['Subject'] == 'fe5d84', 'Sex'] = 'F'\nprint(\"-\"*80);print(\"Subjects -infomation about patients-\");print(\"-\"*80);show_df(subjects)\nprint(\"YearsSinceDx: Years since Parkinson's diagnosis.\")\nprint(\"UPDRSIII_on/off: Unified Parkinson's Disease Rating Scale score during on/off medication respectively..\")\nprint(\"NFOGQ: Self-report FoG questionnaire score. See: https://pubmed.ncbi.nlm.nih.gov/19660949/.\")\nprint()\n# ==============================================================================\n# Tasks - Task metadata for series in the defog dataset.(not tdcsfog & daily)-\n# ==============================================================================\ntasks    = pd.read_csv(\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/tasks.csv\")\ntasks['Duration'] = tasks['End'] - tasks['Begin']\nprint(\"-\"*80);print(\"Tasks - Task metadata for series in the defog dataset.(not tdcsfog & daily)-\");print(\"-\"*80);show_df(tasks)\n\n# ===========================\n# Events (for only notype)\n# ===========================\nevents   = pd.read_csv(\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/events.csv\")\nprint(\"-\"*80);print(\"Events -for  each FoG event(not for notype)-\");print(\"-\"*80);show_df(events)\nprint(\"Init      : Time (s) the event began.\")\nprint(\"Completion: Time (s) the event ended.\")\nprint(\"Type      : Whether StartHesitation, Turn, or Walking.\")\nprint(\"Kinetic   : Whether the event was kinetic (1) and involved movement, or akinetic (0) and static.\")","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:32:18.195408Z","iopub.execute_input":"2023-06-08T23:32:18.195814Z","iopub.status.idle":"2023-06-08T23:32:18.344242Z","shell.execute_reply.started":"2023-06-08T23:32:18.195782Z","shell.execute_reply":"2023-06-08T23:32:18.342838Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ====================\n# Kmeans: subjects\n# ====================\nfrom sklearn import cluster, metrics\n\nsubjects['Sex'] = subjects['Sex'].factorize()[0] # to 0-1\nsubjects = subjects.fillna(0).groupby('Subject').median()\nsubjects['s_group'] = cluster.KMeans(\n    n_clusters = 8, \n    random_state = 42\n).fit_predict(subjects[subjects.columns[1:]])\nnew_names = {\n    'Visit':'s_visit',\n    'Age':'s_age',\n    'YearsSinceDx':'s_years',\n    'UPDRSIII_On':'s_on',\n    'UPDRSIII_Off':'s_off',\n    'NFOGQ':'s_NFOGQ', \n    'Sex': 's_sex'\n}\nsubjects = subjects.rename(columns = new_names)\nprint(\"-\"*80); print(\"subjects\"); print(\"-\"*80); show_df(subjects)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:32:18.345894Z","iopub.execute_input":"2023-06-08T23:32:18.346228Z","iopub.status.idle":"2023-06-08T23:32:19.156261Z","shell.execute_reply.started":"2023-06-08T23:32:18.346199Z","shell.execute_reply":"2023-06-08T23:32:19.155129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ================================\n# show distribution of subjects\n# ================================\nimport matplotlib.pyplot as plt\nprint(\"-\"*80); print(\"distribution of subjects\"); print(\"-\"*80);\nfig, axs = plt.subplots(nrows=2, ncols=4, figsize=(16, 6))\ncols = list(subjects.columns)\n\nfor i, col in enumerate(cols):\n    axs[int(i//4), int(i%4)].hist(subjects[col], bins=20, color='b', alpha=0.5)\n    axs[int(i//4), int(i%4)].set_title(col)\n    axs[int(i//4), int(i%4)].set_ylabel('Frequency')\nplt.tight_layout()\nplt.show()\n\nprint(\"-\"*80); \nprint(\"Visit  : 0/1/2\");\nprint(\"Age    : almost over 40.\");\nprint(\"Sex    : Male(70%) > female(30%)\");\nprint(\"Years  : almost under 20years\");\nprint(\"On/Off : Medication is seems to be effective.\");\nprint(\"NFOGQ  : Some data is unlabeled.\"); \nprint(\"-\"*80);","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:32:19.157962Z","iopub.execute_input":"2023-06-08T23:32:19.158646Z","iopub.status.idle":"2023-06-08T23:32:20.954690Z","shell.execute_reply.started":"2023-06-08T23:32:19.158613Z","shell.execute_reply":"2023-06-08T23:32:20.953480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ===============\n# tasks\n# ===============\ntasks_kmeans = pd.pivot_table(\n    tasks, \n    values=['Duration'], \n    index=['Id'], \n    columns=['Task'], \n    aggfunc='sum', \n    fill_value=0\n)\ntasks_kmeans.columns = [c[1] for c in tasks_kmeans.columns]\ntasks_kmeans = tasks_kmeans.reset_index()\ntasks_kmeans['t_group'] = cluster.KMeans(\n    n_clusters = 8,\n    random_state = 42\n).fit_predict(tasks_kmeans[tasks_kmeans.columns[1:]])\nprint(\"-\"*80); print(\"Tasks - Task metadata for series in the defog dataset.(not tdcsfog & daily)-\"); print(\"-\"*80); show_df(tasks_kmeans)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:32:20.956211Z","iopub.execute_input":"2023-06-08T23:32:20.956572Z","iopub.status.idle":"2023-06-08T23:32:21.112272Z","shell.execute_reply.started":"2023-06-08T23:32:20.956539Z","shell.execute_reply":"2023-06-08T23:32:21.111053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ===========================\n# Tasks -begin time-\n# ===========================\ntask_begin = pd.pivot_table(\n    tasks, \n    values=['Begin'], \n    index=['Id'], \n    columns=['Task'], \n    aggfunc='sum', \n    fill_value=0\n)\ntask_begin","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:32:21.113641Z","iopub.execute_input":"2023-06-08T23:32:21.114026Z","iopub.status.idle":"2023-06-08T23:32:21.202207Z","shell.execute_reply.started":"2023-06-08T23:32:21.113995Z","shell.execute_reply":"2023-06-08T23:32:21.200912Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# =====================================\n# tscsfog_metadata (test at lab)\n# =====================================\ntdcsfog_metadata=pd.read_csv('../input/tlvmc-parkinsons-freezing-gait-prediction/tdcsfog_metadata.csv')\nprint(\"-\"*80);print(\"tdcsfog_metadata -test at labratory-\");print(\"-\"*80);show_df(tdcsfog_metadata)\nprint(f\"Visit: {tdcsfog_metadata.Visit.unique()}\")\nprint(f\"Test: {tdcsfog_metadata.Test.unique()}, 1 <--easy ** hard--> 3\")\nprint(f\"Medication:{tdcsfog_metadata.Medication.unique()}, on/off: add_medicine/or_not\")\nprint()\n# ===============================\n# defog_metadata (test at home)\n# ===============================\ndefog_metadata=pd.read_csv('../input/tlvmc-parkinsons-freezing-gait-prediction/defog_metadata.csv')\nprint(\"-\"*80);print(\"defog_metadata -test at home-\");print(\"-\"*80);show_df(defog_metadata)\nprint(f\"Visit: {defog_metadata.Visit.unique()}\")\nprint(f\"Medication:{defog_metadata.Medication.unique()}\")\nprint()\n# =================================================\n# daily_metadata (24h continuous record at home)\n# =================================================\ndaily_metadata=pd.read_csv('../input/tlvmc-parkinsons-freezing-gait-prediction/daily_metadata.csv')\nprint(\"-\"*80);print(\"daily_metadata -24h continuous record at home-\");print(\"-\"*80);show_df(daily_metadata)\nprint(f\"Visit: {daily_metadata.Visit.unique()}\")\n","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:32:21.206842Z","iopub.execute_input":"2023-06-08T23:32:21.207257Z","iopub.status.idle":"2023-06-08T23:32:21.287662Z","shell.execute_reply.started":"2023-06-08T23:32:21.207221Z","shell.execute_reply":"2023-06-08T23:32:21.286552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ====================\n# Concat metadata\n# ====================\ntdcsfog_metadata['Module']='tdcsfog'\ndefog_metadata['Module']='defog'\n# daily_metadata['Module']='daily'\nfull_metadata=pd.concat([tdcsfog_metadata,defog_metadata])\n# metadata\nprint(\"-\"*80); print(\"full_metadata\"); print(\"-\"*80); show_df(full_metadata)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:32:21.289023Z","iopub.execute_input":"2023-06-08T23:32:21.289380Z","iopub.status.idle":"2023-06-08T23:32:21.321158Z","shell.execute_reply.started":"2023-06-08T23:32:21.289350Z","shell.execute_reply":"2023-06-08T23:32:21.319814Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 1. tdcsfog -laboratory test-","metadata":{}},{"cell_type":"code","source":"# ===================================\n# Conct defog metadata & subjects\n# ===================================\ntdcsfog_metadata_w_subjects = tdcsfog_metadata.merge(subjects, how='left', on='Subject').copy()\nfeatures = tdcsfog_metadata_w_subjects.columns\ntdcsfog_metadata_w_subjects['Medication'] = tdcsfog_metadata_w_subjects['Medication'].factorize()[0]\nprint(\"-\"*80); print(\"tdcsfog_metadata_with_subjects_infomation\"); print(\"-\"*80); show_df(tdcsfog_metadata_w_subjects)\nprint(f\"Unique subjects number (tdcsfog_metadata)            : {len(tdcsfog_metadata.Subject.unique())}\")\nprint(f\"Unique subjects number (tdcsfog_metadata_w_subjects) : {len(tdcsfog_metadata_w_subjects.Subject.unique())}\")","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:32:21.322582Z","iopub.execute_input":"2023-06-08T23:32:21.322975Z","iopub.status.idle":"2023-06-08T23:32:21.381021Z","shell.execute_reply.started":"2023-06-08T23:32:21.322929Z","shell.execute_reply":"2023-06-08T23:32:21.379059Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# =====================================\n# load data & concat\n# =====================================\ndf_list = []\nfor idx, path in tqdm(enumerate(tdcsfog_path)):\n    df = pl.read_csv(path)\n    filename = os.path.basename(path).split(\".cs\")[0]\n    tmp = pl.DataFrame(\n        {\n            \"idx\": [idx]*len(df),\n            \"ID\": [filename]*len(df),\n            \"len_df\": len(df),\n        }\n    )\n    df = pl.concat([df, tmp], how=\"horizontal\")\n    df_list.append(df)\n    \ndf_tdcsfog = pl.concat(df_list)\nshow_df(df_tdcsfog)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:32:21.382860Z","iopub.execute_input":"2023-06-08T23:32:21.383300Z","iopub.status.idle":"2023-06-08T23:32:39.140873Z","shell.execute_reply.started":"2023-06-08T23:32:21.383260Z","shell.execute_reply":"2023-06-08T23:32:39.139599Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# =====================================\n# flag count by ID\n# =====================================\ndf_tdcsfog_sum = df_tdcsfog.select(\"ID\", \"StartHesitation\", \"Turn\", \"Walking\").groupby(\"ID\").sum()\ndf_tdcsfog_sum = df_tdcsfog_sum.join(df_tdcsfog.select(\"ID\", \"len_df\").groupby(\"ID\").mean(), on=\"ID\")\nshow_df(df_tdcsfog_sum)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:32:39.142427Z","iopub.execute_input":"2023-06-08T23:32:39.143305Z","iopub.status.idle":"2023-06-08T23:32:39.552486Z","shell.execute_reply.started":"2023-06-08T23:32:39.143272Z","shell.execute_reply":"2023-06-08T23:32:39.551643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_tdcsfog_sum = df_tdcsfog_sum.to_pandas()\ndf_tdcsfog_sum[\"Total\"] = df_tdcsfog_sum[\"StartHesitation\"] + df_tdcsfog_sum[\"Turn\"] + df_tdcsfog_sum[\"Walking\"]\n\n# =====================================\n# Best3 -StartHesitation is count-\n# =====================================\nprint(\"-\"*80);print(\"StartHesitation\");print(\"-\"*80)\ndf_tdcsfog_sum.sort_values(\"StartHesitation\", ascending=False,inplace=True)\nstarthesitation_ids = df_tdcsfog_sum[\"ID\"][0:3]\nnot_starthesitation_ids = df_tdcsfog_sum[\"ID\"][-3:]\nprint(*starthesitation_ids)\nprint(*not_starthesitation_ids)\nshow_df(df_tdcsfog_sum, 5, True)\n# =====================================\n# Best3 -Turn is count-\n# =====================================\nprint(\"-\"*80);print(\"Turn\");print(\"-\"*80)\ndf_tdcsfog_sum.sort_values(\"Turn\", ascending=False,inplace=True)\nturn_ids = df_tdcsfog_sum[\"ID\"][0:3]\nnot_turn_ids = df_tdcsfog_sum[\"ID\"][-3:]\nprint(*turn_ids)\nprint(*not_turn_ids)\nshow_df(df_tdcsfog_sum, 5, True)\n# =====================================\n# Best3 -Walking is count-\n# =====================================\nprint(\"-\"*80);print(\"Walking\");print(\"-\"*80)\ndf_tdcsfog_sum.sort_values(\"Walking\", ascending=False,inplace=True)\nwalking_ids = df_tdcsfog_sum[\"ID\"][0:3]\nnot_walking_ids = df_tdcsfog_sum[\"ID\"][-3:]\nprint(*walking_ids)\nprint(*not_walking_ids)\nshow_df(df_tdcsfog_sum, 5, True)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:32:39.554008Z","iopub.execute_input":"2023-06-08T23:32:39.554340Z","iopub.status.idle":"2023-06-08T23:32:39.663324Z","shell.execute_reply.started":"2023-06-08T23:32:39.554311Z","shell.execute_reply":"2023-06-08T23:32:39.662142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# =========================\n# plotly: 3D-plot\n# =========================\nimport plotly.express as px\nfig = px.scatter_3d(df_tdcsfog_sum, x='StartHesitation', y='Turn', z='Walking',\n                    symbol='ID')\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:32:39.665122Z","iopub.execute_input":"2023-06-08T23:32:39.665474Z","iopub.status.idle":"2023-06-08T23:32:45.963808Z","shell.execute_reply.started":"2023-06-08T23:32:39.665445Z","shell.execute_reply":"2023-06-08T23:32:45.962654Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def show_tdcsfog(df):\n    # Subplot: 1×4\n    fig, axs = plt.subplots(4, 1, figsize=(30, 10))\n\n    # Subplot-1: AccV\n    axs[0].plot(df.Time, df.AccV)\n    axs[0].set_ylabel('AccV[g] -Vertical-')\n    axs[0].set_ylim([-2.5,0])\n\n    # Subplot-2: AccML\n    axs[1].plot(df.Time, df.AccML)\n    axs[1].set_ylabel('AccML[g] -RightLeft-')\n    axs[1].set_ylim([-2,2])\n\n    # Subplot-3: AccAP\n    axs[2].plot(df.Time, df.AccAP)\n    axs[2].set_ylabel('AccAP[g] -ForwardBack-')\n    axs[2].set_ylim([-1,2])\n\n    # Subplot-4: Freazing Flags\n    axs[3].plot(df.Time, df.StartHesitation, label='StartHesitation')\n    axs[3].plot(df.Time, df.Turn, label='Turn')\n    axs[3].plot(df.Time, df.Walking, label='Walking')\n    axs[3].set_ylabel('freazing_flag')\n    axs[3].set_xlabel('time[sec] -tdcsfog is 128Hz sampling-')\n    axs[3].legend()\n\n    # show graph\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:32:45.965868Z","iopub.execute_input":"2023-06-08T23:32:45.966310Z","iopub.status.idle":"2023-06-08T23:32:45.984593Z","shell.execute_reply.started":"2023-06-08T23:32:45.966271Z","shell.execute_reply":"2023-06-08T23:32:45.983298Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ====================================\n# Line-plot: Start_Hesitation\n# ====================================\nfor _id in starthesitation_ids:    \n    print(\"-\"*80);print(\"StartHesitation\");print(\"-\"*80)\n    display(tdcsfog_metadata_w_subjects[tdcsfog_metadata_w_subjects[\"Id\"] == _id])\n    display(events[events[\"Id\"] == _id])\n    tmp = pd.read_csv(f\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/tdcsfog/{_id}.csv\")\n    tmp[\"Time\"] = tmp.index / 128\n    tmp[\"AccV\"] /= 9.8\n    tmp[\"AccML\"] /= 9.8\n    tmp[\"AccAP\"] /= 9.8\n    tmp[\"StartHesitation\"] *= 0.8\n    tmp[\"Turn\"] *= 1.0\n    tmp[\"Walking\"] *= 1.2\n    print(f\"path: {_id} {tmp.shape}\")\n    show_tdcsfog(tmp)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:32:45.987039Z","iopub.execute_input":"2023-06-08T23:32:45.987514Z","iopub.status.idle":"2023-06-08T23:32:49.641647Z","shell.execute_reply.started":"2023-06-08T23:32:45.987460Z","shell.execute_reply":"2023-06-08T23:32:49.640428Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ====================================\n# Line-plot: not Start_Hesitation\n# ====================================\nfor _id in not_starthesitation_ids:    \n    print(\"-\"*80);print(\"NoT_StartHesitation\");print(\"-\"*80)\n    display(tdcsfog_metadata_w_subjects[tdcsfog_metadata_w_subjects[\"Id\"] == _id])\n    display(events[events[\"Id\"] == _id])\n    tmp = pd.read_csv(f\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/tdcsfog/{_id}.csv\")\n    tmp[\"Time\"] = tmp.index / 128\n    tmp[\"AccV\"] /= 9.8\n    tmp[\"AccML\"] /= 9.8\n    tmp[\"AccAP\"] /= 9.8\n    tmp[\"StartHesitation\"] *= 0.8\n    tmp[\"Turn\"] *= 1.0\n    tmp[\"Walking\"] *= 1.2\n    print(f\"path: {_id} {tmp.shape}\")\n    show_tdcsfog(tmp)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:32:49.643022Z","iopub.execute_input":"2023-06-08T23:32:49.643383Z","iopub.status.idle":"2023-06-08T23:32:52.190540Z","shell.execute_reply.started":"2023-06-08T23:32:49.643354Z","shell.execute_reply":"2023-06-08T23:32:52.189000Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ====================================\n# Line-plot: Turn\n# ====================================\nfor _id in turn_ids:\n    print(\"-\"*80);print(\"Turn\");print(\"-\"*80)\n    display(tdcsfog_metadata_w_subjects[tdcsfog_metadata_w_subjects[\"Id\"] == _id])\n    display(events[events[\"Id\"] == _id])\n    tmp = pd.read_csv(f\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/tdcsfog/{_id}.csv\")\n    tmp[\"Time\"] = tmp.index / 128\n    tmp[\"AccV\"] /= 9.8\n    tmp[\"AccML\"] /= 9.8\n    tmp[\"AccAP\"] /= 9.8\n    tmp[\"StartHesitation\"] *= 0.8\n    tmp[\"Turn\"] *= 1.0\n    tmp[\"Walking\"] *= 1.2\n    print(f\"path: {_id} {tmp.shape}\")\n    show_tdcsfog(tmp)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:32:52.192952Z","iopub.execute_input":"2023-06-08T23:32:52.193433Z","iopub.status.idle":"2023-06-08T23:32:57.983294Z","shell.execute_reply.started":"2023-06-08T23:32:52.193397Z","shell.execute_reply":"2023-06-08T23:32:57.982131Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ====================================\n# Line-plot: not Turn\n# ====================================\nfor _id in not_turn_ids:\n    print(\"-\"*80);print(\"Not Turn\");print(\"-\"*80)\n    display(tdcsfog_metadata_w_subjects[tdcsfog_metadata_w_subjects[\"Id\"] == _id])\n    display(events[events[\"Id\"] == _id])\n    tmp = pd.read_csv(f\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/tdcsfog/{_id}.csv\")\n    tmp[\"Time\"] = tmp.index / 128\n    tmp[\"AccV\"] /= 9.8\n    tmp[\"AccML\"] /= 9.8\n    tmp[\"AccAP\"] /= 9.8\n    tmp[\"StartHesitation\"] *= 0.8\n    tmp[\"Turn\"] *= 1.0\n    tmp[\"Walking\"] *= 1.2\n    print(f\"path: {_id} {tmp.shape}\")\n    show_tdcsfog(tmp)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:32:57.984870Z","iopub.execute_input":"2023-06-08T23:32:57.985249Z","iopub.status.idle":"2023-06-08T23:33:00.870071Z","shell.execute_reply.started":"2023-06-08T23:32:57.985217Z","shell.execute_reply":"2023-06-08T23:33:00.868763Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ====================================\n# Line-plot: Walking\n# ====================================\nfor _id in walking_ids:\n    print(\"-\"*80);print(\"Walking\");print(\"-\"*80)\n    display(tdcsfog_metadata_w_subjects[tdcsfog_metadata_w_subjects[\"Id\"] == _id])\n    display(events[events[\"Id\"] == _id])\n    tmp = pd.read_csv(f\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/tdcsfog/{_id}.csv\")\n    tmp[\"Time\"] = tmp.index / 128\n    tmp[\"AccV\"] /= 9.8\n    tmp[\"AccML\"] /= 9.8\n    tmp[\"AccAP\"] /= 9.8\n    tmp[\"StartHesitation\"] *= 0.8\n    tmp[\"Turn\"] *= 1.0\n    tmp[\"Walking\"] *= 1.2\n    print(f\"path: {_id} {tmp.shape}\")\n    show_tdcsfog(tmp)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:33:00.871376Z","iopub.execute_input":"2023-06-08T23:33:00.871718Z","iopub.status.idle":"2023-06-08T23:33:06.130678Z","shell.execute_reply.started":"2023-06-08T23:33:00.871688Z","shell.execute_reply":"2023-06-08T23:33:06.129119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ====================================\n# Line-plot: not Walking\n# ====================================\nfor _id in not_walking_ids:\n    print(\"-\"*80);print(\"Not Walking\");print(\"-\"*80)\n    display(tdcsfog_metadata_w_subjects[tdcsfog_metadata_w_subjects[\"Id\"] == _id])\n    display(events[events[\"Id\"] == _id])\n    tmp = pd.read_csv(f\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/tdcsfog/{_id}.csv\")\n    tmp[\"Time\"] = tmp.index / 128\n    tmp[\"AccV\"] /= 9.8\n    tmp[\"AccML\"] /= 9.8\n    tmp[\"AccAP\"] /= 9.8\n    tmp[\"StartHesitation\"] *= 0.8\n    tmp[\"Turn\"] *= 1.0\n    tmp[\"Walking\"] *= 1.2\n    print(f\"path: {_id} {tmp.shape}\")\n    show_tdcsfog(tmp)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:33:06.132548Z","iopub.execute_input":"2023-06-08T23:33:06.132943Z","iopub.status.idle":"2023-06-08T23:33:08.591446Z","shell.execute_reply.started":"2023-06-08T23:33:06.132910Z","shell.execute_reply":"2023-06-08T23:33:08.590484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 1. defog - test at home-","metadata":{}},{"cell_type":"code","source":"# ===================================\n# Conct defog metadata & subjects\n# ===================================\ndefog_metadata_w_subjects = defog_metadata.merge(subjects, how='left', on='Subject').copy()\nfeatures = defog_metadata_w_subjects.columns\ndefog_metadata_w_subjects['Medication'] = defog_metadata_w_subjects['Medication'].factorize()[0]\nprint(\"-\"*80); print(\"defog_metadata_with_subjects_infomation\"); print(\"-\"*80); show_df(defog_metadata_w_subjects)\nprint(f\"Unique subjects number (defog_metadata)            : {len(defog_metadata.Subject.unique())}\")\nprint(f\"Unique subjects number (defog_metadata_w_subjects) : {len(defog_metadata_w_subjects.Subject.unique())}\")","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:33:08.592871Z","iopub.execute_input":"2023-06-08T23:33:08.593212Z","iopub.status.idle":"2023-06-08T23:33:08.640399Z","shell.execute_reply.started":"2023-06-08T23:33:08.593175Z","shell.execute_reply":"2023-06-08T23:33:08.639268Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_list = []\nfor idx, path in tqdm(enumerate(defog_path)):\n    df = pl.read_csv(path)\n    filename = os.path.basename(path).split(\".cs\")[0]\n    tmp = pl.DataFrame(\n        {\n            \"idx\": [idx]*len(df),\n            \"ID\": [filename]*len(df),\n            \"len_df\": len(df),\n        }\n    )\n    df = pl.concat([df, tmp], how=\"horizontal\")\n    df_list.append(df)\n    \ndf_defog = pl.concat(df_list)\nshow_df(df_defog)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:33:08.642398Z","iopub.execute_input":"2023-06-08T23:33:08.642784Z","iopub.status.idle":"2023-06-08T23:33:20.939391Z","shell.execute_reply.started":"2023-06-08T23:33:08.642742Z","shell.execute_reply":"2023-06-08T23:33:20.938400Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_defog_sum = df_defog.select(\"ID\", \"StartHesitation\", \"Turn\", \"Walking\").groupby(\"ID\").sum()\ndf_defog_sum = df_defog_sum.join(df_defog.select(\"ID\", \"len_df\").groupby(\"ID\").mean(), on=\"ID\")\nshow_df(df_defog_sum)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:33:20.940745Z","iopub.execute_input":"2023-06-08T23:33:20.941376Z","iopub.status.idle":"2023-06-08T23:33:21.543776Z","shell.execute_reply.started":"2023-06-08T23:33:20.941341Z","shell.execute_reply":"2023-06-08T23:33:21.543008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_defog_sum = df_defog_sum.to_pandas()\ndf_defog_sum[\"Total\"] = df_defog_sum[\"StartHesitation\"] + df_defog_sum[\"Turn\"] + df_defog_sum[\"Walking\"]\n\n# =====================================\n# Best3 -StartHesitation is count-\n# =====================================\nprint(\"-\"*80);print(\"StartHesitation\");print(\"-\"*80)\ndf_defog_sum.sort_values(\"StartHesitation\", ascending=False,inplace=True)\nstarthesitation_ids = df_defog_sum[\"ID\"][0:5]\nnot_starthesitation_ids = df_defog_sum[\"ID\"][-3:]\nprint(*starthesitation_ids)\nprint(*not_starthesitation_ids)\nshow_df(df_defog_sum, 5, True)\n# =====================================\n# Best3 -Turn is count-\n# =====================================\nprint(\"-\"*80);print(\"Turn\");print(\"-\"*80)\ndf_defog_sum.sort_values(\"Turn\", ascending=False,inplace=True)\nturn_ids = df_defog_sum[\"ID\"][0:5]\nnot_turn_ids = df_defog_sum[\"ID\"][-3:]\nprint(*turn_ids)\nprint(*not_turn_ids)\nshow_df(df_defog_sum, 5, True)\n# =====================================\n# Best3 -Walking is count-\n# =====================================\nprint(\"-\"*80);print(\"Walking\");print(\"-\"*80)\ndf_defog_sum.sort_values(\"Walking\", ascending=False,inplace=True)\nwalking_ids = df_defog_sum[\"ID\"][0:3]\nnot_walking_ids = df_defog_sum[\"ID\"][-3:]\nprint(*walking_ids)\nprint(*not_walking_ids)\nshow_df(df_defog_sum, 5, True)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:33:21.544886Z","iopub.execute_input":"2023-06-08T23:33:21.545596Z","iopub.status.idle":"2023-06-08T23:33:21.621637Z","shell.execute_reply.started":"2023-06-08T23:33:21.545565Z","shell.execute_reply":"2023-06-08T23:33:21.620458Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# =========================\n# plotly: 3D-plot\n# =========================\nimport plotly.express as px\nfig = px.scatter_3d(df_defog_sum, x='StartHesitation', y='Turn', z='Walking',\n                    symbol='ID')\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:33:21.630499Z","iopub.execute_input":"2023-06-08T23:33:21.630929Z","iopub.status.idle":"2023-06-08T23:33:22.063685Z","shell.execute_reply.started":"2023-06-08T23:33:21.630896Z","shell.execute_reply":"2023-06-08T23:33:22.062591Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def show_defog(df):\n    # Subplot: 1×4\n    fig, axs = plt.subplots(4, 1, figsize=(30, 10))\n\n    # Subplot-1: AccV\n    axs[0].plot(df.Time, df.AccV)\n    axs[0].set_ylabel('AccV[g] -Vertical-')\n    axs[0].set_ylim([-2.5,0])\n    axs[0].ticklabel_format(style='plain')\n\n    # Subplot-2: AccML\n    axs[1].plot(df.Time, df.AccML)\n    axs[1].set_ylabel('AccML[g] -RightLeft-')\n    axs[1].set_ylim([-2,2])\n    axs[1].ticklabel_format(style='plain')\n\n    # Subplot-3: AccAP\n    axs[2].plot(df.Time, df.AccAP)\n    axs[2].set_ylabel('AccAP[g] -ForwardBack-')\n    axs[2].set_ylim([-1,2])\n    axs[2].ticklabel_format(style='plain')\n\n    # Subplot-4: Freazing Flags\n    axs[3].plot(df.Time, df.StartHesitation, label='StartHesitation')\n    axs[3].plot(df.Time, df.Turn, label='Turn')\n    axs[3].plot(df.Time, df.Walking, label='Walking')\n    axs[3].plot(df.Time, df.Valid, label='Valid')\n    axs[3].plot(df.Time, df.Task, label='Task')\n    axs[3].set_ylabel('freazing_flag')\n    axs[3].set_xlabel('time[sec] -defog is 100Hz sampling-')\n    axs[3].legend()\n    axs[3].ticklabel_format(style='plain')\n    # show graph\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:33:22.065525Z","iopub.execute_input":"2023-06-08T23:33:22.066526Z","iopub.status.idle":"2023-06-08T23:33:22.079083Z","shell.execute_reply.started":"2023-06-08T23:33:22.066491Z","shell.execute_reply":"2023-06-08T23:33:22.077744Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ====================================\n# Line-plot: StartHesitaion\n# ====================================\nfor _id in starthesitation_ids:\n    print(\"-\"*80);print(\"StartHesitation\");print(\"-\"*80)\n    display(defog_metadata_w_subjects[defog_metadata_w_subjects[\"Id\"] == _id])\n    display(tasks[tasks[\"Id\"] == _id])\n    display(events[events[\"Id\"] == _id])\n    tmp = pd.read_csv(f\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/defog/{_id}.csv\")\n    tmp[\"Time\"] = tmp.index / 100\n    tmp[\"StartHesitation\"] *= 0.8\n    tmp[\"Turn\"] *= 1.0\n    tmp[\"Walking\"] *= 1.2\n    tmp[\"Valid\"] *= -0.8\n    tmp[\"Task\"] *= -1.0\n    print(f\"path: {_id} {tmp.shape}\")\n    show_defog(tmp)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:33:22.080720Z","iopub.execute_input":"2023-06-08T23:33:22.081099Z","iopub.status.idle":"2023-06-08T23:33:43.102235Z","shell.execute_reply.started":"2023-06-08T23:33:22.081068Z","shell.execute_reply":"2023-06-08T23:33:43.101066Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ====================================\n# Line-plot: Not_StartHesitaion\n# ====================================\nfor _id in not_starthesitation_ids:\n    print(\"-\"*80);print(\"Not_StartHesitation\");print(\"-\"*80)\n    display(defog_metadata_w_subjects[defog_metadata_w_subjects[\"Id\"] == _id])\n    display(tasks[tasks[\"Id\"] == _id])\n    display(events[events[\"Id\"] == _id])\n    tmp = pd.read_csv(f\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/defog/{_id}.csv\")\n    tmp[\"Time\"] = tmp.index / 100\n    tmp[\"StartHesitation\"] *= 0.8\n    tmp[\"Turn\"] *= 1.0\n    tmp[\"Walking\"] *= 1.2\n    tmp[\"Valid\"] *= -0.8\n    tmp[\"Task\"] *= -1.0\n    print(f\"path: {_id} {tmp.shape}\")\n    show_defog(tmp)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:33:43.103651Z","iopub.execute_input":"2023-06-08T23:33:43.104027Z","iopub.status.idle":"2023-06-08T23:33:56.137662Z","shell.execute_reply.started":"2023-06-08T23:33:43.103997Z","shell.execute_reply":"2023-06-08T23:33:56.136463Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ====================================\n# Line-plot: Turn\n# ====================================\nfor _id in turn_ids:\n    print(\"-\"*80);print(\"Turn\");print(\"-\"*80)\n    display(defog_metadata_w_subjects[defog_metadata_w_subjects[\"Id\"] == _id])\n    display(tasks[tasks[\"Id\"] == _id])\n    display(events[events[\"Id\"] == _id])\n    tmp = pd.read_csv(f\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/defog/{_id}.csv\")\n    tmp[\"Time\"] = tmp.index / 100\n    tmp[\"StartHesitation\"] *= 0.8\n    tmp[\"Turn\"] *= 1.0\n    tmp[\"Walking\"] *= 1.2\n    tmp[\"Valid\"] *= -0.8\n    tmp[\"Task\"] *= -1.0\n    print(f\"path: {_id}\")\n    show_defog(tmp)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:33:56.139161Z","iopub.execute_input":"2023-06-08T23:33:56.139988Z","iopub.status.idle":"2023-06-08T23:34:23.988260Z","shell.execute_reply.started":"2023-06-08T23:33:56.139952Z","shell.execute_reply":"2023-06-08T23:34:23.986900Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ====================================\n# Line-plot: not_Turn\n# ====================================\nfor _id in not_turn_ids:\n    print(\"-\"*80);print(\"Not_Turn\");print(\"-\"*80)\n    display(defog_metadata_w_subjects[defog_metadata_w_subjects[\"Id\"] == _id])\n    display(tasks[tasks[\"Id\"] == _id])\n    display(events[events[\"Id\"] == _id])\n    tmp = pd.read_csv(f\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/defog/{_id}.csv\")\n    tmp[\"Time\"] = tmp.index / 100\n    tmp[\"StartHesitation\"] *= 0.8\n    tmp[\"Turn\"] *= 1.0\n    tmp[\"Walking\"] *= 1.2\n    tmp[\"Valid\"] *= -0.8\n    tmp[\"Task\"] *= -1.0\n    print(f\"path: {_id}\")\n    show_defog(tmp)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:34:23.989986Z","iopub.execute_input":"2023-06-08T23:34:23.991064Z","iopub.status.idle":"2023-06-08T23:34:38.955256Z","shell.execute_reply.started":"2023-06-08T23:34:23.991023Z","shell.execute_reply":"2023-06-08T23:34:38.953922Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ====================================\n# Line-plot: Walking\n# ====================================\nfor _id in walking_ids:\n    print(\"-\"*80);print(\"Walking\");print(\"-\"*80)\n    display(defog_metadata_w_subjects[defog_metadata_w_subjects[\"Id\"] == _id])\n    display(tasks[tasks[\"Id\"] == _id])\n    display(events[events[\"Id\"] == _id])\n    tmp = pd.read_csv(f\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/defog/{_id}.csv\")\n    tmp[\"Time\"] = tmp.index / 100\n    tmp[\"StartHesitation\"] *= 0.8\n    tmp[\"Turn\"] *= 1.0\n    tmp[\"Walking\"] *= 1.2\n    tmp[\"Valid\"] *= -0.8\n    tmp[\"Task\"] *= -1.0\n    print(f\"path: {_id} {tmp.shape}\")\n    show_defog(tmp)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:34:38.956625Z","iopub.execute_input":"2023-06-08T23:34:38.957020Z","iopub.status.idle":"2023-06-08T23:35:01.873249Z","shell.execute_reply.started":"2023-06-08T23:34:38.956986Z","shell.execute_reply":"2023-06-08T23:35:01.872341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ====================================\n# Line-plot: Not_Walking\n# ====================================\nfor _id in not_walking_ids:\n    print(\"-\"*80);print(\"Not_Walking\");print(\"-\"*80)\n    display(defog_metadata_w_subjects[defog_metadata_w_subjects[\"Id\"] == _id])\n    display(tasks[tasks[\"Id\"] == _id])\n    display(events[events[\"Id\"] == _id])\n    tmp = pd.read_csv(f\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/defog/{_id}.csv\")\n    tmp[\"Time\"] = tmp.index / 100\n    tmp[\"StartHesitation\"] *= 0.8\n    tmp[\"Turn\"] *= 1.0\n    tmp[\"Walking\"] *= 1.2\n    tmp[\"Valid\"] *= -0.8\n    tmp[\"Task\"] *= -1.0\n    print(f\"path: {_id} {tmp.shape}\")\n    show_defog(tmp)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:35:01.874665Z","iopub.execute_input":"2023-06-08T23:35:01.875504Z","iopub.status.idle":"2023-06-08T23:35:13.799464Z","shell.execute_reply.started":"2023-06-08T23:35:01.875472Z","shell.execute_reply":"2023-06-08T23:35:13.798638Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 3. notype","metadata":{}},{"cell_type":"code","source":"df_list = []\nfor idx, path in tqdm(enumerate(notype_path)):\n    df = pl.read_csv(path)\n    filename = os.path.basename(path).split(\".cs\")[0]\n    tmp = pl.DataFrame(\n        {\n            \"idx\": [idx]*len(df),\n            \"ID\": [filename]*len(df),\n            \"len_df\": len(df),\n        }\n    )\n    df = pl.concat([df, tmp], how=\"horizontal\")\n    df_list.append(df)\n    \ndf_notype = pl.concat(df_list)\nshow_df(df_notype)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:35:13.800701Z","iopub.execute_input":"2023-06-08T23:35:13.801855Z","iopub.status.idle":"2023-06-08T23:35:21.744693Z","shell.execute_reply.started":"2023-06-08T23:35:13.801796Z","shell.execute_reply":"2023-06-08T23:35:21.743599Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### memo: Event Indicator variable for the occurrence of any FOG-type event. Present only in the notype series, which lack type-level annotations.","metadata":{}},{"cell_type":"code","source":"df_notype_sum = df_notype.select(\"ID\", \"Event\").groupby(\"ID\").sum()\ndf_notype_sum = df_notype_sum.join(df_notype.select(\"ID\", \"len_df\").groupby(\"ID\").mean(), on=\"ID\")\nshow_df(df_notype_sum)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:35:21.745817Z","iopub.execute_input":"2023-06-08T23:35:21.746507Z","iopub.status.idle":"2023-06-08T23:35:22.160244Z","shell.execute_reply.started":"2023-06-08T23:35:21.746477Z","shell.execute_reply":"2023-06-08T23:35:22.159169Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_notype_sum = df_notype_sum.to_pandas()\n\n# =====================================\n# Best3 -Event is count-\n# =====================================\nprint(\"-\"*80);print(\"Event\");print(\"-\"*80)\ndf_notype_sum.sort_values(\"Event\", ascending=False,inplace=True)\nevent_ids = df_notype_sum[\"ID\"][0:3]\nnot_event_ids = df_notype_sum[\"ID\"][-3:]\nprint(*event_ids)\nprint(*not_event_ids)\nshow_df(df_notype_sum, 5, True)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:35:22.161528Z","iopub.execute_input":"2023-06-08T23:35:22.161894Z","iopub.status.idle":"2023-06-08T23:35:22.198345Z","shell.execute_reply.started":"2023-06-08T23:35:22.161862Z","shell.execute_reply":"2023-06-08T23:35:22.197069Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def show_notype(df):\n    # Subplot: 1×4\n    fig, axs = plt.subplots(4, 1, figsize=(30, 10))\n\n    # Subplot-1: AccV\n    axs[0].plot(df.Time, df.AccV)\n    axs[0].set_ylabel('AccV[g] -Vertical-')\n    axs[0].set_ylim([-2.5,0])\n    axs[0].ticklabel_format(style='plain')\n\n    # Subplot-2: AccML\n    axs[1].plot(df.Time, df.AccML)\n    axs[1].set_ylabel('AccML[g] -RightLeft-')\n    axs[1].set_ylim([-2,2])\n    axs[1].ticklabel_format(style='plain')\n\n    # Subplot-3: AccAP\n    axs[2].plot(df.Time, df.AccAP)\n    axs[2].set_ylabel('AccAP[g] -ForwardBack-')\n    axs[2].set_ylim([-1,2])\n    axs[2].ticklabel_format(style='plain')\n\n    # Subplot-4: Freazing Flags\n    axs[3].plot(df.Time, df.Event, label='Event')\n    axs[3].plot(df.Time, df.Valid, label='Valid')\n    axs[3].plot(df.Time, df.Task, label='Task')\n    axs[3].set_ylabel('freazing_flag')\n    axs[3].set_xlabel('time[sec] -notype is 100Hz sampling-')\n    axs[3].legend()\n    axs[3].ticklabel_format(style='plain')\n    # show graph\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:35:22.200179Z","iopub.execute_input":"2023-06-08T23:35:22.200945Z","iopub.status.idle":"2023-06-08T23:35:22.215544Z","shell.execute_reply.started":"2023-06-08T23:35:22.200901Z","shell.execute_reply":"2023-06-08T23:35:22.214628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ====================================\n# Line-plot: Not_Walking\n# ====================================\nfor _id in event_ids:\n    print(\"-\"*80);print(\"Event\");print(\"-\"*80)\n    tmp = pd.read_csv(f\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/notype/{_id}.csv\")\n    tmp[\"Time\"] = tmp.index / 100\n    tmp[\"Event\"] *= 1.0\n    tmp[\"Valid\"] *= -0.8\n    tmp[\"Task\"] *= -1.0\n    print(f\"path: {_id} {tmp.shape}\")\n    show_notype(tmp)","metadata":{"execution":{"iopub.status.busy":"2023-06-08T23:35:22.217381Z","iopub.execute_input":"2023-06-08T23:35:22.218162Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ====================================\n# Line-plot: Not_Walking\n# ====================================\nfor _id in event_ids:\n    print(\"-\"*80);print(\"not_Event\");print(\"-\"*80)\n    tmp = pd.read_csv(f\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/notype/{_id}.csv\")\n    tmp[\"Time\"] = tmp.index / 100\n    tmp[\"Event\"] *= 1.0\n    tmp[\"Valid\"] *= -0.8\n    tmp[\"Task\"] *= -1.0\n    print(f\"path: {_id} {tmp.shape}\")\n    show_notype(tmp)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 4. Test data","metadata":{}},{"cell_type":"code","source":"def show_testdata(df):\n    # Subplot: 1×4\n    fig, axs = plt.subplots(3, 1, figsize=(30, 10))\n\n    # Subplot-1: AccV\n    axs[0].plot(df.Time, df.AccV)\n    axs[0].set_ylabel('AccV[g] -Vertical-')\n    axs[0].set_ylim([-2.5,0])\n    axs[0].ticklabel_format(style='plain')\n\n    # Subplot-2: AccML\n    axs[1].plot(df.Time, df.AccML)\n    axs[1].set_ylabel('AccML[g] -RightLeft-')\n    axs[1].set_ylim([-2,2])\n    axs[1].ticklabel_format(style='plain')\n\n    # Subplot-3: AccAP\n    axs[2].plot(df.Time, df.AccAP)\n    axs[2].set_ylabel('AccAP[g] -ForwardBack-')\n    axs[2].set_ylim([-1,2])\n    axs[2].ticklabel_format(style='plain')\n    axs[2].set_xlabel('time[sec] -notype is 100Hz sampling-')\n    # show graph\n    plt.show()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ====================================\n# Testdata -tdcsfog-\n# ====================================\nprint(\"-\"*80);print(\"tdcsfog\");print(\"-\"*80)\ndf_tdcsfog = pd.read_csv(\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/test/tdcsfog/003f117e14.csv\")\ndf_tdcsfog[\"Time\"] = df_tdcsfog.index / 128\ndf_tdcsfog[\"AccV\"]  /= 9.8\ndf_tdcsfog[\"AccML\"] /= 9.8\ndf_tdcsfog[\"AccAP\"] /= 9.8\nshow_testdata(df_tdcsfog)\n# ====================================\n# Testdata -defog-\n# ====================================\nprint(\"-\"*80);print(\"defog\");print(\"-\"*80)\ndf_defog = pd.read_csv(\"/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/test/defog/02ab235146.csv\")\nshow_df(df_defog)\ndf_defog[\"Time\"] = df_defog.index / 100\nshow_df(df_defog)\nshow_testdata(df_defog)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}