{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","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":30786,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2024-11-17T10:14:17.780084Z","iopub.execute_input":"2024-11-17T10:14:17.780816Z","iopub.status.idle":"2024-11-17T10:14:19.452221Z","shell.execute_reply.started":"2024-11-17T10:14:17.780763Z","shell.execute_reply":"2024-11-17T10:14:19.450794Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nimport glob\nimport pandas as pd\n\n\ntrain_dir = '/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/defog'\ntest_dir = '/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/test/defog'\n\n\ntrain_files = glob.glob(os.path.join(train_dir, '*.csv'))\ntrain_data = pd.concat([pd.read_csv(file) for file in train_files], ignore_index=True)\n\n\ntest_files = glob.glob(os.path.join(test_dir, '*.csv'))\ntest_data = pd.concat([pd.read_csv(file) for file in test_files], ignore_index=True)\n\n\nprint(\"Train Data Info:\")\nprint(train_data.info())\nprint(\"\\nTest Data Info:\")\nprint(test_data.info())\n\n\nprint(\"\\nFirst 5 rows of Train Data:\")\nprint(train_data.head())\n\nprint(\"\\nFirst 5 rows of Test Data:\")\nprint(test_data.head())\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-17T10:40:50.543870Z","iopub.execute_input":"2024-11-17T10:40:50.544364Z","iopub.status.idle":"2024-11-17T10:41:07.892572Z","shell.execute_reply.started":"2024-11-17T10:40:50.544318Z","shell.execute_reply":"2024-11-17T10:41:07.891217Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\nmissing_train = train_data.isnull().sum()\nprint(\"\\nMissing Values in Train Data:\")\nprint(missing_train[missing_train > 0])\n\n\nmissing_test = test_data.isnull().sum()\nprint(\"\\nMissing Values in Test Data:\")\nprint(missing_test[missing_test > 0])\n\n\ntrain_data.fillna(train_data.median(), inplace=True)\ntest_data.fillna(test_data.median(), inplace=True)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-17T10:41:18.984450Z","iopub.execute_input":"2024-11-17T10:41:18.984903Z","iopub.status.idle":"2024-11-17T10:41:20.634742Z","shell.execute_reply.started":"2024-11-17T10:41:18.984860Z","shell.execute_reply":"2024-11-17T10:41:20.633534Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\nplt.figure(figsize=(10, 10))\ntrain_data.hist()\nplt.suptitle(\"Distribution in Train Data\")\nplt.show()\n\nplt.figure(figsize=(12, 10))\ntest_data.hist()\nplt.suptitle(\"Distribution in Test Data\")\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-17T11:27:15.128982Z","iopub.execute_input":"2024-11-17T11:27:15.129503Z","iopub.status.idle":"2024-11-17T11:27:20.309449Z","shell.execute_reply.started":"2024-11-17T11:27:15.129457Z","shell.execute_reply":"2024-11-17T11:27:20.308358Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(12, 8))\nsns.heatmap(train_data.corr(), annot=True)\nplt.title(\"Correlation Matrix for Train Data\")\nplt.show()\n\nplt.figure(figsize=(12, 8))\nsns.heatmap(test_data.corr(), annot=True)\nplt.title(\"Correlation Matrix for Test Data\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-17T11:21:34.549642Z","iopub.execute_input":"2024-11-17T11:21:34.550093Z","iopub.status.idle":"2024-11-17T11:21:39.190292Z","shell.execute_reply.started":"2024-11-17T11:21:34.550052Z","shell.execute_reply":"2024-11-17T11:21:39.189076Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for col in train_data.select_dtypes(include=[np.number]).columns:\n    plt.figure(figsize=(10, 5))\n    sns.boxplot(x=train_data[col])\n    plt.title(f\"Boxplot of {col} in Train Data\")\n    plt.show()\n    \nfor col in test_data.select_dtypes(include=[np.number]).columns:\n    plt.figure(figsize=(10, 5))\n    sns.boxplot(x=test_data[col])\n    plt.title(f\"Boxplot of {col} in Test Data\")\n    plt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-17T10:42:26.141455Z","iopub.execute_input":"2024-11-17T10:42:26.141937Z","iopub.status.idle":"2024-11-17T10:42:37.118344Z","shell.execute_reply.started":"2024-11-17T10:42:26.141891Z","shell.execute_reply":"2024-11-17T10:42:37.117094Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"skewness_train = train_data.select_dtypes(include=[np.number]).skew()\nskewness_test = test_data.select_dtypes(include=[np.number]).skew()\n\nprint(\"Skewness in Train Data:\")\nprint(skewness_train)\n\nprint(\"\\nSkewness in Test Data:\")\nprint(skewness_test)\n\nplt.figure(figsize=(12, 6))\ntrain_data.select_dtypes(include=[np.number]).skew().plot(kind='bar')\nplt.title(\"Skewness of Numerical Features in Train Data\")\nplt.show()\nplt.figure(figsize=(12, 6))\ntest_data.select_dtypes(include=[np.number]).skew().plot(kind='bar')\nplt.title(\"Skewness of Numerical Features in Test Data\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-17T10:57:50.425556Z","iopub.execute_input":"2024-11-17T10:57:50.426957Z","iopub.status.idle":"2024-11-17T10:57:55.196958Z","shell.execute_reply.started":"2024-11-17T10:57:50.426898Z","shell.execute_reply":"2024-11-17T10:57:55.195697Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.subplot(3, 1, 1)\nplt.plot(train_data['Time'], train_data['AccV'])\nplt.title('accV - Acceleration in Vertical Axis')\nplt.xlabel('Time')\nplt.ylabel('Acceleration (m/s²)')\n\nplt.subplot(3, 1, 2)\nplt.plot(train_data['Time'], train_data['AccML'])\nplt.title('accML - Acceleration in Medial-Lateral Axis')\nplt.xlabel('Time')\nplt.ylabel('Acceleration (m/s²)')\n\nplt.subplot(3, 1, 3)\nplt.plot(train_data['Time'], train_data['AccAP'])\nplt.title('accAP - Acceleration in Anterior-Posterior Axis')\nplt.xlabel('Time')\nplt.ylabel('Acceleration (m/s²)')\n\nplt.tight_layout()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-17T11:05:26.752572Z","iopub.execute_input":"2024-11-17T11:05:26.753021Z","iopub.status.idle":"2024-11-17T11:05:32.857098Z","shell.execute_reply.started":"2024-11-17T11:05:26.752978Z","shell.execute_reply":"2024-11-17T11:05:32.855852Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sensor_columns = ['AccV', 'AccML', 'AccAP']\nprint(train_data[sensor_columns].describe())\nprint(train_data[sensor_columns].skew())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-17T11:07:34.642316Z","iopub.execute_input":"2024-11-17T11:07:34.642774Z","iopub.status.idle":"2024-11-17T11:07:37.130105Z","shell.execute_reply.started":"2024-11-17T11:07:34.642731Z","shell.execute_reply":"2024-11-17T11:07:37.128929Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sensor_data_corr = train_data[sensor_columns].corr()\nplt.figure(figsize=(6, 5))\nsns.heatmap(sensor_data_corr, annot=True, fmt=\".2f\", cmap='coolwarm', vmin=-1, vmax=1)\nplt.title(\"Correlation Heatmap for Accelerometer Data\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-17T11:08:15.079358Z","iopub.execute_input":"2024-11-17T11:08:15.080270Z","iopub.status.idle":"2024-11-17T11:08:15.987827Z","shell.execute_reply.started":"2024-11-17T11:08:15.080223Z","shell.execute_reply":"2024-11-17T11:08:15.986586Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(15, 5))\nsns.boxplot(x='Walking', y='AccV', data=train_data)\nplt.title('Walking Impact on Vertical Acceleration')\nplt.show()\n\nsns.boxplot(x='StartHesitation', y='AccML', data=train_data)\nplt.title('Start Hesitation Impact on Medial-Lateral Acceleration')\nplt.show()\n\nsns.boxplot(x='Turn', y='AccAP', data=train_data)\nplt.title('Turn Impact on Anterior-Posterior Acceleration')\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-17T11:12:47.909902Z","iopub.execute_input":"2024-11-17T11:12:47.910385Z","iopub.status.idle":"2024-11-17T11:12:56.266605Z","shell.execute_reply.started":"2024-11-17T11:12:47.910343Z","shell.execute_reply":"2024-11-17T11:12:56.265492Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"walking_data = train_data[train_data['Walking'] == 1]\nplt.figure(figsize=(12, 6))\nplt.plot(walking_data['AccV'], label=\"AccV (Vertical)\")\nplt.plot(walking_data['AccML'], label=\"AccML (Medial-Lateral)\")\nplt.plot(walking_data['AccAP'], label=\"AccAP (Anterior-Posterior)\")\nplt.title('Sensor Data during Walking')\nplt.legend()\nplt.show()\n\nhesitation_data = train_data[train_data['StartHesitation'] == 1]\nplt.figure(figsize=(12, 6))\nplt.plot(hesitation_data['AccV'], label=\"AccV (Vertical)\")\nplt.plot(hesitation_data['AccML'], label=\"AccML (Medial-Lateral)\")\nplt.plot(hesitation_data['AccAP'], label=\"AccAP (Anterior-Posterior)\")\nplt.title('Sensor Data during Start Hesitation')\nplt.legend()\nplt.show()\n\nturn_data = train_data[train_data['Turn'] == 1]\nplt.figure(figsize=(12, 6))\nplt.plot(turn_data['AccV'], label=\"AccV (Vertical)\")\nplt.plot(turn_data['AccML'], label=\"AccML (Medial-Lateral)\")\nplt.plot(turn_data['AccAP'], label=\"AccAP (Anterior-Posterior)\")\nplt.title('Sensor Data during Turn')\nplt.legend()\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-17T11:17:56.264986Z","iopub.execute_input":"2024-11-17T11:17:56.266040Z","iopub.status.idle":"2024-11-17T11:18:00.426315Z","shell.execute_reply.started":"2024-11-17T11:17:56.265992Z","shell.execute_reply":"2024-11-17T11:18:00.425236Z"}},"outputs":[],"execution_count":null}]}