{"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":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\n%config Completer.use_jedi = False\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","execution":{"iopub.status.busy":"2024-02-02T11:48:56.803824Z","iopub.execute_input":"2024-02-02T11:48:56.804162Z","iopub.status.idle":"2024-02-02T11:48:57.142965Z","shell.execute_reply.started":"2024-02-02T11:48:56.804137Z","shell.execute_reply":"2024-02-02T11:48:57.142294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\ndf = pd.read_csv('/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/tdcsfog/0330ea6680.csv')\ndf.head(5)","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:48:57.144304Z","iopub.execute_input":"2024-02-02T11:48:57.144790Z","iopub.status.idle":"2024-02-02T11:48:57.202935Z","shell.execute_reply.started":"2024-02-02T11:48:57.144766Z","shell.execute_reply":"2024-02-02T11:48:57.202036Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.tail(5)","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:48:57.205046Z","iopub.execute_input":"2024-02-02T11:48:57.205289Z","iopub.status.idle":"2024-02-02T11:48:57.216182Z","shell.execute_reply.started":"2024-02-02T11:48:57.205268Z","shell.execute_reply":"2024-02-02T11:48:57.215440Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10,5))\nplt.plot(df['Time'],df['AccV'])\nplt.show","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:48:57.218372Z","iopub.execute_input":"2024-02-02T11:48:57.218794Z","iopub.status.idle":"2024-02-02T11:48:57.474445Z","shell.execute_reply.started":"2024-02-02T11:48:57.218772Z","shell.execute_reply":"2024-02-02T11:48:57.473755Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10,5))\nplt.plot(df['Time'],df['AccML'])\nplt.show","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:48:57.475777Z","iopub.execute_input":"2024-02-02T11:48:57.476233Z","iopub.status.idle":"2024-02-02T11:48:57.671574Z","shell.execute_reply.started":"2024-02-02T11:48:57.476207Z","shell.execute_reply":"2024-02-02T11:48:57.670912Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10,5))\nplt.plot(df['Time'],df['AccAP'])\nplt.show","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:48:57.672704Z","iopub.execute_input":"2024-02-02T11:48:57.673157Z","iopub.status.idle":"2024-02-02T11:48:57.867771Z","shell.execute_reply.started":"2024-02-02T11:48:57.673131Z","shell.execute_reply":"2024-02-02T11:48:57.866767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe()","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:48:57.869134Z","iopub.execute_input":"2024-02-02T11:48:57.869652Z","iopub.status.idle":"2024-02-02T11:48:57.896390Z","shell.execute_reply.started":"2024-02-02T11:48:57.869621Z","shell.execute_reply":"2024-02-02T11:48:57.895455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tdcsfog_path = '/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/tdcsfog'\n\ntdcsfog_list = []\n\nfor file_name in os.listdir(tdcsfog_path):\n    if file_name.endswith('.csv'):\n        file_path = os.path.join(tdcsfog_path, file_name)\n        file = pd.read_csv(file_path)\n        file.Time = file.Time/128\n        tdcsfog_list.append(file)\n\ntdcsfog = pd.concat(tdcsfog_list, axis = 0)\n\ntdcsfog","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:48:57.897521Z","iopub.execute_input":"2024-02-02T11:48:57.897796Z","iopub.status.idle":"2024-02-02T11:49:17.474141Z","shell.execute_reply.started":"2024-02-02T11:48:57.897775Z","shell.execute_reply":"2024-02-02T11:49:17.473366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tdcsfog[tdcsfog['Time']==40].shape[0]","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:49:17.475429Z","iopub.execute_input":"2024-02-02T11:49:17.475661Z","iopub.status.idle":"2024-02-02T11:49:17.496910Z","shell.execute_reply.started":"2024-02-02T11:49:17.475640Z","shell.execute_reply":"2024-02-02T11:49:17.496085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def reduce_memory_usage(df):\n    \n    start_mem = df.memory_usage().sum() / 1024 ** 2\n    print('Memory usage of dataframe is {:.2f} MB'.format(start_mem))\n    \n    for col in df.columns:\n        col_type = df[col].dtype.name\n        if ((col_type != 'datetime64[ns]') & (col_type != 'category')):\n            if (col_type != 'object'):\n                c_min = df[col].min()\n                c_max = df[col].max()\n\n                if str(col_type)[:3] == 'int':\n                    if c_min > np.iinfo(np.int8).min and c_max < np.iinfo(np.int8).max:\n                        df[col] = df[col].astype(np.int8)\n                    elif c_min > np.iinfo(np.int16).min and c_max < np.iinfo(np.int16).max:\n                        df[col] = df[col].astype(np.int16)\n                    elif c_min > np.iinfo(np.int32).min and c_max < np.iinfo(np.int32).max:\n                        df[col] = df[col].astype(np.int32)\n                    elif c_min > np.iinfo(np.int64).min and c_max < np.iinfo(np.int64).max:\n                        df[col] = df[col].astype(np.int64)\n\n                else:\n                    if c_min > np.finfo(np.float16).min and c_max < np.finfo(np.float16).max:\n                        df[col] = df[col].astype(np.float16)\n                    elif c_min > np.finfo(np.float32).min and c_max < np.finfo(np.float32).max:\n                        df[col] = df[col].astype(np.float32)\n                    else:\n                        pass\n            else:\n                df[col] = df[col].astype('category')\n    mem_usg = df.memory_usage().sum() / 1024 ** 2 \n    print(\"Memory usage became: \",mem_usg,\" MB\")\n    \n    return df","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:49:17.500754Z","iopub.execute_input":"2024-02-02T11:49:17.501479Z","iopub.status.idle":"2024-02-02T11:49:17.511848Z","shell.execute_reply.started":"2024-02-02T11:49:17.501450Z","shell.execute_reply":"2024-02-02T11:49:17.511084Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tdcsfog = reduce_memory_usage(tdcsfog)","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:49:17.512981Z","iopub.execute_input":"2024-02-02T11:49:17.513486Z","iopub.status.idle":"2024-02-02T11:49:17.732821Z","shell.execute_reply.started":"2024-02-02T11:49:17.513457Z","shell.execute_reply":"2024-02-02T11:49:17.732048Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tdcsfog.describe()","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:49:17.733924Z","iopub.execute_input":"2024-02-02T11:49:17.734455Z","iopub.status.idle":"2024-02-02T11:49:19.973077Z","shell.execute_reply.started":"2024-02-02T11:49:17.734425Z","shell.execute_reply":"2024-02-02T11:49:19.972485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\ndata = pd.DataFrame(\n    np.concatenate([\n        ['Total'] * len(tdcsfog),\n        ['StartHesitation'] * int(np.ceil(len(tdcsfog) / 2 * tdcsfog['StartHesitation'].mean())),\n        ['Turn'] * int(np.ceil(len(tdcsfog) / 2 * tdcsfog['Turn'].mean())),\n        ['Walking'] * int(np.ceil(len(tdcsfog) / 2 * tdcsfog['Walking'].mean()))\n    ]),\n    columns = [\"The Number of 1\"]\n)\n\nsns.countplot(x = 'The Number of 1', data = data)","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:49:19.973841Z","iopub.execute_input":"2024-02-02T11:49:19.974219Z","iopub.status.idle":"2024-02-02T11:49:26.031100Z","shell.execute_reply.started":"2024-02-02T11:49:19.974198Z","shell.execute_reply":"2024-02-02T11:49:26.030065Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nplt.figure(figsize = (12,6))\n\n# Calculates the mean values of all other columns for each unique value of Time.\n# Reset the index of the resulting dataframe.\ntdcsfog['Time'] = tdcsfog['Time'].astype('float64')\ntdcsfog_means = tdcsfog.groupby('Time').mean().reset_index()\n\n\nplt.plot(tdcsfog_means['Time'], tdcsfog_means['StartHesitation'], label = 'StartHesitation')\nplt.plot(tdcsfog_means['Time'], tdcsfog_means['Turn'], label = 'Turn')\nplt.plot(tdcsfog_means['Time'], tdcsfog_means['Walking'], label = 'Walking')\nplt.legend()\nplt.xlabel('Time')\nplt.ylabel('Mean Value')\nplt.title('Mean Values of StartHesitation, Turn, and Walking over Time')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:49:26.032398Z","iopub.execute_input":"2024-02-02T11:49:26.032722Z","iopub.status.idle":"2024-02-02T11:49:26.878949Z","shell.execute_reply.started":"2024-02-02T11:49:26.032693Z","shell.execute_reply":"2024-02-02T11:49:26.877959Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = tdcsfog.copy()\ndf['start']=df['Time'].eq(0)\ndf['id']=df['start'].cumsum()\nsubject_time_ranges = df.groupby('id')['Time'].max()","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:49:26.879953Z","iopub.execute_input":"2024-02-02T11:49:26.880201Z","iopub.status.idle":"2024-02-02T11:49:27.069545Z","shell.execute_reply.started":"2024-02-02T11:49:26.880180Z","shell.execute_reply":"2024-02-02T11:49:27.068505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"subject_time_ranges","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:49:27.070701Z","iopub.execute_input":"2024-02-02T11:49:27.070985Z","iopub.status.idle":"2024-02-02T11:49:27.078748Z","shell.execute_reply.started":"2024-02-02T11:49:27.070961Z","shell.execute_reply":"2024-02-02T11:49:27.077793Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bins = np.arange(0,200+10.0,10.0)\ntime_range_categories = pd.cut(subject_time_ranges, bins)\ntime_range_counts = time_range_categories.value_counts().sort_index()","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:49:27.090445Z","iopub.execute_input":"2024-02-02T11:49:27.090776Z","iopub.status.idle":"2024-02-02T11:49:27.107325Z","shell.execute_reply.started":"2024-02-02T11:49:27.090723Z","shell.execute_reply":"2024-02-02T11:49:27.106455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10, 6))\ntime_range_counts.plot(kind='bar')\nplt.title('Subject')\nplt.xlabel('time')\nplt.ylabel('Subject')\nplt.xticks(rotation=45, fontsize=10)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:49:27.108363Z","iopub.execute_input":"2024-02-02T11:49:27.108612Z","iopub.status.idle":"2024-02-02T11:49:27.508425Z","shell.execute_reply.started":"2024-02-02T11:49:27.108590Z","shell.execute_reply":"2024-02-02T11:49:27.507572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"defog_path = '/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/defog'\ndefog_list = []\n\n# 100 Hz\nfor file_name in os.listdir(defog_path):\n    if file_name.endswith('.csv'):\n        file_path = os.path.join(defog_path, file_name)\n        file = pd.read_csv(file_path)\n        file.Time = file.Time /100\n        defog_list.append(file)\n\ndefog = pd.concat(defog_list, axis = 0)\n\ndefog","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:49:27.856941Z","iopub.execute_input":"2024-02-02T11:49:27.857385Z","iopub.status.idle":"2024-02-02T11:49:53.974420Z","shell.execute_reply.started":"2024-02-02T11:49:27.857361Z","shell.execute_reply":"2024-02-02T11:49:53.973173Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"defog.describe()","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:49:53.975519Z","iopub.execute_input":"2024-02-02T11:49:53.975777Z","iopub.status.idle":"2024-02-02T11:49:55.829207Z","shell.execute_reply.started":"2024-02-02T11:49:53.975754Z","shell.execute_reply":"2024-02-02T11:49:55.828103Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (12,6))\n\n# Calculates the mean values of all other columns for each unique value of Time.\n# Reset the index of the resulting dataframe.\ndefog['Time'] = defog['Time'].astype('float64')\ndefog_means = defog.groupby('Time').mean().reset_index()\n\n\nplt.plot(defog_means['Time'], defog_means['StartHesitation'], label = 'StartHesitation')\nplt.plot(defog_means['Time'], defog_means['Turn'], label = 'Turn')\nplt.plot(defog_means['Time'], defog_means['Walking'], label = 'Walking')\nplt.legend()\nplt.xlabel('Time')\nplt.ylabel('Mean Value')\nplt.title('Mean Values of StartHesitation, Turn, and Walking over Time')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:49:55.830765Z","iopub.execute_input":"2024-02-02T11:49:55.831186Z","iopub.status.idle":"2024-02-02T11:49:58.644151Z","shell.execute_reply.started":"2024-02-02T11:49:55.831147Z","shell.execute_reply":"2024-02-02T11:49:58.643061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"defog = reduce_memory_usage(defog)","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:49:58.645657Z","iopub.execute_input":"2024-02-02T11:49:58.646067Z","iopub.status.idle":"2024-02-02T11:49:59.156506Z","shell.execute_reply.started":"2024-02-02T11:49:58.646003Z","shell.execute_reply":"2024-02-02T11:49:59.155258Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"defog = defog[(defog['Task'] == 1) & (defog['Valid'] == 1)]\ndefog = defog.iloc[:, :7]","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:49:59.157708Z","iopub.execute_input":"2024-02-02T11:49:59.157975Z","iopub.status.idle":"2024-02-02T11:49:59.721755Z","shell.execute_reply.started":"2024-02-02T11:49:59.157952Z","shell.execute_reply":"2024-02-02T11:49:59.720841Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"defog.describe()","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:49:59.723102Z","iopub.execute_input":"2024-02-02T11:49:59.723622Z","iopub.status.idle":"2024-02-02T11:50:01.284860Z","shell.execute_reply.started":"2024-02-02T11:49:59.723596Z","shell.execute_reply":"2024-02-02T11:50:01.284072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"merged = pd.concat([tdcsfog, defog], axis = 0)\nmerged","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:50:01.289900Z","iopub.execute_input":"2024-02-02T11:50:01.290161Z","iopub.status.idle":"2024-02-02T11:50:01.347139Z","shell.execute_reply.started":"2024-02-02T11:50:01.290139Z","shell.execute_reply":"2024-02-02T11:50:01.346293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_merged = merged.iloc[:, 0:4]  # input features\nX = tdcsfog.iloc[:, 0:4]  # input features\ny1 = merged['StartHesitation']  # target variable for StartHesitation\ny2 = merged['Turn']  # target variable for Turn\ny3 = tdcsfog['Walking']  # target variable for Walking","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:50:01.348104Z","iopub.execute_input":"2024-02-02T11:50:01.348950Z","iopub.status.idle":"2024-02-02T11:50:01.755000Z","shell.execute_reply.started":"2024-02-02T11:50:01.348927Z","shell.execute_reply":"2024-02-02T11:50:01.754095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y1_zeros = np.where(y1 == 0)[0]\ny1_ones = np.where(y1 == 1)[0]\n\nnum1_ones = (y1 == 1).sum()\nnp.random.seed(42)\ny1_zeros = np.random.choice(np.where(y1 == 0)[0], size = num1_ones, replace = False)\ny1_balanced_idxs = np.sort(np.concatenate([y1_zeros, y1_ones]))\n\n# Use the balanced indices to get the corresponding rows of X and y1.\nX1_balanced = X_merged.iloc[y1_balanced_idxs, :]\ny1_balanced = y1.iloc[y1_balanced_idxs]","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:50:01.756298Z","iopub.execute_input":"2024-02-02T11:50:01.756629Z","iopub.status.idle":"2024-02-02T11:50:02.393032Z","shell.execute_reply.started":"2024-02-02T11:50:01.756601Z","shell.execute_reply":"2024-02-02T11:50:02.392079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y2_zeros = np.where(y2 == 0)[0]\ny2_ones = np.where(y2 == 1)[0]\n\nnum2_ones = (y2 == 1).sum()\nnp.random.seed(42)\ny2_zeros = np.random.choice(np.where(y2 == 0)[0], size = num2_ones, replace = False)\n\ny2_balanced_idxs = np.sort(np.concatenate([y2_zeros, y2_ones]))\n\n# Use the balanced indices to get the corresponding rows of X and y1.\nX2_balanced = X_merged.iloc[y2_balanced_idxs, :]\ny2_balanced = y2.iloc[y2_balanced_idxs]\n","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:50:02.395607Z","iopub.execute_input":"2024-02-02T11:50:02.395864Z","iopub.status.idle":"2024-02-02T11:50:03.338338Z","shell.execute_reply.started":"2024-02-02T11:50:02.395840Z","shell.execute_reply":"2024-02-02T11:50:03.337110Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y3_zeros = np.where(y3 == 0)[0]\ny3_ones = np.where(y3 == 1)[0]\n\nnum3_ones = (y3 == 1).sum()\nnp.random.seed(42)\ny3_zeros = np.random.choice(np.where(y3 == 0)[0], size = num3_ones, replace = False)\n\ny3_balanced_idxs = np.sort(np.concatenate([y3_zeros, y3_ones]))\n\n# Use the balanced indices to get the corresponding rows of X and y3.\nX3_balanced = X.iloc[y3_balanced_idxs, :]\ny3_balanced = y3.iloc[y3_balanced_idxs]","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:50:03.339433Z","iopub.execute_input":"2024-02-02T11:50:03.339671Z","iopub.status.idle":"2024-02-02T11:50:03.701434Z","shell.execute_reply.started":"2024-02-02T11:50:03.339649Z","shell.execute_reply":"2024-02-02T11:50:03.700376Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\nX1_train, X1_test, y1_train, y1_test = train_test_split(X1_balanced, y1_balanced, test_size = 0.2, random_state = 42)\nX2_train, X2_test, y2_train, y2_test = train_test_split(X2_balanced, y2_balanced, test_size = 0.2, random_state = 42)\nX3_train, X3_test, y3_train, y3_test = train_test_split(X3_balanced, y3_balanced, test_size = 0.2, random_state = 42)","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:50:03.702858Z","iopub.execute_input":"2024-02-02T11:50:03.703492Z","iopub.status.idle":"2024-02-02T11:50:04.641168Z","shell.execute_reply.started":"2024-02-02T11:50:03.703452Z","shell.execute_reply":"2024-02-02T11:50:04.640157Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import StandardScaler\n\n# Standardize the independent variables.\nscaler1 = StandardScaler()\nX1_train = scaler1.fit_transform(X1_train)\nX1_test = scaler1.transform(X1_test)\n\nscaler2 = StandardScaler()\nX2_train = scaler2.fit_transform(X2_train)\nX2_test = scaler2.transform(X2_test)\n\nscaler3 = StandardScaler()\nX3_train = scaler3.fit_transform(X3_train)\nX3_test = scaler3.transform(X3_test)","metadata":{"execution":{"iopub.status.busy":"2024-02-02T11:50:04.642284Z","iopub.execute_input":"2024-02-02T11:50:04.642543Z","iopub.status.idle":"2024-02-02T11:50:04.915453Z","shell.execute_reply.started":"2024-02-02T11:50:04.642520Z","shell.execute_reply":"2024-02-02T11:50:04.914272Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\n\n# Create models.\nmodel1 = RandomForestClassifier(n_estimators = 20, random_state=42, n_jobs=-1)\nmodel2 = RandomForestClassifier(n_estimators = 20, random_state=42,n_jobs=-1)\nmodel3 = RandomForestClassifier(n_estimators = 20, random_state=42,n_jobs=-1)\n\n\nmodel1.fit(X1_train, y1_train)\nmodel2.fit(X2_train, y2_train)\nmodel3.fit(X3_train, y3_train)\n\n\nprint('Accuracy for StartHesitation:', model1.score(X1_test, y1_test))\nprint('Accuracy for Turn:', model2.score(X2_test, y2_test))\nprint('Accuracy for Walking:', model3.score(X3_test, y3_test))","metadata":{"execution":{"iopub.status.busy":"2024-02-02T12:24:32.284521Z","iopub.execute_input":"2024-02-02T12:24:32.284965Z","iopub.status.idle":"2024-02-02T12:27:23.030882Z","shell.execute_reply.started":"2024-02-02T12:24:32.284933Z","shell.execute_reply":"2024-02-02T12:27:23.030051Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import classification_report, confusion_matrix\n\n# Get the predictions for the three models on the test data.\ny1_pred = model1.predict(X1_test)\ny2_pred = model2.predict(X2_test)\ny3_pred = model3.predict(X3_test)\n\n# Create a classification report for each model.\nprint('Classification Report for StartHesitation:')\nprint(classification_report(y1_test, y1_pred))\n\nprint('Classification Report for Turn:')\nprint(classification_report(y2_test, y2_pred))\n\nprint('Classification Report for Walking:')\nprint(classification_report(y3_test, y3_pred))\n\n# Create a confusion matrix for each model.\nprint('Confusion Matrix for StartHesitation:')\nprint(confusion_matrix(y1_test, y1_pred))\n\nprint('Confusion Matrix for Turn:')\nprint(confusion_matrix(y2_test, y2_pred))\n\nprint('Confusion Matrix for Walking:')\nprint(confusion_matrix(y3_test, y3_pred))","metadata":{"execution":{"iopub.status.busy":"2024-02-02T12:33:14.327700Z","iopub.execute_input":"2024-02-02T12:33:14.328077Z","iopub.status.idle":"2024-02-02T12:33:20.900753Z","shell.execute_reply.started":"2024-02-02T12:33:14.328047Z","shell.execute_reply":"2024-02-02T12:33:20.899567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tdcsfog_test_path = '/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/test/tdcsfog'\n\ntdcsfog_test_list = []\n\n# 128 Hz\nfor file_name in os.listdir(tdcsfog_test_path):\n    if file_name.endswith('.csv'):\n        file_path = os.path.join(tdcsfog_test_path, file_name)\n        file = pd.read_csv(file_path)\n        file['Id'] = file_name[:-4] + '_' + file['Time'].apply(str)\n        file.Time = file.Time / 128\n        tdcsfog_test_list.append(file)\n\ntdcsfog_test = pd.concat(tdcsfog_test_list, axis = 0)\n\ntdcsfog_test","metadata":{"execution":{"iopub.status.busy":"2024-02-02T12:43:29.279393Z","iopub.execute_input":"2024-02-02T12:43:29.279947Z","iopub.status.idle":"2024-02-02T12:43:29.302678Z","shell.execute_reply.started":"2024-02-02T12:43:29.279895Z","shell.execute_reply":"2024-02-02T12:43:29.301856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tdcsfog_test = reduce_memory_usage(tdcsfog_test)","metadata":{"execution":{"iopub.status.busy":"2024-02-02T12:43:37.245921Z","iopub.execute_input":"2024-02-02T12:43:37.246333Z","iopub.status.idle":"2024-02-02T12:43:37.262077Z","shell.execute_reply.started":"2024-02-02T12:43:37.246299Z","shell.execute_reply":"2024-02-02T12:43:37.261049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"defog_test_path = '/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/test/defog'\n\ndefog_test_list = []\n\n# 100 hz\nfor file_name in os.listdir(defog_test_path):\n    if file_name.endswith('.csv'):\n        file_path = os.path.join(defog_test_path, file_name)\n        file = pd.read_csv(file_path)\n        file['Id'] = file_name[:-4] + '_' + file['Time'].apply(str)\n        file.Time = file.Time / 100\n        defog_test_list.append(file)\n\ndefog_test = pd.concat(defog_test_list, axis = 0)\n\ndefog_test","metadata":{"execution":{"iopub.status.busy":"2024-02-02T12:43:52.300471Z","iopub.execute_input":"2024-02-02T12:43:52.300833Z","iopub.status.idle":"2024-02-02T12:43:52.506120Z","shell.execute_reply.started":"2024-02-02T12:43:52.300804Z","shell.execute_reply":"2024-02-02T12:43:52.505306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"defog_test = reduce_memory_usage(defog_test)","metadata":{"execution":{"iopub.status.busy":"2024-02-02T12:43:59.665911Z","iopub.execute_input":"2024-02-02T12:43:59.666299Z","iopub.status.idle":"2024-02-02T12:43:59.947187Z","shell.execute_reply.started":"2024-02-02T12:43:59.666271Z","shell.execute_reply":"2024-02-02T12:43:59.946195Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = pd.concat([tdcsfog_test, defog_test], axis = 0).reset_index(drop = True)\ntest","metadata":{"execution":{"iopub.status.busy":"2024-02-02T12:44:07.223762Z","iopub.execute_input":"2024-02-02T12:44:07.224099Z","iopub.status.idle":"2024-02-02T12:44:07.345694Z","shell.execute_reply.started":"2024-02-02T12:44:07.224073Z","shell.execute_reply":"2024-02-02T12:44:07.344852Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Separate the dataset for the independent variables.\ntest_X = test.iloc[:, 0:4]\n\n# Standardize the independent variables by a new scaler.\nscaler = StandardScaler()\nscaler.fit(test_X)\ntest_X = scaler.transform(test_X)\n\npred_y1 = model1.predict(test_X)\npred_y2 = model2.predict(test_X)\npred_y3 = model3.predict(test_X)\n\ntest['StartHesitation'] = pred_y1 # target variable for StartHesitation\ntest['Turn'] = pred_y2 # target variable for Turn\ntest['Walking'] = pred_y3 # target variable for Walking\n\npred_proba_y1 = model1.predict_proba(test_X)[:, 1]\npred_proba_y2 = model2.predict_proba(test_X)[:, 1]\npred_proba_y3 = model3.predict_proba(test_X)[:, 1]\n\n# Update the values in the test dataframe.\ntest['StartHesitation'] = pred_proba_y1\ntest['Turn'] = pred_proba_y2\ntest['Walking'] = pred_proba_y3\n\ntest","metadata":{"execution":{"iopub.status.busy":"2024-02-02T12:44:22.784521Z","iopub.execute_input":"2024-02-02T12:44:22.784870Z","iopub.status.idle":"2024-02-02T12:44:23.735340Z","shell.execute_reply.started":"2024-02-02T12:44:22.784846Z","shell.execute_reply":"2024-02-02T12:44:23.734245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = test.iloc[:, 4:].fillna(0.0)\nsubmission['StartHesitation'] = (submission['StartHesitation']>=0.5).astype(int)\nsubmission['Turn'] = (submission['Turn']>=0.5).astype(int)\nsubmission['Walking'] = (submission['Walking']>=0.5).astype(int)\nsubmission","metadata":{"execution":{"iopub.status.busy":"2024-02-02T12:50:52.893150Z","iopub.execute_input":"2024-02-02T12:50:52.893496Z","iopub.status.idle":"2024-02-02T12:50:52.928697Z","shell.execute_reply.started":"2024-02-02T12:50:52.893461Z","shell.execute_reply":"2024-02-02T12:50:52.927905Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv(\"submission.csv\", index = False)","metadata":{"execution":{"iopub.status.busy":"2024-02-02T12:55:03.479158Z","iopub.execute_input":"2024-02-02T12:55:03.479497Z","iopub.status.idle":"2024-02-02T12:55:03.849563Z","shell.execute_reply.started":"2024-02-02T12:55:03.479471Z","shell.execute_reply":"2024-02-02T12:55:03.848638Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"My notebook: https://www.kaggle.com/code/xiyuhou/notebookcd099604df","metadata":{}}]}