{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":41880,"databundleVersionId":5677426,"sourceType":"competition"}],"dockerImageVersionId":30635,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!pip install fasteda >> None","metadata":{"execution":{"iopub.status.busy":"2024-01-26T06:48:56.678881Z","iopub.execute_input":"2024-01-26T06:48:56.679291Z","iopub.status.idle":"2024-01-26T06:49:11.360934Z","shell.execute_reply.started":"2024-01-26T06:48:56.679260Z","shell.execute_reply":"2024-01-26T06:49:11.359217Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport time\n\n# Installed libraries\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\nfrom sklearn.metrics import roc_auc_score, log_loss\nfrom sklearn.model_selection import train_test_split\nimport torch\n\nfrom sklearn.preprocessing import LabelEncoder\nfrom sklearn.metrics import f1_score\nimport matplotlib.pyplot as plt\nfrom fasteda import fast_eda","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-01-26T06:49:11.363572Z","iopub.execute_input":"2024-01-26T06:49:11.364021Z","iopub.status.idle":"2024-01-26T06:49:11.372120Z","shell.execute_reply.started":"2024-01-26T06:49:11.363984Z","shell.execute_reply":"2024-01-26T06:49:11.370829Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filepath = '/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/tdcsfog_metadata.csv'\ndf_meta = pd.read_csv(filepath)\nfreq = {}\nfor _, row in df_meta.iterrows():\n    i = row['Id']\n    s = row['Subject']\n    if s in freq:\n        freq[s] += 1\n    else:\n        freq[s] = 1\nprint (\"Number of sessions in tdcsfog: \", len(set(df_meta['Id'].tolist())))\nprint (\"Distinct subjects in tdcsfog: \", len(set(df_meta['Subject'].tolist())))\nfreq","metadata":{"execution":{"iopub.status.busy":"2024-01-26T06:49:11.374084Z","iopub.execute_input":"2024-01-26T06:49:11.374568Z","iopub.status.idle":"2024-01-26T06:49:11.467694Z","shell.execute_reply.started":"2024-01-26T06:49:11.374522Z","shell.execute_reply":"2024-01-26T06:49:11.466361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filepath = '/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/defog_metadata.csv'\ndf_meta = pd.read_csv(filepath)\nfreq = {}\nfor _, row in df_meta.iterrows():\n    i = row['Id']\n    s = row['Subject']\n    if s in freq:\n        freq[s] += 1\n    else:\n        freq[s] = 1\nprint (\"Number of sessions in defog: \", len(set(df_meta['Id'].tolist())))\nprint (\"Distinct subjects in defog: \", len(set(df_meta['Subject'].tolist())))\nfreq","metadata":{"execution":{"iopub.status.busy":"2024-01-26T06:49:11.471089Z","iopub.execute_input":"2024-01-26T06:49:11.471608Z","iopub.status.idle":"2024-01-26T06:49:11.500385Z","shell.execute_reply.started":"2024-01-26T06:49:11.471560Z","shell.execute_reply":"2024-01-26T06:49:11.499045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = '/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/tdcsfog/'\ntdcsfog = pd.concat([pd.read_csv(os.path.join(root, name)) for root, _, files in os.walk(path) for name in files], axis=0)\n\ntdcsfog.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-26T06:49:11.501960Z","iopub.execute_input":"2024-01-26T06:49:11.502407Z","iopub.status.idle":"2024-01-26T06:49:28.775470Z","shell.execute_reply.started":"2024-01-26T06:49:11.502362Z","shell.execute_reply":"2024-01-26T06:49:28.774144Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print (\"Count of tdcsfog data:\", len(defog))\ndefog.describe()","metadata":{"execution":{"iopub.status.busy":"2024-01-26T06:49:28.776887Z","iopub.execute_input":"2024-01-26T06:49:28.777244Z","iopub.status.idle":"2024-01-26T06:49:33.125640Z","shell.execute_reply.started":"2024-01-26T06:49:28.777213Z","shell.execute_reply":"2024-01-26T06:49:33.124377Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = '/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/defog'\ndefog = pd.concat([pd.read_csv(os.path.join(root, name)) for root, _, files in os.walk(path) for name in files], axis=0)\n\ndefog_data_valid = defog.loc[ \\\n                        (defog.Valid == True) & (defog.Task == True)].copy()\n\ndefog_data_valid.reset_index(drop=True, inplace=True)\ndefog_data_valid.drop(['Valid', 'Task'], axis=1, inplace=True)\nprint (\"Count of valid defog data:\", len(defog_data_valid))\n# Defog data acc unit is g rather than m/s^2, fix it first\nfull_data = pd.concat([tdcsfog, defog_data_valid])\nprint (\"Count of combined data:\", len(full_data))\nfull_data.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-26T06:49:33.127265Z","iopub.execute_input":"2024-01-26T06:49:33.127703Z","iopub.status.idle":"2024-01-26T06:49:50.466674Z","shell.execute_reply.started":"2024-01-26T06:49:33.127666Z","shell.execute_reply":"2024-01-26T06:49:50.465457Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.heatmap(tdcsfog.corr(),annot= True)","metadata":{"execution":{"iopub.status.busy":"2024-01-26T06:53:59.963302Z","iopub.execute_input":"2024-01-26T06:53:59.963780Z","iopub.status.idle":"2024-01-26T06:54:01.940944Z","shell.execute_reply.started":"2024-01-26T06:53:59.963729Z","shell.execute_reply":"2024-01-26T06:54:01.939569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df= pd.DataFrame(np.concatenate([\n    ['total entries'] * len(tdcsfog),\n    ['Start Hesitation'] *  int(tdcsfog['StartHesitation'].mean() * len(tdcsfog)),\n    ['Turn'] * int(tdcsfog['Turn'].mean() * len(tdcsfog)),\n    ['Walking'] * int(tdcsfog['Walking'].mean() * len(tdcsfog))]),\n    columns= ['Number of 1s']\n    )\n\nsns.countplot(data=df, x='Number of 1s')","metadata":{"execution":{"iopub.status.busy":"2024-01-26T06:54:34.493967Z","iopub.execute_input":"2024-01-26T06:54:34.494848Z","iopub.status.idle":"2024-01-26T06:54:51.638665Z","shell.execute_reply.started":"2024-01-26T06:54:34.494802Z","shell.execute_reply":"2024-01-26T06:54:51.637424Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.pairplot(tdcsfog[['AccV','AccML','AccAP']])","metadata":{"execution":{"iopub.status.busy":"2024-01-26T06:56:05.153027Z","iopub.execute_input":"2024-01-26T06:56:05.153509Z","iopub.status.idle":"2024-01-26T06:59:32.576622Z","shell.execute_reply.started":"2024-01-26T06:56:05.153475Z","shell.execute_reply":"2024-01-26T06:59:32.575676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.histplot(data=tdcsfog[['AccV', 'AccML', 'AccAP']])","metadata":{"execution":{"iopub.status.busy":"2024-01-26T07:04:22.456453Z","iopub.execute_input":"2024-01-26T07:04:22.456899Z","iopub.status.idle":"2024-01-26T07:05:31.310213Z","shell.execute_reply.started":"2024-01-26T07:04:22.456864Z","shell.execute_reply":"2024-01-26T07:05:31.308858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.histplot(data=tdcsfog, x='AccV', hue='StartHesitation')","metadata":{"execution":{"iopub.status.busy":"2024-01-26T07:09:23.589977Z","iopub.execute_input":"2024-01-26T07:09:23.590455Z","iopub.status.idle":"2024-01-26T07:09:58.210633Z","shell.execute_reply.started":"2024-01-26T07:09:23.590411Z","shell.execute_reply":"2024-01-26T07:09:58.209094Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.histplot(data=tdcsfog, x='AccV', hue='Turn')","metadata":{"execution":{"iopub.status.busy":"2024-01-26T07:01:17.074750Z","iopub.execute_input":"2024-01-26T07:01:17.075204Z","iopub.status.idle":"2024-01-26T07:01:52.859030Z","shell.execute_reply.started":"2024-01-26T07:01:17.075160Z","shell.execute_reply":"2024-01-26T07:01:52.857562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.histplot(data=tdcsfog, x='AccV', hue='Walking')","metadata":{"execution":{"iopub.status.busy":"2024-01-26T07:09:58.212415Z","iopub.execute_input":"2024-01-26T07:09:58.212787Z","iopub.status.idle":"2024-01-26T07:10:30.945263Z","shell.execute_reply.started":"2024-01-26T07:09:58.212724Z","shell.execute_reply":"2024-01-26T07:10:30.943686Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.histplot(data=tdcsfog, x='AccML', hue='StartHesitation')","metadata":{"execution":{"iopub.status.busy":"2024-01-26T07:12:18.324737Z","iopub.execute_input":"2024-01-26T07:12:18.325833Z","iopub.status.idle":"2024-01-26T07:12:42.565163Z","shell.execute_reply.started":"2024-01-26T07:12:18.325752Z","shell.execute_reply":"2024-01-26T07:12:42.564011Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.histplot(data=tdcsfog, x='AccML', hue='Turn')","metadata":{"execution":{"iopub.status.busy":"2024-01-26T07:02:45.129750Z","iopub.execute_input":"2024-01-26T07:02:45.130195Z","iopub.status.idle":"2024-01-26T07:03:08.502532Z","shell.execute_reply.started":"2024-01-26T07:02:45.130161Z","shell.execute_reply":"2024-01-26T07:03:08.501276Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.histplot(data=tdcsfog, x='AccML', hue='Walking')","metadata":{"execution":{"iopub.status.busy":"2024-01-26T07:12:42.567457Z","iopub.execute_input":"2024-01-26T07:12:42.567899Z","iopub.status.idle":"2024-01-26T07:13:04.910042Z","shell.execute_reply.started":"2024-01-26T07:12:42.567865Z","shell.execute_reply":"2024-01-26T07:13:04.909225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.histplot(data=tdcsfog, x='AccAP', hue='StartHesitation')","metadata":{"execution":{"iopub.status.busy":"2024-01-26T07:13:04.911507Z","iopub.execute_input":"2024-01-26T07:13:04.912086Z","iopub.status.idle":"2024-01-26T07:13:25.150426Z","shell.execute_reply.started":"2024-01-26T07:13:04.912054Z","shell.execute_reply":"2024-01-26T07:13:25.149358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.histplot(data=tdcsfog, x='AccAP', hue='Turn')","metadata":{"execution":{"iopub.status.busy":"2024-01-26T07:03:08.504287Z","iopub.execute_input":"2024-01-26T07:03:08.504629Z","iopub.status.idle":"2024-01-26T07:03:26.762537Z","shell.execute_reply.started":"2024-01-26T07:03:08.504599Z","shell.execute_reply":"2024-01-26T07:03:26.761102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.histplot(data=tdcsfog, x='AccAP', hue='Walking')","metadata":{"execution":{"iopub.status.busy":"2024-01-26T07:13:25.152904Z","iopub.execute_input":"2024-01-26T07:13:25.153785Z","iopub.status.idle":"2024-01-26T07:13:43.428441Z","shell.execute_reply.started":"2024-01-26T07:13:25.153726Z","shell.execute_reply":"2024-01-26T07:13:43.427211Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Looking at single session graph","metadata":{}},{"cell_type":"code","source":"path = '/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/tdcsfog/'\nstart_hesitation_sessions, turn_sessions, walking_sessions = [], [], []\nfor root, _, files in os.walk(path):\n    for file in files:\n        df = pd.read_csv(os.path.join(root, file))\n        if len(set(df['StartHesitation'].tolist())) == 2:\n            start_hesitation_sessions.append(file)\n        if len(set(df['Turn'].tolist())) == 2:\n            turn_sessions.append(file)\n        if len(set(df['Walking'].tolist())) == 2:\n            walking_sessions.append(file)\nprint (start_hesitation_sessions[:10])\nprint (turn_sessions[:10])\nprint (walking_sessions[:10])","metadata":{"execution":{"iopub.status.busy":"2024-01-26T07:39:43.208460Z","iopub.execute_input":"2024-01-26T07:39:43.208987Z","iopub.status.idle":"2024-01-26T07:39:54.636402Z","shell.execute_reply.started":"2024-01-26T07:39:43.208946Z","shell.execute_reply":"2024-01-26T07:39:54.633999Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Example session which had Start Hesitation FOG\npath = '/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/tdcsfog/9b378f315c.csv'\ndf_session = pd.read_csv(path)","metadata":{"execution":{"iopub.status.busy":"2024-01-26T07:50:49.950176Z","iopub.execute_input":"2024-01-26T07:50:49.950598Z","iopub.status.idle":"2024-01-26T07:50:49.971026Z","shell.execute_reply.started":"2024-01-26T07:50:49.950567Z","shell.execute_reply":"2024-01-26T07:50:49.969975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.scatterplot(data=df_session[df_session.Time < 1500], x=\"Time\", y=\"AccV\", hue='StartHesitation')","metadata":{"execution":{"iopub.status.busy":"2024-01-26T07:51:30.309736Z","iopub.execute_input":"2024-01-26T07:51:30.310209Z","iopub.status.idle":"2024-01-26T07:51:30.788610Z","shell.execute_reply.started":"2024-01-26T07:51:30.310173Z","shell.execute_reply":"2024-01-26T07:51:30.787358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.scatterplot(data=df_session[df_session.Time < 1500], x=\"Time\", y=\"AccML\", hue='StartHesitation')","metadata":{"execution":{"iopub.status.busy":"2024-01-26T07:51:56.732927Z","iopub.execute_input":"2024-01-26T07:51:56.733407Z","iopub.status.idle":"2024-01-26T07:51:57.269441Z","shell.execute_reply.started":"2024-01-26T07:51:56.733369Z","shell.execute_reply":"2024-01-26T07:51:57.268182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.scatterplot(data=df_session[df_session.Time < 1500], x=\"Time\", y=\"AccAP\", hue='StartHesitation')","metadata":{"execution":{"iopub.status.busy":"2024-01-26T07:52:13.580952Z","iopub.execute_input":"2024-01-26T07:52:13.581370Z","iopub.status.idle":"2024-01-26T07:52:14.128574Z","shell.execute_reply.started":"2024-01-26T07:52:13.581339Z","shell.execute_reply":"2024-01-26T07:52:14.127356Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Example session which had Turn FOG\npath = '/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/tdcsfog/5ff654941a.csv'\ndf_session = pd.read_csv(path)","metadata":{"execution":{"iopub.status.busy":"2024-01-26T07:54:57.306699Z","iopub.execute_input":"2024-01-26T07:54:57.307148Z","iopub.status.idle":"2024-01-26T07:54:57.326338Z","shell.execute_reply.started":"2024-01-26T07:54:57.307114Z","shell.execute_reply":"2024-01-26T07:54:57.325129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.scatterplot(data=df_session[df_session.Time < 3000], x=\"Time\", y=\"AccV\", hue='Turn')","metadata":{"execution":{"iopub.status.busy":"2024-01-26T07:55:23.876904Z","iopub.execute_input":"2024-01-26T07:55:23.877370Z","iopub.status.idle":"2024-01-26T07:55:24.482272Z","shell.execute_reply.started":"2024-01-26T07:55:23.877333Z","shell.execute_reply":"2024-01-26T07:55:24.479833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.scatterplot(data=df_session[df_session.Time < 3000], x=\"Time\", y=\"AccML\", hue='Turn')","metadata":{"execution":{"iopub.status.busy":"2024-01-26T07:55:34.031020Z","iopub.execute_input":"2024-01-26T07:55:34.031744Z","iopub.status.idle":"2024-01-26T07:55:34.718435Z","shell.execute_reply.started":"2024-01-26T07:55:34.031684Z","shell.execute_reply":"2024-01-26T07:55:34.717102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.scatterplot(data=df_session[df_session.Time < 3000], x=\"Time\", y=\"AccAP\", hue='Turn')","metadata":{"execution":{"iopub.status.busy":"2024-01-26T07:55:40.937470Z","iopub.execute_input":"2024-01-26T07:55:40.937908Z","iopub.status.idle":"2024-01-26T07:55:41.548268Z","shell.execute_reply.started":"2024-01-26T07:55:40.937874Z","shell.execute_reply":"2024-01-26T07:55:41.547377Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Example session which had Walking FOG\npath = '/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/tdcsfog/7fb91164ad.csv'\ndf_session = pd.read_csv(path)","metadata":{"execution":{"iopub.status.busy":"2024-01-26T07:45:01.628952Z","iopub.execute_input":"2024-01-26T07:45:01.629405Z","iopub.status.idle":"2024-01-26T07:45:01.649347Z","shell.execute_reply.started":"2024-01-26T07:45:01.629371Z","shell.execute_reply":"2024-01-26T07:45:01.647985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.scatterplot(data=df_session, x=\"Time\", y=\"AccV\", hue='Walking')","metadata":{"execution":{"iopub.status.busy":"2024-01-26T07:46:32.751533Z","iopub.execute_input":"2024-01-26T07:46:32.751977Z","iopub.status.idle":"2024-01-26T07:46:34.617152Z","shell.execute_reply.started":"2024-01-26T07:46:32.751942Z","shell.execute_reply":"2024-01-26T07:46:34.615690Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.scatterplot(data=df_session, x=\"Time\", y=\"AccML\", hue='Walking')","metadata":{"execution":{"iopub.status.busy":"2024-01-26T07:46:26.397471Z","iopub.execute_input":"2024-01-26T07:46:26.397908Z","iopub.status.idle":"2024-01-26T07:46:27.502639Z","shell.execute_reply.started":"2024-01-26T07:46:26.397873Z","shell.execute_reply":"2024-01-26T07:46:27.501419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.scatterplot(data=df_session, x=\"Time\", y=\"AccAP\", hue='Walking')","metadata":{"execution":{"iopub.status.busy":"2024-01-26T07:46:00.811626Z","iopub.execute_input":"2024-01-26T07:46:00.812143Z","iopub.status.idle":"2024-01-26T07:46:02.291177Z","shell.execute_reply.started":"2024-01-26T07:46:00.812105Z","shell.execute_reply":"2024-01-26T07:46:02.289942Z"},"trusted":true},"execution_count":null,"outputs":[]}]}