{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","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":30698,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Data Science for Neuroscience - Final Project - Group 3\n> ## Parkinson - FOG Classification\n> by Arna, Cristian, Kryst, Kseniia and Nele","metadata":{}},{"cell_type":"code","source":"# importing all the libraries\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport warnings\nimport os\nimport pywt\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.metrics import accuracy_score\nfrom sklearn import metrics\nfrom sklearn.metrics import accuracy_score, classification_report\nfrom sklearn.model_selection import train_test_split\nfrom scipy import signal\nfrom imblearn.over_sampling import SMOTE\n\n\nimport lightgbm as lgb\n\n\n#to remove warnings\nwarnings.filterwarnings(action = \"ignore\", category = DeprecationWarning ) \nwarnings.filterwarnings(action = \"ignore\", category = FutureWarning ) ","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-08-25T21:20:47.451664Z","iopub.execute_input":"2024-08-25T21:20:47.452114Z","iopub.status.idle":"2024-08-25T21:20:47.92149Z","shell.execute_reply.started":"2024-08-25T21:20:47.45208Z","shell.execute_reply":"2024-08-25T21:20:47.919761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 1. Data Exploration\n> ### a. Load Data","metadata":{}},{"cell_type":"code","source":"tdcsfog_path = '/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/tdcsfog'\ntdcsfog_list = []\n\n# iterate over each file in the directory\nfor file_name in os.listdir(tdcsfog_path):\n    # exclude this file because it is also in the test set\n    if file_name.endswith('.csv') and file_name != '003f117e14.csv': \n        file_path = os.path.join(tdcsfog_path, file_name)\n        df = pd.read_csv(file_path)\n        \n        # add a new column with the file name without the .csv extension\n        df['file_name'] = file_name[:-4]\n        \n        tdcsfog_list.append(df)\n\ntdcsfog = pd.concat(tdcsfog_list, ignore_index=True)\n\n# create 'IsFOG' column based on any non-zero value in 'StartHesitation', 'Walking', 'Turn' columns\ntdcsfog['IsFOG'] = tdcsfog[['StartHesitation', 'Walking', 'Turn']].any(axis='columns')\n\ntdcsfog.head()","metadata":{"execution":{"iopub.status.busy":"2024-08-25T20:14:24.089369Z","iopub.execute_input":"2024-08-25T20:14:24.089916Z","iopub.status.idle":"2024-08-25T20:14:35.544081Z","shell.execute_reply.started":"2024-08-25T20:14:24.089877Z","shell.execute_reply":"2024-08-25T20:14:35.542841Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# merge the dataframes based on matching 'file_name' in tdcsfog and 'id' in tdcsfog_metadata\ntdcsfog_metadata = pd.read_csv('/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/tdcsfog_metadata.csv')\ntdcsfog = tdcsfog.merge(tdcsfog_metadata[['Id', 'Subject']], left_on='file_name', right_on='Id', how='left')\n\ntdcsfog = tdcsfog.rename(columns={'Subject': 'subject'})\ntdcsfog = tdcsfog.drop(columns=['Id'])","metadata":{"execution":{"iopub.status.busy":"2024-08-25T20:15:36.824503Z","iopub.execute_input":"2024-08-25T20:15:36.824993Z","iopub.status.idle":"2024-08-25T20:15:41.322792Z","shell.execute_reply.started":"2024-08-25T20:15:36.824957Z","shell.execute_reply":"2024-08-25T20:15:41.320394Z"},"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# iterate over each file in the directory\nfor file_name in os.listdir(defog_path):\n    # exclude this file because it is also in the test set\n    if file_name.endswith('.csv') and file_name != '003f117e14.csv': \n        file_path = os.path.join(defog_path, file_name)\n        df = pd.read_csv(file_path)\n        df = df.drop(columns = ['Valid', 'Task'], errors = 'ignore')\n        df['file_name'] = file_name[:-4]\n        defog_list.append(df)\n\ndefog = pd.concat(defog_list, ignore_index=True)\n\n# create 'IsFOG' column based on any non-zero value in 'StartHesitation', 'Walking', 'Turn' columns\ndefog['IsFOG'] = defog[['StartHesitation', 'Walking', 'Turn']].any(axis='columns')\n\n# Display the first few rows of the DataFrame\ndefog.head()","metadata":{"execution":{"iopub.status.busy":"2024-08-25T20:18:07.77776Z","iopub.execute_input":"2024-08-25T20:18:07.778289Z","iopub.status.idle":"2024-08-25T20:18:36.932874Z","shell.execute_reply.started":"2024-08-25T20:18:07.778243Z","shell.execute_reply":"2024-08-25T20:18:36.93168Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# merge the dataframes based on matching 'file_name' in tdcsfog and 'id' in tdcsfog_metadata\ndefog_metadata = pd.read_csv('/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/defog_metadata.csv')\ndefog = defog.merge(defog_metadata[['Id', 'Subject']], left_on='file_name', right_on='Id', how='left')\n\ndefog = defog.rename(columns={'Subject': 'subject'})\ndefog = defog.drop(columns=['Id'])\n","metadata":{"execution":{"iopub.status.busy":"2024-08-25T20:19:46.63337Z","iopub.execute_input":"2024-08-25T20:19:46.633806Z","iopub.status.idle":"2024-08-25T20:19:54.988961Z","shell.execute_reply.started":"2024-08-25T20:19:46.633776Z","shell.execute_reply":"2024-08-25T20:19:54.987398Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> ### b. Feature Engineering: Bandpass Filter ","metadata":{}},{"cell_type":"code","source":"def bandpass_filter(data, lowcut, highcut, fs, order=2):\n    '''\n    function which does a bandpass filter on specific frequencies and \n    therefore only keeps a specific frequency (range) in the signal\n    \n    input: \n    - data: input data\n    - lowcut: lower cutoff frequency\n    - highcut: higher cutoff frequency \n    - fs: samling rate\n    - order: order of filter, defines steepness\n    '''\n    \n    # normalize cutoff frequency to the nqyquist frequency\n    nyquist = 0.5 * fs\n    low = lowcut / nyquist\n    high = highcut / nyquist\n    \n    # butterworth bandpass filter\n    b, a = signal.butter(order, [low, high], btype='band')\n    # filters data along each row \n    filtered_data = np.apply_along_axis(lambda m: signal.lfilter(b, a, m), axis=1, arr=data)\n    return filtered_data\n\n# sampling frequencies for tDCSFOG and DeFOG data\nsampling_freq_tdcsfog = 128  \nsampling_freq_defog = 100    \n\n# define bandpass filters for delta, theta, alpha bands for tDCS FOG\ndef bandpass_delta(data, fs=sampling_freq_tdcsfog):\n    return bandpass_filter(data, lowcut=0.5, highcut=4, fs=fs)\n\ndef bandpass_theta(data, fs=sampling_freq_tdcsfog):\n    return bandpass_filter(data, lowcut=4, highcut=8, fs=fs)\n\ndef bandpass_alpha(data, fs=sampling_freq_tdcsfog):\n    return bandpass_filter(data, lowcut=8, highcut=16, fs=fs)","metadata":{"execution":{"iopub.status.busy":"2024-08-25T20:33:08.815489Z","iopub.execute_input":"2024-08-25T20:33:08.817752Z","iopub.status.idle":"2024-08-25T20:33:08.83545Z","shell.execute_reply.started":"2024-08-25T20:33:08.817683Z","shell.execute_reply":"2024-08-25T20:33:08.833773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sampling_freq_tdcsfog = 128  \nsampling_freq_defog = 100\n\n# Calculate the sampling periods\nsampling_period_tdcsfog = 1 / sampling_freq_tdcsfog\nsampling_period_defog = 1 / sampling_freq_defog","metadata":{"execution":{"iopub.status.busy":"2024-08-25T20:33:18.409395Z","iopub.execute_input":"2024-08-25T20:33:18.409917Z","iopub.status.idle":"2024-08-25T20:33:18.417108Z","shell.execute_reply.started":"2024-08-25T20:33:18.409882Z","shell.execute_reply":"2024-08-25T20:33:18.415496Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# applies bandpass to tdcsfog data\ntdcsfog_results = pd.DataFrame()\n\nfor file_name in tdcsfog['file_name'].unique():\n    subject = tdcsfog[tdcsfog['file_name'] == file_name].copy()\n    \n    # filter for delta, theta, alpha bands\n    subject['AccML_delta'] = bandpass_delta(subject[['AccML']].values.T, sampling_freq_tdcsfog).T.flatten()\n    subject['AccML_theta'] = bandpass_theta(subject[['AccML']].values.T, sampling_freq_tdcsfog).T.flatten()\n    subject['AccML_alpha'] = bandpass_alpha(subject[['AccML']].values.T, sampling_freq_tdcsfog).T.flatten()\n\n    subject['AccAP_delta'] = bandpass_delta(subject[['AccAP']].values.T, sampling_freq_tdcsfog).T.flatten()\n    subject['AccAP_theta'] = bandpass_theta(subject[['AccAP']].values.T, sampling_freq_tdcsfog).T.flatten()\n    subject['AccAP_alpha'] = bandpass_alpha(subject[['AccAP']].values.T, sampling_freq_tdcsfog).T.flatten()\n\n    subject['AccV_delta'] = bandpass_delta(subject[['AccV']].values.T, sampling_freq_tdcsfog).T.flatten()\n    subject['AccV_theta'] = bandpass_theta(subject[['AccV']].values.T, sampling_freq_tdcsfog).T.flatten()\n    subject['AccV_alpha'] = bandpass_alpha(subject[['AccV']].values.T, sampling_freq_tdcsfog).T.flatten()\n    \n    # prepares data frame\n    subject_results = pd.DataFrame({\n        'Time': subject['Time'], \n        'AccML': subject['AccML'],\n        'AccAP': subject['AccAP'],\n        'AccV': subject['AccV'],\n        'AccML_delta': subject['AccML_delta'],\n        'AccML_theta': subject['AccML_theta'],\n        'AccML_alpha': subject['AccML_alpha'],\n        'AccAP_delta': subject['AccAP_delta'],\n        'AccAP_theta': subject['AccAP_theta'],\n        'AccAP_alpha': subject['AccAP_alpha'],\n        'AccV_delta': subject['AccV_delta'],\n        'AccV_theta': subject['AccV_theta'],\n        'AccV_alpha': subject['AccV_alpha'],\n    })\n    \n    tdcsfog_results = pd.concat([tdcsfog_results, subject_results], ignore_index=True)\n\nprint(\"Feature extraction and filtering completed and saved.\")","metadata":{"execution":{"iopub.status.busy":"2024-08-25T20:33:29.140733Z","iopub.execute_input":"2024-08-25T20:33:29.141358Z","iopub.status.idle":"2024-08-25T20:55:36.558897Z","shell.execute_reply.started":"2024-08-25T20:33:29.141307Z","shell.execute_reply":"2024-08-25T20:55:36.557685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"defog_results = pd.DataFrame()\n\nfor file_name in defog['file_name'].unique():\n    subject = defog[defog['file_name'] == file_name].copy()\n    \n     # filter for delta, theta, alpha bands\n    subject['AccML_delta'] = bandpass_delta(subject[['AccML']].values.T, sampling_freq_defog).T.flatten()\n    subject['AccML_theta'] = bandpass_theta(subject[['AccML']].values.T, sampling_freq_defog).T.flatten()\n    subject['AccML_alpha'] = bandpass_alpha(subject[['AccML']].values.T, sampling_freq_defog).T.flatten()\n\n    subject['AccAP_delta'] = bandpass_delta(subject[['AccAP']].values.T, sampling_freq_defog).T.flatten()\n    subject['AccAP_theta'] = bandpass_theta(subject[['AccAP']].values.T, sampling_freq_defog).T.flatten()\n    subject['AccAP_alpha'] = bandpass_alpha(subject[['AccAP']].values.T, sampling_freq_defog).T.flatten()\n\n    subject['AccV_delta'] = bandpass_delta(subject[['AccV']].values.T, sampling_freq_defog).T.flatten()\n    subject['AccV_theta'] = bandpass_theta(subject[['AccV']].values.T, sampling_freq_defog).T.flatten()\n    subject['AccV_alpha'] = bandpass_alpha(subject[['AccV']].values.T, sampling_freq_defog).T.flatten()\n    \n    # prepare data frame\n    subject_results = pd.DataFrame({\n        'Time': subject['Time'], \n        'AccML': subject['AccML'],\n        'AccAP': subject['AccAP'],\n        'AccV': subject['AccV'],\n        'AccML_delta': subject['AccML_delta'],\n        'AccML_theta': subject['AccML_theta'],\n        'AccML_alpha': subject['AccML_alpha'],\n        'AccAP_delta': subject['AccAP_delta'],\n        'AccAP_theta': subject['AccAP_theta'],\n        'AccAP_alpha': subject['AccAP_alpha'],\n        'AccV_delta': subject['AccV_delta'],\n        'AccV_theta': subject['AccV_theta'],\n        'AccV_alpha': subject['AccV_alpha'],\n    })\n    \n    defog_results = pd.concat([defog_results, subject_results], ignore_index=True)\n\nprint(\"Feature extraction and filtering completed and saved.\")","metadata":{"execution":{"iopub.status.busy":"2024-08-25T20:55:36.560992Z","iopub.execute_input":"2024-08-25T20:55:36.561373Z","iopub.status.idle":"2024-08-25T21:00:11.569015Z","shell.execute_reply.started":"2024-08-25T20:55:36.561344Z","shell.execute_reply":"2024-08-25T21:00:11.567801Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# features \ntdcsfog_results = tdcsfog_results[['AccML_delta', 'AccML_theta', 'AccML_alpha', \n                                   'AccAP_delta', 'AccAP_theta', 'AccAP_alpha', \n                                   'AccV_delta', 'AccV_theta', 'AccV_alpha', \n                                   ]]\ndefog_results = defog_results[['AccML_delta', 'AccML_theta', 'AccML_alpha', \n                               'AccAP_delta', 'AccAP_theta', 'AccAP_alpha', \n                               'AccV_delta', 'AccV_theta', 'AccV_alpha', \n                               ]]","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:00:11.570452Z","iopub.execute_input":"2024-08-25T21:00:11.570829Z","iopub.status.idle":"2024-08-25T21:00:12.075089Z","shell.execute_reply.started":"2024-08-25T21:00:11.570797Z","shell.execute_reply":"2024-08-25T21:00:12.073847Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# combined with the original data set\ndefog = pd.concat([defog, defog_results], axis=1)\n\ntdcsfog =pd.concat([tdcsfog, tdcsfog_results], axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:00:12.078119Z","iopub.execute_input":"2024-08-25T21:00:12.078535Z","iopub.status.idle":"2024-08-25T21:00:13.871964Z","shell.execute_reply.started":"2024-08-25T21:00:12.078501Z","shell.execute_reply":"2024-08-25T21:00:13.870844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 2. Data Splitting","metadata":{}},{"cell_type":"code","source":"train_data_list = []\ntest_data_list = []\n\n# group subject and process each group\nfor subject, group in tdcsfog.groupby('subject'):\n    \n    split_index = int(0.8 * len(group))\n    \n    train_subject_data = group.iloc[:split_index]\n    test_subject_data = group.iloc[-(len(group) - split_index):]\n    \n    train_data_list.append(train_subject_data)\n    test_data_list.append(test_subject_data)\n\ntrain_data_tdcsfog = pd.concat(train_data_list)\ntest_data_tdcsfog = pd.concat(test_data_list)\n\nprint(f'Train data rows: {len(train_data_tdcsfog)}')\nprint(f'Test data rows: {len(test_data_tdcsfog)}')","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data_list = []\ntest_data_list = []\n\nfor subject, group in defog.groupby('subject'):\n    \n    split_index = int(0.8 * len(group))\n    \n    train_subject_data = group.iloc[:split_index]\n    test_subject_data = group.iloc[-(len(group) - split_index):]\n    \n    train_data_list.append(train_subject_data)\n    test_data_list.append(test_subject_data)\n\ntrain_data_defog = pd.concat(train_data_list)\ntest_data_defog = pd.concat(test_data_list)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 3. First Model - Fog Identification\n> In order to detect fog events, such as start hesitation, turning or walking, within the dataset, we first construct a model that is designed to detect the occurrence of any fog event. This task is essentially binary, where the model is trained to detect fog events over nonfog events (indicated by a value of 1 in either start hesitation, turning or walking) using a random forest algorithm, specifically LightGBM in our case.","metadata":{}},{"cell_type":"code","source":"train_features_tdcsfog = train_data_tdcsfog[['Time','AccML_delta', 'AccML_theta', 'AccML_alpha',\n    'AccAP_delta', 'AccAP_theta', 'AccAP_alpha',\n    'AccV_delta', 'AccV_theta', 'AccV_alpha']]\ntest_features_tdcsfog = test_data_tdcsfog[['Time','AccML_delta', 'AccML_theta', 'AccML_alpha',\n    'AccAP_delta', 'AccAP_theta', 'AccAP_alpha',\n    'AccV_delta', 'AccV_theta', 'AccV_alpha']]\n\ntrain_labels_tdcsfog = train_data_tdcsfog['IsFOG']\ntest_labels_tdcsfog = test_data_tdcsfog['IsFOG']\n\n# create LightGBM datasets\ntrain_dataset_tdcsfog = lgb.Dataset(train_features_tdcsfog, label=train_labels_tdcsfog)\ntest_dataset_tdcsfog = lgb.Dataset(test_features_tdcsfog, label=test_labels_tdcsfog)","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:00:20.305985Z","iopub.execute_input":"2024-08-25T21:00:20.306321Z","iopub.status.idle":"2024-08-25T21:00:20.565605Z","shell.execute_reply.started":"2024-08-25T21:00:20.306293Z","shell.execute_reply":"2024-08-25T21:00:20.564527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_features_defog = train_data_defog[['Time','AccML_delta', 'AccML_theta', 'AccML_alpha',\n    'AccAP_delta', 'AccAP_theta', 'AccAP_alpha',\n    'AccV_delta', 'AccV_theta', 'AccV_alpha']]\ntest_features_defog = test_data_defog[['Time','AccML_delta', 'AccML_theta', 'AccML_alpha',\n    'AccAP_delta', 'AccAP_theta', 'AccAP_alpha',\n    'AccV_delta', 'AccV_theta', 'AccV_alpha']]\n\n\ntrain_labels_defog = train_data_defog['IsFOG']\ntest_labels_defog = test_data_defog['IsFOG']\n\n# create LightGBM datasets\ntrain_dataset_defog = lgb.Dataset(train_features_defog, label=train_labels_defog)\ntest_dataset_defog = lgb.Dataset(test_features_defog, label=test_labels_defog)\n","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:06:32.049143Z","iopub.execute_input":"2024-08-25T21:06:32.049811Z","iopub.status.idle":"2024-08-25T21:06:32.570363Z","shell.execute_reply.started":"2024-08-25T21:06:32.04977Z","shell.execute_reply":"2024-08-25T21:06:32.569019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fog_params={\n    'objective': 'binary', #binary target feature\n    'metric': 'auc', \n    'boosting_type': 'gbdt',  #GradientBoostingDecisionTree\n    'learning_rate': 0.18,\n    'verbose': 1,\n    'max_depth': 10,\n    'num_leaves': 80,\n    'is_unbalance':True\n}\n\n# train the LightGBM model\nnum_round = 200  \n\nfog_model_tdcsfog = lgb.train(fog_params, train_dataset_tdcsfog, num_round, valid_sets=[test_dataset_tdcsfog])\n\n# predictions\ny_pred_tdcsfog = fog_model_tdcsfog.predict(test_features_tdcsfog, num_iteration=fog_model_tdcsfog.best_iteration)\n\n# convert probabilities to binary predictions\ny_pred_binary_tdcsfog = (y_pred_tdcsfog > 0.5).astype(int)\n\naccuracy = metrics.accuracy_score(test_labels_tdcsfog, y_pred_binary_tdcsfog)\nprint(f\"Accuracy: {accuracy}\")","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:06:32.603391Z","iopub.execute_input":"2024-08-25T21:06:32.603922Z","iopub.status.idle":"2024-08-25T21:07:59.388371Z","shell.execute_reply.started":"2024-08-25T21:06:32.603884Z","shell.execute_reply":"2024-08-25T21:07:59.386804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fog_params={\n    'objective': 'binary', #binary target feature\n    'metric': 'auc', \n    'boosting_type': 'gbdt',  #GradientBoostingDecisionTree\n    'learning_rate': 0.18,\n    'verbose': 1,\n    'max_depth': 10,\n    'num_leaves': 80,\n    'is_unbalance':True\n}\n# train the LightGBM model\nnum_round = 200  \n\nfog_model_defog = lgb.train(fog_params, train_dataset_defog, num_round, valid_sets=[test_dataset_defog])\n\n# predictions\ny_pred_defog = fog_model_defog.predict(test_features_defog, num_iteration=fog_model_defog.best_iteration)\n\n# convert probabilities to binary predictions\ny_pred_binary_defog = (y_pred_defog > 0.5).astype(int)\n\n# evaluate the model\naccuracy_defog = metrics.accuracy_score(test_labels_defog, y_pred_binary_defog)\nprint(f\"Accuracy: {accuracy_defog}\")","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:07:59.394153Z","iopub.execute_input":"2024-08-25T21:07:59.394618Z","iopub.status.idle":"2024-08-25T21:10:38.544116Z","shell.execute_reply.started":"2024-08-25T21:07:59.394574Z","shell.execute_reply":"2024-08-25T21:10:38.542741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 4. Second Model - FOG Classification\n> Now, we build another model, which classifies the three different fog events.\n\n### a. Data Preparation\n- split train data into the three different fog events: start hesitation, turn and walking\n- balance data \n","metadata":{}},{"cell_type":"code","source":"targets = [\"StartHesitation\", \"Turn\", 'Walking', 'IsFOG', 'file_name','subject']","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:10:38.545904Z","iopub.execute_input":"2024-08-25T21:10:38.546422Z","iopub.status.idle":"2024-08-25T21:10:38.55313Z","shell.execute_reply.started":"2024-08-25T21:10:38.546378Z","shell.execute_reply":"2024-08-25T21:10:38.551828Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data_tdcsfog_cl = train_data_tdcsfog[train_data_tdcsfog['IsFOG'] == True]\ntest_data_tdcsfog_cl = test_data_tdcsfog[test_data_tdcsfog['IsFOG'] == True]","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:10:38.556981Z","iopub.execute_input":"2024-08-25T21:10:38.558073Z","iopub.status.idle":"2024-08-25T21:10:38.799186Z","shell.execute_reply.started":"2024-08-25T21:10:38.558027Z","shell.execute_reply":"2024-08-25T21:10:38.797842Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data_defog_cl = train_data_defog[train_data_defog['IsFOG'] == True]\ntest_data_defog_cl = test_data_defog[test_data_defog['IsFOG'] == True]","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:10:38.800639Z","iopub.execute_input":"2024-08-25T21:10:38.801Z","iopub.status.idle":"2024-08-25T21:10:38.89482Z","shell.execute_reply.started":"2024-08-25T21:10:38.80097Z","shell.execute_reply":"2024-08-25T21:10:38.892986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# features\nX_train_tdcsfog = train_data_tdcsfog_cl.drop(targets, axis=1)\nX_test_tdcsfog = test_data_tdcsfog_cl.drop(targets, axis=1) \n\n# split data into the three classes\ny1_train_tdcsfog = train_data_tdcsfog_cl[['StartHesitation', 'Turn','Walking']]\ny1_test_tdcsfog = test_data_tdcsfog_cl[['StartHesitation', 'Turn','Walking']]","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:10:38.896871Z","iopub.execute_input":"2024-08-25T21:10:38.89739Z","iopub.status.idle":"2024-08-25T21:10:39.015197Z","shell.execute_reply.started":"2024-08-25T21:10:38.897349Z","shell.execute_reply":"2024-08-25T21:10:39.014092Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# features\nX_train_defog = train_data_defog_cl.drop(targets, axis=1) \nX_test_defog = test_data_defog_cl.drop(targets, axis=1)  \n\n# split data into the three classes\ny1_train_defog = train_data_defog_cl[['StartHesitation', 'Turn','Walking']]\ny1_test_defog = test_data_defog_cl[['StartHesitation', 'Turn','Walking']]","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:10:39.017073Z","iopub.execute_input":"2024-08-25T21:10:39.017546Z","iopub.status.idle":"2024-08-25T21:10:39.064915Z","shell.execute_reply.started":"2024-08-25T21:10:39.017508Z","shell.execute_reply":"2024-08-25T21:10:39.063762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_StartHesitation_tdcsfog_train = y1_train_tdcsfog['StartHesitation']\ny_Turn_tdcsfog_train = y1_train_tdcsfog['Turn']\ny_Walking_tdcsfog_train = y1_train_tdcsfog['Walking']\n\ny_StartHesitation_tdcsfog_test = y1_test_tdcsfog['StartHesitation']\ny_Turn_tdcsfog_test = y1_test_tdcsfog['Turn']\ny_Walking_tdcsfog_test = y1_test_tdcsfog['Walking']","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:10:39.066383Z","iopub.execute_input":"2024-08-25T21:10:39.06684Z","iopub.status.idle":"2024-08-25T21:10:39.074695Z","shell.execute_reply.started":"2024-08-25T21:10:39.066798Z","shell.execute_reply":"2024-08-25T21:10:39.073203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_StartHesitation_defog_train = y1_train_defog['StartHesitation']\ny_Turn_defog_train = y1_train_defog['Turn']\ny_Walking_defog_train = y1_train_defog['Walking']","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:10:39.076271Z","iopub.execute_input":"2024-08-25T21:10:39.076746Z","iopub.status.idle":"2024-08-25T21:10:39.091361Z","shell.execute_reply.started":"2024-08-25T21:10:39.076703Z","shell.execute_reply":"2024-08-25T21:10:39.090058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_StartHesitation_defog_test = y1_test_defog['StartHesitation']\ny_Turn_defog_test = y1_test_defog['Turn']\ny_Walking_defog_test = y1_test_defog['Walking']","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:10:39.095813Z","iopub.execute_input":"2024-08-25T21:10:39.096252Z","iopub.status.idle":"2024-08-25T21:10:39.105734Z","shell.execute_reply.started":"2024-08-25T21:10:39.096204Z","shell.execute_reply":"2024-08-25T21:10:39.104403Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def apply_smote(X, y):\n    '''\n    function that pplies the Synthetic Minority Over-sampling Technique (SMOTE) to balance the dataset\n    \n    input:\n    - X: input data where each row represents a sample and each column represents a feature\n    - y: output labels associated with the samples in X\n    \n    output:\n    - X_smote: feature matrix after applying SMOTE, with additional synthetic samples added to balance the classes\n    - y_smote: output labels after applying SMOTE, with corresponding labels for the new synthetic samples\n    ''' \n    \n    smote = SMOTE(random_state=42)\n    X_smote, y_smote = smote.fit_resample(X, y)\n    \n    return X_smote, y_smote","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:10:39.10739Z","iopub.execute_input":"2024-08-25T21:10:39.107794Z","iopub.status.idle":"2024-08-25T21:10:39.118163Z","shell.execute_reply.started":"2024-08-25T21:10:39.107762Z","shell.execute_reply":"2024-08-25T21:10:39.116844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# smote for tdcsfog\nX_train_tdcsfog_SH, y_StartHesitation_tdcsfog_train = apply_smote(X_train_tdcsfog, y_StartHesitation_tdcsfog_train)\nX_train_tdcsfog_T, y_Turn_tdcsfog_train = apply_smote(X_train_tdcsfog, y_Turn_tdcsfog_train)\nX_train_tdcsfog_W, y_Walking_tdcsfog_train = apply_smote(X_train_tdcsfog, y_Walking_tdcsfog_train)","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:20:54.627473Z","iopub.execute_input":"2024-08-25T21:20:54.629201Z","iopub.status.idle":"2024-08-25T21:21:10.079726Z","shell.execute_reply.started":"2024-08-25T21:20:54.62916Z","shell.execute_reply":"2024-08-25T21:21:10.078533Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# smote for defog\nX_train_defog_SH, y_StartHesitation_defog_train = apply_smote(X_train_defog, y_StartHesitation_defog_train)\nX_train_defog_T, y_Turn_defog_train = apply_smote(X_train_defog, y_Turn_defog_train)\nX_train_defog_W, y_Walking_defog_train = apply_smote(X_train_defog, y_Walking_defog_train)","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:21:10.08213Z","iopub.execute_input":"2024-08-25T21:21:10.082622Z","iopub.status.idle":"2024-08-25T21:21:13.51589Z","shell.execute_reply.started":"2024-08-25T21:21:10.082579Z","shell.execute_reply":"2024-08-25T21:21:13.514757Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# create LightGBM datasets\ntrain_dataset_defog_SH = lgb.Dataset(X_train_defog_SH, label=y_StartHesitation_defog_train)\ntest_dataset_defog_SH = lgb.Dataset(X_test_defog, label=y_StartHesitation_defog_test)\n\ntrain_dataset_defog_T = lgb.Dataset(X_train_defog_T, label=y_Turn_defog_train)\ntest_dataset_defog_T = lgb.Dataset(X_test_defog, label=y_Turn_defog_test)\n\ntrain_dataset_defog_W = lgb.Dataset(X_train_defog_W, label=y_Walking_defog_train)\ntest_dataset_defog_W = lgb.Dataset(X_test_defog, label=y_Walking_defog_test)\n\ntrain_dataset_tdcsfog_SH = lgb.Dataset(X_train_tdcsfog_SH, label=y_StartHesitation_tdcsfog_train)\ntest_dataset_tdcsfog_SH = lgb.Dataset(X_test_tdcsfog, label=y_StartHesitation_tdcsfog_test)\n\ntrain_dataset_tdcsfog_T = lgb.Dataset(X_train_tdcsfog_T, label=y_Turn_tdcsfog_train)\ntest_dataset_tdcsfog_T = lgb.Dataset(X_test_tdcsfog, label=y_Turn_tdcsfog_test)\n\ntrain_dataset_tdcsfog_W = lgb.Dataset(X_train_tdcsfog_W, label=y_Walking_tdcsfog_train)\ntest_dataset_tdcsfog_W = lgb.Dataset(X_test_tdcsfog, label=y_Walking_tdcsfog_test)\n\n# define parameters\nparams = {\n    'objective': 'binary',  \n    'eval_metric': 'auc', \n    'colsample_bytree': 0.5282057895135501,\n    'learning_rate': 0.22659963168004743,\n    'max_depth': 15,\n    'min_child_weight': 3.1233911067827616,\n    'n_estimators': 291,\n    'subsample': 0.9961057796456088,\n    'num_leaves': 150,\n}\nnum_round = 300  ","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:21:13.51719Z","iopub.execute_input":"2024-08-25T21:21:13.517556Z","iopub.status.idle":"2024-08-25T21:21:13.528779Z","shell.execute_reply.started":"2024-08-25T21:21:13.51752Z","shell.execute_reply":"2024-08-25T21:21:13.527538Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train the LightGBM model\nmodel1_defog_SH = lgb.train(params, train_dataset_defog_SH, num_round, valid_sets=[test_dataset_defog_SH])","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:21:13.531865Z","iopub.execute_input":"2024-08-25T21:21:13.532341Z","iopub.status.idle":"2024-08-25T21:21:37.311526Z","shell.execute_reply.started":"2024-08-25T21:21:13.532308Z","shell.execute_reply":"2024-08-25T21:21:37.310274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train the LightGBM model\nmodel2_defog_T = lgb.train(params, train_dataset_defog_T, num_round, valid_sets=[test_dataset_defog_T])","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:21:37.312766Z","iopub.execute_input":"2024-08-25T21:21:37.313104Z","iopub.status.idle":"2024-08-25T21:22:02.974613Z","shell.execute_reply.started":"2024-08-25T21:21:37.313077Z","shell.execute_reply":"2024-08-25T21:22:02.973481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train the LightGBM model\nmodel3_defog_W = lgb.train(params, train_dataset_defog_W, num_round, valid_sets=[test_dataset_defog_W])","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:22:02.976739Z","iopub.execute_input":"2024-08-25T21:22:02.977113Z","iopub.status.idle":"2024-08-25T21:22:29.697628Z","shell.execute_reply.started":"2024-08-25T21:22:02.977082Z","shell.execute_reply":"2024-08-25T21:22:29.696453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train the LightGBM model\nmodel4_tdcsfog_SH = lgb.train(params, train_dataset_tdcsfog_SH, num_round, valid_sets=[test_dataset_tdcsfog_SH])","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:22:29.699111Z","iopub.execute_input":"2024-08-25T21:22:29.699611Z","iopub.status.idle":"2024-08-25T21:23:33.292031Z","shell.execute_reply.started":"2024-08-25T21:22:29.699572Z","shell.execute_reply":"2024-08-25T21:23:33.290837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train the LightGBM model\nmodel5_tdcsfog_T = lgb.train(params, train_dataset_tdcsfog_T, num_round, valid_sets=[test_dataset_tdcsfog_T])","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:23:33.293575Z","iopub.execute_input":"2024-08-25T21:23:33.293946Z","iopub.status.idle":"2024-08-25T21:24:28.25377Z","shell.execute_reply.started":"2024-08-25T21:23:33.293915Z","shell.execute_reply":"2024-08-25T21:24:28.25257Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train the LightGBM model\nmodel6_tdcsfog_W = lgb.train(params, train_dataset_tdcsfog_W, num_round, valid_sets=[test_dataset_tdcsfog_W])","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:24:28.255396Z","iopub.execute_input":"2024-08-25T21:24:28.255785Z","iopub.status.idle":"2024-08-25T21:25:30.069413Z","shell.execute_reply.started":"2024-08-25T21:24:28.255745Z","shell.execute_reply":"2024-08-25T21:25:30.067899Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 5. Submission","metadata":{}},{"cell_type":"code","source":"# loading test file\ntdcsfog_test_path = '/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/test/tdcsfog'\n        \ntdcsfog_test_list = [\n    pd.read_csv(os.path.join(tdcsfog_test_path, file_name)).assign(Id=lambda df: file_name[:-4] + '_' + df['Time'].astype(str))\n    for file_name in os.listdir(tdcsfog_test_path)\n    if file_name.endswith('.csv')\n]        \n\ntdcsfog_test = pd.concat(tdcsfog_test_list, axis = 0)","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:25:30.075249Z","iopub.execute_input":"2024-08-25T21:25:30.075812Z","iopub.status.idle":"2024-08-25T21:25:30.115951Z","shell.execute_reply.started":"2024-08-25T21:25:30.075779Z","shell.execute_reply":"2024-08-25T21:25:30.114863Z"},"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    pd.read_csv(os.path.join(defog_test_path, file_name)).assign(Id=lambda df: file_name[:-4] + '_' + df['Time'].astype(str))\n    for file_name in os.listdir(defog_test_path)\n    if file_name.endswith('.csv')\n]        \n\ndefog_test = pd.concat(defog_test_list, axis = 0)","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:25:30.117627Z","iopub.execute_input":"2024-08-25T21:25:30.118086Z","iopub.status.idle":"2024-08-25T21:25:30.739972Z","shell.execute_reply.started":"2024-08-25T21:25:30.118047Z","shell.execute_reply":"2024-08-25T21:25:30.738798Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> Unfortunately, we did not manage to do the bandpass on the test set, thats why we only used the three acceleration values for the test set. This is not optimal and should be improved. ","metadata":{}},{"cell_type":"code","source":"feature_columns = ['Time','AccV', 'AccML', 'AccAP']\nX_defog = defog_test[feature_columns]\n\nX_tdcsfog= tdcsfog_test[feature_columns]","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:25:30.741272Z","iopub.execute_input":"2024-08-25T21:25:30.741601Z","iopub.status.idle":"2024-08-25T21:25:30.75233Z","shell.execute_reply.started":"2024-08-25T21:25:30.741574Z","shell.execute_reply":"2024-08-25T21:25:30.750923Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_pred_defog = fog_model_defog.predict(X_defog, predict_disable_shape_check=True)\ntest_pred_tdcsfog = fog_model_tdcsfog.predict(X_tdcsfog, predict_disable_shape_check=True)","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:25:30.754088Z","iopub.execute_input":"2024-08-25T21:25:30.754574Z","iopub.status.idle":"2024-08-25T21:25:31.657697Z","shell.execute_reply.started":"2024-08-25T21:25:30.754532Z","shell.execute_reply":"2024-08-25T21:25:31.656618Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# smooth the transition from FOG events to normal gait by adding momentum to the predictions.\n# this helps maintain continuity in FOG event identification, reducing abrupt changes in the prediction\nde_len = len(test_pred_defog)\n# shifts the original data by one position to the right\ndefog_pred = np.insert(test_pred_defog, 0, 0)\n# create a new list where each element is a weighted sum of the current and next prediction values\n# this smooths the predictions, making it less likely to miss the end of a FOG event\ndefog_pred_fog = [(defog_pred[i]/8) + defog_pred[i+1] for i in range(de_len)]","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:25:31.659212Z","iopub.execute_input":"2024-08-25T21:25:31.659716Z","iopub.status.idle":"2024-08-25T21:25:31.903916Z","shell.execute_reply.started":"2024-08-25T21:25:31.659676Z","shell.execute_reply":"2024-08-25T21:25:31.902605Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# same as above\ntdcsfog_len = len(test_pred_tdcsfog)\ntdcsfog_pred = np.insert(test_pred_tdcsfog, 0, 0)\ntdcsfog_pred_fog = [(tdcsfog_pred[i]/8) + tdcsfog_pred[i+1] for i in range(tdcsfog_len)]","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:25:31.905459Z","iopub.execute_input":"2024-08-25T21:25:31.905889Z","iopub.status.idle":"2024-08-25T21:25:31.921102Z","shell.execute_reply.started":"2024-08-25T21:25:31.905857Z","shell.execute_reply":"2024-08-25T21:25:31.919581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tdcsfog_test['FogProb'] = tdcsfog_pred_fog","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:25:31.922463Z","iopub.execute_input":"2024-08-25T21:25:31.922887Z","iopub.status.idle":"2024-08-25T21:25:31.93416Z","shell.execute_reply.started":"2024-08-25T21:25:31.922843Z","shell.execute_reply":"2024-08-25T21:25:31.932804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"defog_test['FogProb'] = defog_pred_fog","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:25:31.935713Z","iopub.execute_input":"2024-08-25T21:25:31.936095Z","iopub.status.idle":"2024-08-25T21:25:32.045887Z","shell.execute_reply.started":"2024-08-25T21:25:31.936065Z","shell.execute_reply":"2024-08-25T21:25:32.044674Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_defog","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:25:32.047732Z","iopub.execute_input":"2024-08-25T21:25:32.048107Z","iopub.status.idle":"2024-08-25T21:25:32.065287Z","shell.execute_reply.started":"2024-08-25T21:25:32.048076Z","shell.execute_reply":"2024-08-25T21:25:32.064001Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_defog_SH_pred = model1_defog_SH.predict(X_defog, predict_disable_shape_check='TRUE')\ntest_defog_T_pred = model2_defog_T.predict(X_defog, predict_disable_shape_check='TRUE')\ntest_defog_W_pred = model3_defog_W.predict(X_defog, predict_disable_shape_check='TRUE')","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:25:32.066808Z","iopub.execute_input":"2024-08-25T21:25:32.067189Z","iopub.status.idle":"2024-08-25T21:25:37.001406Z","shell.execute_reply.started":"2024-08-25T21:25:32.067159Z","shell.execute_reply":"2024-08-25T21:25:37.000201Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_tdcsfog_SH_pred = model4_tdcsfog_SH.predict(X_tdcsfog, predict_disable_shape_check='TRUE')\ntest_tdcsfog_T_pred = model5_tdcsfog_T.predict(X_tdcsfog, predict_disable_shape_check='TRUE')\ntest_tdcsfog_W_pred = model6_tdcsfog_W.predict(X_tdcsfog, predict_disable_shape_check='TRUE')","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:25:37.002709Z","iopub.execute_input":"2024-08-25T21:25:37.00303Z","iopub.status.idle":"2024-08-25T21:25:37.113758Z","shell.execute_reply.started":"2024-08-25T21:25:37.003003Z","shell.execute_reply":"2024-08-25T21:25:37.112678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"defog_test['StartHesitation'] = np.sqrt(test_defog_SH_pred * defog_pred_fog)\ndefog_test['Turn'] = np.sqrt(test_defog_T_pred * defog_pred_fog)\ndefog_test['Walking'] = np.sqrt(test_defog_W_pred * defog_pred_fog)","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:25:37.11507Z","iopub.execute_input":"2024-08-25T21:25:37.115449Z","iopub.status.idle":"2024-08-25T21:25:37.196749Z","shell.execute_reply.started":"2024-08-25T21:25:37.115417Z","shell.execute_reply":"2024-08-25T21:25:37.195523Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# combines result from each classification model\ntdcsfog_test['StartHesitation'] = np.sqrt(test_tdcsfog_SH_pred * tdcsfog_pred_fog)\ntdcsfog_test['Turn'] = np.sqrt(test_tdcsfog_T_pred * tdcsfog_pred_fog)\ntdcsfog_test['Walking'] = np.sqrt(test_tdcsfog_W_pred * tdcsfog_pred_fog)","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:25:37.198764Z","iopub.execute_input":"2024-08-25T21:25:37.199154Z","iopub.status.idle":"2024-08-25T21:25:37.20936Z","shell.execute_reply.started":"2024-08-25T21:25:37.199122Z","shell.execute_reply":"2024-08-25T21:25:37.208016Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_defog = defog_test[['Id','StartHesitation','Turn','Walking']]","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:25:37.210752Z","iopub.execute_input":"2024-08-25T21:25:37.211166Z","iopub.status.idle":"2024-08-25T21:25:37.229863Z","shell.execute_reply.started":"2024-08-25T21:25:37.211134Z","shell.execute_reply":"2024-08-25T21:25:37.228738Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_tdcsfog = tdcsfog_test[['Id','StartHesitation','Turn','Walking']]","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:25:37.231213Z","iopub.execute_input":"2024-08-25T21:25:37.231614Z","iopub.status.idle":"2024-08-25T21:25:37.24154Z","shell.execute_reply.started":"2024-08-25T21:25:37.231583Z","shell.execute_reply":"2024-08-25T21:25:37.24034Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.concat([submission_defog, submission_tdcsfog], ignore_index=True)","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:25:37.242919Z","iopub.execute_input":"2024-08-25T21:25:37.243291Z","iopub.status.idle":"2024-08-25T21:25:37.260357Z","shell.execute_reply.started":"2024-08-25T21:25:37.24325Z","shell.execute_reply":"2024-08-25T21:25:37.259077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv(\"submission.csv\", index = False)","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:25:37.262002Z","iopub.execute_input":"2024-08-25T21:25:37.262951Z","iopub.status.idle":"2024-08-25T21:25:39.796883Z","shell.execute_reply.started":"2024-08-25T21:25:37.262909Z","shell.execute_reply":"2024-08-25T21:25:39.795521Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission","metadata":{"execution":{"iopub.status.busy":"2024-08-25T21:25:39.798435Z","iopub.execute_input":"2024-08-25T21:25:39.798922Z","iopub.status.idle":"2024-08-25T21:25:39.816797Z","shell.execute_reply.started":"2024-08-25T21:25:39.798879Z","shell.execute_reply":"2024-08-25T21:25:39.81564Z"},"trusted":true},"execution_count":null,"outputs":[]}]}