{"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":"code","source":"# importing all the libraries\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport warnings\nimport os\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.metrics import accuracy_score\nfrom sklearn.model_selection import train_test_split\n\n#to remove warnings\nwarnings.filterwarnings(action = \"ignore\", category = DeprecationWarning ) \nwarnings.filterwarnings(action = \"ignore\", category = FutureWarning ) \nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport os\nimport seaborn as sns\nimport warnings\n\nfrom sklearn.model_selection import train_test_split\nfrom sklearn import metrics\nfrom sklearn.metrics import accuracy_score, classification_report\n\nimport lightgbm as lgb\n\n!pip install xgboost\nimport xgboost as xgb\n\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-24T13:57:23.222265Z","iopub.execute_input":"2024-08-24T13:57:23.222642Z","iopub.status.idle":"2024-08-24T13:57:58.666932Z","shell.execute_reply.started":"2024-08-24T13:57:23.222609Z","shell.execute_reply":"2024-08-24T13:57:58.665535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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    if file_name.endswith('.csv') and file_name != '003f117e14.csv':  # Exclude the specific file\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\n# Concatenate all DataFrames in the list into a single DataFrame\ntdcsfog = pd.concat(tdcsfog_list, ignore_index=True)\n\n# Create the 'IsFOG' column based on any non-zero value in 'StartHesitation', 'Walking', 'Turn' columns\ntdcsfog['IsFOG'] = tdcsfog[['StartHesitation', 'Walking', 'Turn']].any(axis='columns')\n\n# Display the first few rows of the DataFrame\ntdcsfog.head()\n","metadata":{"execution":{"iopub.status.busy":"2024-08-24T13:57:58.669026Z","iopub.execute_input":"2024-08-24T13:57:58.669829Z","iopub.status.idle":"2024-08-24T13:58:16.39868Z","shell.execute_reply.started":"2024-08-24T13:57:58.669796Z","shell.execute_reply":"2024-08-24T13:58:16.397752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tdcsfog_metadata = pd.read_csv('/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/tdcsfog_metadata.csv')\n# Merge the dataframes based on matching 'file_name' in tdcsfog and 'id' in tdcsfog_metadata\n# Assuming 'file_name' and 'id' are the column names in the respective dataframes\n# and that the 'id' in tdcsfog_metadata corresponds to 'file_name' in tdcsfog\ntdcsfog = tdcsfog.merge(tdcsfog_metadata[['Id', 'Subject']], left_on='file_name', right_on='Id', how='left')\n\n# Rename the 'Subject' column from tdcsfog_metadata to 'subject' in tdcsfog\ntdcsfog = tdcsfog.rename(columns={'Subject': 'subject'})\n# Drop the now unnecessary 'id' column from the merge\ntdcsfog = tdcsfog.drop(columns=['Id'])\n\nprint(tdcsfog.head())\n# Count the number of unique values in each column\nunique_counts = tdcsfog.nunique()\n\n# Display the number of unique values in each column\nprint(unique_counts)","metadata":{"execution":{"iopub.status.busy":"2024-08-24T13:58:16.400117Z","iopub.execute_input":"2024-08-24T13:58:16.400475Z","iopub.status.idle":"2024-08-24T13:58:26.113978Z","shell.execute_reply.started":"2024-08-24T13:58:16.400448Z","shell.execute_reply":"2024-08-24T13:58:26.112974Z"},"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    if file_name.endswith('.csv') and file_name != '003f117e14.csv':  # Exclude the specific file\n        file_path = os.path.join(defog_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        defog_list.append(df)\n\n# Concatenate all DataFrames in the list into a single DataFrame\ndefog = pd.concat(defog_list, ignore_index=True)\n\n# Create the '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-24T13:58:26.116008Z","iopub.execute_input":"2024-08-24T13:58:26.116357Z","iopub.status.idle":"2024-08-24T13:58:48.112336Z","shell.execute_reply.started":"2024-08-24T13:58:26.116329Z","shell.execute_reply":"2024-08-24T13:58:48.111053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"defog_metadata = pd.read_csv('/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/defog_metadata.csv')\n# Merge the dataframes based on matching 'file_name' in tdcsfog and 'id' in tdcsfog_metadata\n# Assuming 'file_name' and 'id' are the column names in the respective dataframes\n# and that the 'id' in tdcsfog_metadata corresponds to 'file_name' in tdcsfog\ndefog = defog.merge(defog_metadata[['Id', 'Subject']], left_on='file_name', right_on='Id', how='left')\n\n# Rename the 'Subject' column from tdcsfog_metadata to 'subject' in tdcsfog\ndefog = defog.rename(columns={'Subject': 'subject'})\n# Drop the now unnecessary 'id' column from the merge\ndefog = defog.drop(columns=['Id'])\n\nprint(tdcsfog.head())\n# Count the number of unique values in each column\nunique_counts = defog.nunique()\n\n# Display the number of unique values in each column\nprint(unique_counts)","metadata":{"execution":{"iopub.status.busy":"2024-08-24T13:58:48.113534Z","iopub.execute_input":"2024-08-24T13:58:48.113837Z","iopub.status.idle":"2024-08-24T13:59:03.632501Z","shell.execute_reply.started":"2024-08-24T13:58:48.113811Z","shell.execute_reply":"2024-08-24T13:59:03.631508Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plotting\nplt.figure(figsize=(10, 6))\n\nplt.plot(tdcsfog['AccV'], label='AccV')\nplt.plot(tdcsfog['AccML'], label='AccML')\nplt.plot(tdcsfog['AccAP'], label='AccAP')\n\nplt.title('Event Progression Over Time')\nplt.xlabel('Time')\nplt.ylabel('Acc')\nplt.legend()\nplt.grid(True)\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-08-24T13:59:03.633739Z","iopub.execute_input":"2024-08-24T13:59:03.634049Z","iopub.status.idle":"2024-08-24T13:59:30.959288Z","shell.execute_reply.started":"2024-08-24T13:59:03.634023Z","shell.execute_reply":"2024-08-24T13:59:30.958104Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tdcsfog","metadata":{"execution":{"iopub.status.busy":"2024-08-24T13:59:30.960508Z","iopub.execute_input":"2024-08-24T13:59:30.960816Z","iopub.status.idle":"2024-08-24T13:59:30.978812Z","shell.execute_reply.started":"2024-08-24T13:59:30.960789Z","shell.execute_reply":"2024-08-24T13:59:30.977842Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def add_rolling_window_features(data, window_size=200, feature_columns=['AccV', 'AccML', 'AccAP']):\n    \"\"\"\n    Add rolling window features to the dataset.\n\n    Parameters:\n    - data: The pandas DataFrame to which the features will be added.\n    - window_size: The size of the rolling window. 2 seconds window for 100Hz sampling rate\n    - feature_columns: The columns to calculate the rolling features for.\n\n    Returns:\n    - The pandas DataFrame with the new rolling window features added.\n    \"\"\"\n    for axis in feature_columns:\n        data[f'{axis}_rolling_mean'] = data[axis].rolling(window=window_size, min_periods=1).mean()\n        data[f'{axis}_rolling_std'] = data[axis].rolling(window=window_size, min_periods=1).std()\n        data[f'{axis}_rolling_max'] = data[axis].rolling(window=window_size, min_periods=1).max()\n        data[f'{axis}_rolling_min'] = data[axis].rolling(window=window_size, min_periods=1).min()\n    \n    data.dropna(inplace=True)\n    return data","metadata":{"execution":{"iopub.status.busy":"2024-08-24T13:59:30.979991Z","iopub.execute_input":"2024-08-24T13:59:30.980322Z","iopub.status.idle":"2024-08-24T13:59:30.990277Z","shell.execute_reply.started":"2024-08-24T13:59:30.980293Z","shell.execute_reply":"2024-08-24T13:59:30.989299Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tdcsfog = add_rolling_window_features(tdcsfog)\ndefog = add_rolling_window_features(defog)","metadata":{"execution":{"iopub.status.busy":"2024-08-24T13:59:30.991564Z","iopub.execute_input":"2024-08-24T13:59:30.992031Z","iopub.status.idle":"2024-08-24T13:59:47.125924Z","shell.execute_reply.started":"2024-08-24T13:59:30.991998Z","shell.execute_reply":"2024-08-24T13:59:47.124838Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tdcsfog","metadata":{"execution":{"iopub.status.busy":"2024-08-24T13:59:47.129365Z","iopub.execute_input":"2024-08-24T13:59:47.1297Z","iopub.status.idle":"2024-08-24T13:59:50.485754Z","shell.execute_reply.started":"2024-08-24T13:59:47.129664Z","shell.execute_reply":"2024-08-24T13:59:50.484784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Extract unique file names\nunique_files_tdcsfog = tdcsfog['subject'].unique()\n\n# Calculate the split index\nsplit_index_tdcsfog  = int(0.8 * len(unique_files_tdcsfog))\n\n# Split the file names into training and test sets\ntrain_files_tdcsfog = unique_files_tdcsfog[:split_index_tdcsfog]\ntest_files_tdcsfog = unique_files_tdcsfog[split_index_tdcsfog:]\n\n# Filter the DataFrame for training and test sets\ntrain_data_tdcsfog = tdcsfog[tdcsfog['subject'].isin(train_files_tdcsfog)]\ntest_data_tdcsfog = tdcsfog[tdcsfog['subject'].isin(test_files_tdcsfog)]\n\n# Print the number of rows in each set to verify\nprint(f'Train data rows: {len(train_data_tdcsfog)}')\nprint(f'Test data rows: {len(test_data_tdcsfog)}')\n\n","metadata":{"execution":{"iopub.status.busy":"2024-08-24T13:59:50.487115Z","iopub.execute_input":"2024-08-24T13:59:50.48751Z","iopub.status.idle":"2024-08-24T13:59:52.397029Z","shell.execute_reply.started":"2024-08-24T13:59:50.487476Z","shell.execute_reply":"2024-08-24T13:59:52.395723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Extract unique file names\nunique_files_defog = defog['subject'].unique()\n\n# Calculate the split index\nsplit_index_defog  = int(0.8 * len(unique_files_defog))\n\n# Split the file names into training and test sets\ntrain_files_defog = unique_files_defog[:split_index_defog]\ntest_files_defog = unique_files_defog[split_index_defog:]\n\n# Filter the DataFrame for training and test sets\ntrain_data_defog = defog[defog['subject'].isin(train_files_defog)]\ntest_data_defog = defog[defog['subject'].isin(test_files_defog)]\n\n# Print the number of rows in each set to verify\nprint(f'Train data rows: {len(train_data_defog)}')\nprint(f'Test data rows: {len(test_data_defog)}')\n\n","metadata":{"execution":{"iopub.status.busy":"2024-08-24T13:59:52.398659Z","iopub.execute_input":"2024-08-24T13:59:52.399074Z","iopub.status.idle":"2024-08-24T13:59:55.83104Z","shell.execute_reply.started":"2024-08-24T13:59:52.399037Z","shell.execute_reply":"2024-08-24T13:59:55.829903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plotting\nplt.figure(figsize=(10, 6))\n\nplt.plot(train_data_tdcsfog['AccV'], label='AccV')\nplt.plot(train_data_tdcsfog['AccML'], label='AccML')\nplt.plot(train_data_tdcsfog['AccAP'], label='AccAP')\n\nplt.title('Event Progression Over Time')\nplt.xlabel('Time')\nplt.ylabel('Acc')\nplt.legend()\nplt.grid(True)\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-08-24T13:59:55.83236Z","iopub.execute_input":"2024-08-24T13:59:55.832727Z","iopub.status.idle":"2024-08-24T14:00:19.411472Z","shell.execute_reply.started":"2024-08-24T13:59:55.832695Z","shell.execute_reply":"2024-08-24T14:00:19.41045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plotting\nplt.figure(figsize=(10, 6))\n\nplt.plot(test_data_tdcsfog['AccV'], label='AccV')\nplt.plot(test_data_tdcsfog['AccML'], label='AccML')\nplt.plot(test_data_tdcsfog['AccAP'], label='AccAP')\n\nplt.title('Event Progression Over Time')\nplt.xlabel('Time')\nplt.ylabel('Acc')\nplt.legend()\nplt.grid(True)\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:00:19.412766Z","iopub.execute_input":"2024-08-24T14:00:19.413085Z","iopub.status.idle":"2024-08-24T14:00:22.126215Z","shell.execute_reply.started":"2024-08-24T14:00:19.413057Z","shell.execute_reply":"2024-08-24T14:00:22.125013Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data_tdcsfog","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:00:22.127948Z","iopub.execute_input":"2024-08-24T14:00:22.128492Z","iopub.status.idle":"2024-08-24T14:00:25.001429Z","shell.execute_reply.started":"2024-08-24T14:00:22.128453Z","shell.execute_reply":"2024-08-24T14:00:25.000259Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Assuming 'train_data' and 'test_data' are pandas DataFrames\ntrain_features_tdcsfog = train_data_tdcsfog[['Time','AccV', 'AccML', 'AccAP', \n                   'AccV_rolling_mean', 'AccV_rolling_std', 'AccV_rolling_max', 'AccV_rolling_min',\n                   'AccML_rolling_mean', 'AccML_rolling_std', 'AccML_rolling_max', 'AccML_rolling_min',\n                   'AccAP_rolling_mean', 'AccAP_rolling_std', 'AccAP_rolling_max', 'AccAP_rolling_min']]\ntest_features_tdcsfog = test_data_tdcsfog[['Time','AccV', 'AccML', 'AccAP', \n                   'AccV_rolling_mean', 'AccV_rolling_std', 'AccV_rolling_max', 'AccV_rolling_min',\n                   'AccML_rolling_mean', 'AccML_rolling_std', 'AccML_rolling_max', 'AccML_rolling_min',\n                   'AccAP_rolling_mean', 'AccAP_rolling_std', 'AccAP_rolling_max', 'AccAP_rolling_min']]\n\n# Select the label column\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-24T14:00:25.002631Z","iopub.execute_input":"2024-08-24T14:00:25.002964Z","iopub.status.idle":"2024-08-24T14:00:25.43546Z","shell.execute_reply.started":"2024-08-24T14:00:25.002937Z","shell.execute_reply":"2024-08-24T14:00:25.434577Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Assuming 'train_data' and 'test_data' are pandas DataFrames\ntrain_features_defog = train_data_defog[['Time','AccV', 'AccML', 'AccAP', \n                   'AccV_rolling_mean', 'AccV_rolling_std', 'AccV_rolling_max', 'AccV_rolling_min',\n                   'AccML_rolling_mean', 'AccML_rolling_std', 'AccML_rolling_max', 'AccML_rolling_min',\n                   'AccAP_rolling_mean', 'AccAP_rolling_std', 'AccAP_rolling_max', 'AccAP_rolling_min']]\ntest_features_defog = test_data_defog[['Time','AccV', 'AccML', 'AccAP', \n                   'AccV_rolling_mean', 'AccV_rolling_std', 'AccV_rolling_max', 'AccV_rolling_min',\n                   'AccML_rolling_mean', 'AccML_rolling_std', 'AccML_rolling_max', 'AccML_rolling_min',\n                   'AccAP_rolling_mean', 'AccAP_rolling_std', 'AccAP_rolling_max', 'AccAP_rolling_min']]\n\n# Select the label column\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-24T14:00:25.436694Z","iopub.execute_input":"2024-08-24T14:00:25.437041Z","iopub.status.idle":"2024-08-24T14:00:26.277057Z","shell.execute_reply.started":"2024-08-24T14:00:25.437012Z","shell.execute_reply":"2024-08-24T14:00:26.276243Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plotting\nplt.figure(figsize=(10, 6))\n\nplt.plot(train_features_tdcsfog['AccV'], label='AccV')\nplt.plot(train_features_tdcsfog['AccML'], label='AccML')\nplt.plot(train_features_tdcsfog['AccAP'], label='AccAP')\n\nplt.title('Event Progression Over Time')\nplt.xlabel('Time')\nplt.ylabel('Acc')\nplt.legend()\nplt.grid(True)\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:00:26.278139Z","iopub.execute_input":"2024-08-24T14:00:26.278425Z","iopub.status.idle":"2024-08-24T14:00:49.932953Z","shell.execute_reply.started":"2024-08-24T14:00:26.278402Z","shell.execute_reply":"2024-08-24T14:00:49.931808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plotting\nplt.figure(figsize=(10, 6))\n\nplt.plot(test_features_tdcsfog['AccV'], label='AccV')\nplt.plot(test_features_tdcsfog['AccML'], label='AccML')\nplt.plot(test_features_tdcsfog['AccAP'], label='AccAP')\n\nplt.title('Event Progression Over Time')\nplt.xlabel('Time')\nplt.ylabel('Acc')\nplt.legend()\nplt.grid(True)\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:00:49.934478Z","iopub.execute_input":"2024-08-24T14:00:49.93485Z","iopub.status.idle":"2024-08-24T14:00:52.484688Z","shell.execute_reply.started":"2024-08-24T14:00:49.934818Z","shell.execute_reply":"2024-08-24T14:00:52.483616Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fog_params={\n    'objective': 'binary', #binary target feature\n    'metric': 'average_precision', \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\n# Train the model\nfog_model_tdcsfog = lgb.train(fog_params, train_dataset_tdcsfog, num_round, valid_sets=[test_dataset_tdcsfog])\n\n# Make 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\n# Evaluate the model\naccuracy = metrics.accuracy_score(test_labels_tdcsfog, y_pred_binary_tdcsfog)\nprint(f\"Accuracy: {accuracy}\")","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:00:52.48593Z","iopub.execute_input":"2024-08-24T14:00:52.486254Z","iopub.status.idle":"2024-08-24T14:02:38.270408Z","shell.execute_reply.started":"2024-08-24T14:00:52.486228Z","shell.execute_reply":"2024-08-24T14:02:38.268859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fog_params={\n    'objective': 'binary', #binary target feature\n    'metric': 'average_precision', \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\n# Train the model\nfog_model_defog = lgb.train(fog_params, train_dataset_defog, num_round, valid_sets=[test_dataset_defog])\n\n# Make 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-24T14:02:38.272274Z","iopub.execute_input":"2024-08-24T14:02:38.272628Z","iopub.status.idle":"2024-08-24T14:05:47.184158Z","shell.execute_reply.started":"2024-08-24T14:02:38.272594Z","shell.execute_reply":"2024-08-24T14:05:47.182873Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"targets = [\"StartHesitation\", \"Turn\", 'Walking', 'IsFOG', 'file_name','subject']","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:05:47.187858Z","iopub.execute_input":"2024-08-24T14:05:47.188305Z","iopub.status.idle":"2024-08-24T14:05:47.194534Z","shell.execute_reply.started":"2024-08-24T14:05:47.188269Z","shell.execute_reply":"2024-08-24T14:05:47.19348Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"CLASSIFICATION","metadata":{}},{"cell_type":"code","source":"train_data_tdcsfog","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:05:47.195996Z","iopub.execute_input":"2024-08-24T14:05:47.196687Z","iopub.status.idle":"2024-08-24T14:05:50.232886Z","shell.execute_reply.started":"2024-08-24T14:05:47.196642Z","shell.execute_reply":"2024-08-24T14:05:50.231908Z"},"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-24T14:05:50.234326Z","iopub.execute_input":"2024-08-24T14:05:50.234638Z","iopub.status.idle":"2024-08-24T14:05:50.560586Z","shell.execute_reply.started":"2024-08-24T14:05:50.234611Z","shell.execute_reply":"2024-08-24T14:05:50.559645Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data_tdcsfog_cl","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:05:50.562028Z","iopub.execute_input":"2024-08-24T14:05:50.562384Z","iopub.status.idle":"2024-08-24T14:05:51.521864Z","shell.execute_reply.started":"2024-08-24T14:05:50.562349Z","shell.execute_reply":"2024-08-24T14:05:51.520913Z"},"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-24T14:05:51.523132Z","iopub.execute_input":"2024-08-24T14:05:51.523419Z","iopub.status.idle":"2024-08-24T14:05:51.653559Z","shell.execute_reply.started":"2024-08-24T14:05:51.523396Z","shell.execute_reply":"2024-08-24T14:05:51.652706Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# X values for on which the model is trained\nX_train_tdcsfog = train_data_tdcsfog_cl.drop(targets, axis=1)  # features\n\n# split data into the three \ny1_train_tdcsfog = train_data_tdcsfog_cl[['StartHesitation', 'Turn','Walking']]\n# X values for on which the model is trained\nX_test_tdcsfog = test_data_tdcsfog_cl.drop(targets, axis=1)  # features\n\n# split data into the three \ny1_test_tdcsfog = test_data_tdcsfog_cl[['StartHesitation', 'Turn','Walking']]","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:05:51.657283Z","iopub.execute_input":"2024-08-24T14:05:51.657631Z","iopub.status.idle":"2024-08-24T14:05:51.851334Z","shell.execute_reply.started":"2024-08-24T14:05:51.657598Z","shell.execute_reply":"2024-08-24T14:05:51.850351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y1_train_tdcsfog['combined'] = y1_train_tdcsfog['StartHesitation'].astype(str) + y1_train_tdcsfog['Turn'].astype(str) + y1_train_tdcsfog['Walking'].astype(str)\ny1_train_tdcsfog = y1_train_tdcsfog[['combined']]\n\ny1_test_tdcsfog['combined'] = y1_test_tdcsfog['StartHesitation'].astype(str) + y1_test_tdcsfog['Turn'].astype(str) + y1_test_tdcsfog['Walking'].astype(str)\ny1_test_tdcsfog = y1_test_tdcsfog[['combined']]\n\ny1_test_tdcsfog","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:05:51.859968Z","iopub.execute_input":"2024-08-24T14:05:51.860414Z","iopub.status.idle":"2024-08-24T14:05:54.323804Z","shell.execute_reply.started":"2024-08-24T14:05:51.860385Z","shell.execute_reply":"2024-08-24T14:05:54.322709Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_tdcsfog","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:05:54.324956Z","iopub.execute_input":"2024-08-24T14:05:54.325293Z","iopub.status.idle":"2024-08-24T14:05:54.348501Z","shell.execute_reply.started":"2024-08-24T14:05:54.325263Z","shell.execute_reply":"2024-08-24T14:05:54.347484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# X values for on which the model is trained\nX_train_defog = train_data_defog_cl.drop(targets, axis=1)  # features\n\n# split data into the three \ny1_train_defog = train_data_defog_cl[['StartHesitation', 'Turn','Walking']]\n# X values for on which the model is trained\nX_test_defog = test_data_defog_cl.drop(targets, axis=1)  # features\n\n# split data into the three \ny1_test_defog = test_data_defog_cl[['StartHesitation', 'Turn','Walking']]","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:05:54.349812Z","iopub.execute_input":"2024-08-24T14:05:54.350163Z","iopub.status.idle":"2024-08-24T14:05:54.418708Z","shell.execute_reply.started":"2024-08-24T14:05:54.350129Z","shell.execute_reply":"2024-08-24T14:05:54.417588Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_tdcsfog","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:05:54.419997Z","iopub.execute_input":"2024-08-24T14:05:54.420645Z","iopub.status.idle":"2024-08-24T14:05:54.44454Z","shell.execute_reply.started":"2024-08-24T14:05:54.420608Z","shell.execute_reply":"2024-08-24T14:05:54.443371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y1_train_defog['combined'] = y1_train_defog['StartHesitation'].astype(str) + y1_train_defog['Turn'].astype(str) + y1_train_defog['Walking'].astype(str)\ny1_train_defog = y1_train_defog[['combined']]\n\ny1_test_defog['combined'] = y1_test_defog['StartHesitation'].astype(str) + y1_test_defog['Turn'].astype(str) + y1_test_defog['Walking'].astype(str)\ny1_test_defog = y1_test_defog[['combined']]\n\ny1_train_defog","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:05:54.445816Z","iopub.execute_input":"2024-08-24T14:05:54.44636Z","iopub.status.idle":"2024-08-24T14:05:55.153709Z","shell.execute_reply.started":"2024-08-24T14:05:54.44633Z","shell.execute_reply":"2024-08-24T14:05:55.152702Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plotting\nplt.figure(figsize=(10, 6))\n\nplt.plot(X_train_tdcsfog['AccV'], label='AccV')\nplt.plot(X_train_tdcsfog['AccML'], label='AccML')\nplt.plot(X_train_tdcsfog['AccAP'], label='AccAP')\n\nplt.title('Event Progression Over Time')\nplt.xlabel('Time')\nplt.ylabel('Acc')\nplt.legend()\nplt.grid(True)\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:05:55.154962Z","iopub.execute_input":"2024-08-24T14:05:55.155288Z","iopub.status.idle":"2024-08-24T14:05:59.590916Z","shell.execute_reply.started":"2024-08-24T14:05:55.155261Z","shell.execute_reply":"2024-08-24T14:05:59.589843Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y1_test_tdcsfog","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:05:59.592511Z","iopub.execute_input":"2024-08-24T14:05:59.592951Z","iopub.status.idle":"2024-08-24T14:05:59.603799Z","shell.execute_reply.started":"2024-08-24T14:05:59.592914Z","shell.execute_reply":"2024-08-24T14:05:59.602607Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from imblearn.over_sampling import SMOTE\ndef apply_smote(X, y):\n    smote = SMOTE(random_state=42)\n    X_smote, y_smote = smote.fit_resample(X, y)\n    return X_smote, y_smote","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:05:59.605236Z","iopub.execute_input":"2024-08-24T14:05:59.605635Z","iopub.status.idle":"2024-08-24T14:06:00.014064Z","shell.execute_reply.started":"2024-08-24T14:05:59.605599Z","shell.execute_reply":"2024-08-24T14:06:00.012787Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_tdcsfog = X_train_tdcsfog.values\ny1_train_tdcsfog = y1_train_tdcsfog.values\n\nX_test_tdcsfog = X_test_tdcsfog.values\ny1_test_tdcsfog = y1_test_tdcsfog.values\n\nX_train_defog = X_train_defog.values\ny1_train_defog = y1_train_defog.values\n\nX_test_defog = X_test_defog.values\ny1_test_defog = y1_test_defog.values","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:06:00.015337Z","iopub.execute_input":"2024-08-24T14:06:00.017147Z","iopub.status.idle":"2024-08-24T14:06:01.046302Z","shell.execute_reply.started":"2024-08-24T14:06:00.017112Z","shell.execute_reply":"2024-08-24T14:06:01.045355Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_tdcsfog","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:06:01.047459Z","iopub.execute_input":"2024-08-24T14:06:01.047787Z","iopub.status.idle":"2024-08-24T14:06:01.058535Z","shell.execute_reply.started":"2024-08-24T14:06:01.047761Z","shell.execute_reply":"2024-08-24T14:06:01.057537Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_tdcsfog, y1_train_tdcsfog = apply_smote(X_train_tdcsfog, y1_train_tdcsfog)\nX_test_tdcsfog, y1_test_tdcsfog = apply_smote(X_test_tdcsfog, y1_test_tdcsfog)\nX_train_defog, y1_train_defog = apply_smote(X_train_defog, y1_train_defog)\nX_test_defog, y1_test_defog = apply_smote(X_test_defog, y1_test_defog)","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:06:01.062084Z","iopub.execute_input":"2024-08-24T14:06:01.062468Z","iopub.status.idle":"2024-08-24T14:16:45.463376Z","shell.execute_reply.started":"2024-08-24T14:06:01.062439Z","shell.execute_reply":"2024-08-24T14:16:45.462278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\n# Plot the AccV column from the numpy arrays and the DataFrame\nplt.figure(figsize=(10, 6))  # Optional: to make the plot larger\n\n# Plotting the AccV column from the numpy arrays\nplt.plot(X_train_tdcsfog[:10000, 1], label='X_train_tdcsfog AccV')\nplt.plot(X_test_tdcsfog[:10000, 1], label='X_test_tdcsfog AccV')\n\n# Plotting the AccV column from the DataFrame\nplt.plot(train_data_tdcsfog['AccV'][:10000], label='train_data_tdcsfog AccV')\n\n# Adding titles and labels\nplt.title('AccV Column from Different Datasets')\nplt.xlabel('Sample Index')\nplt.ylabel('AccV Value')\n\n# Adding a legend\nplt.legend()\n\n# Show the plot\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:16:45.464867Z","iopub.execute_input":"2024-08-24T14:16:45.465357Z","iopub.status.idle":"2024-08-24T14:16:45.797052Z","shell.execute_reply.started":"2024-08-24T14:16:45.465319Z","shell.execute_reply":"2024-08-24T14:16:45.796061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# y1_train_tdcsfog = pd.DataFrame(y1_train_tdcsfog)\n# y1_test_tdcsfog = pd.DataFrame(y1_test_tdcsfog)\n# y1_train_defog = pd.DataFrame(y1_train_defog)\n# y1_test_defog = pd.DataFrame(y1_test_defog)","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:16:45.798587Z","iopub.execute_input":"2024-08-24T14:16:45.79898Z","iopub.status.idle":"2024-08-24T14:16:45.803404Z","shell.execute_reply.started":"2024-08-24T14:16:45.798948Z","shell.execute_reply":"2024-08-24T14:16:45.802384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y1_train_tdcsfog","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:16:45.8049Z","iopub.execute_input":"2024-08-24T14:16:45.805574Z","iopub.status.idle":"2024-08-24T14:16:45.82144Z","shell.execute_reply.started":"2024-08-24T14:16:45.805538Z","shell.execute_reply":"2024-08-24T14:16:45.820486Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# y_StartHesitation_tdcsfog_train = y1_train_tdcsfog[0]\n# y_Turn_tdcsfog_train = y1_train_tdcsfog[1]\n# y_Walking_tdcsfog_train = y1_train_tdcsfog[2]\n\n# y_StartHesitation_tdcsfog_test = y1_test_tdcsfog[0]\n# y_Turn_tdcsfog_test = y1_test_tdcsfog[1]\n# y_Walking_tdcsfog_test = y1_test_tdcsfog[2]","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:16:45.822511Z","iopub.execute_input":"2024-08-24T14:16:45.822835Z","iopub.status.idle":"2024-08-24T14:16:45.83097Z","shell.execute_reply.started":"2024-08-24T14:16:45.822807Z","shell.execute_reply":"2024-08-24T14:16:45.830042Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# y_StartHesitation_defog_train = y1_train_defog[0]\n# y_Turn_defog_train = y1_train_defog[1]\n# y_Walking_defog_train = y1_train_defog[2]\n\n# y_StartHesitation_defog_test = y1_test_defog[0]\n# y_Turn_defog_test = y1_test_defog[1]\n# y_Walking_defog_test = y1_test_defog[2]","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:16:45.832174Z","iopub.execute_input":"2024-08-24T14:16:45.832479Z","iopub.status.idle":"2024-08-24T14:16:45.840688Z","shell.execute_reply.started":"2024-08-24T14:16:45.832455Z","shell.execute_reply":"2024-08-24T14:16:45.839714Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # Create LightGBM datasets\n# train_dataset_defog_SH = lgb.Dataset(X_train_defog, label=y_StartHesitation_defog_train)\n# test_dataset_defog_SH = lgb.Dataset(X_test_defog, label=y_StartHesitation_defog_test)\n\n# # Create LightGBM datasets\n# train_dataset_defog_T = lgb.Dataset(X_train_defog, label=y_Turn_defog_train)\n# test_dataset_defog_T = lgb.Dataset(X_test_defog, label=y_Turn_defog_test)\n\n# # Create LightGBM datasets\n# train_dataset_defog_W = lgb.Dataset(X_train_defog, label=y_Walking_defog_train)\n# test_dataset_defog_W = lgb.Dataset(X_test_defog, label=y_Walking_defog_test)\n\n# # Create LightGBM datasets\n# train_dataset_tdcsfog_SH = lgb.Dataset(X_train_tdcsfog, label=y_StartHesitation_tdcsfog_train)\n# test_dataset_tdcsfog_SH = lgb.Dataset(X_test_tdcsfog, label=y_StartHesitation_tdcsfog_test)\n\n# # Create LightGBM datasets\n# train_dataset_tdcsfog_T = lgb.Dataset(X_train_tdcsfog, label=y_Turn_tdcsfog_train)\n# test_dataset_tdcsfog_T = lgb.Dataset(X_test_tdcsfog, label=y_Turn_tdcsfog_test)\n\n# # Create LightGBM datasets\n# train_dataset_tdcsfog_W = lgb.Dataset(X_train_tdcsfog, label=y_Walking_tdcsfog_train)\n# test_dataset_tdcsfog_W = lgb.Dataset(X_test_tdcsfog, label=y_Walking_tdcsfog_test)\n\n\n# # # Create LightGBM datasets\n# train_dataset_defog_SH = lgb.Dataset(X_train_defog, label=y_StartHesitation_defog_train)\n# test_dataset_defog_SH = lgb.Dataset(X_test_defog, label=y_StartHesitation_defog_test)\n\n\n# # Create LightGBM datasets\ntrain_dataset_tdcsfog_W = lgb.Dataset(X_train_tdcsfog, label=y1_train_tdcsfog)\n\n\n# Define XGBoost parameters\nxgboost_params = {\n    'objective': 'binary',\n    'metric': 'average_precision',\n    'boosting_type': 'gbdt',\n    'learning_rate': 0.03,\n    'verbose': 1,\n    'max_depth': 6,\n    'num_leaves': 50\n}\nnum_round = 300  ","metadata":{"execution":{"iopub.status.busy":"2024-08-24T14:16:45.841844Z","iopub.execute_input":"2024-08-24T14:16:45.84216Z","iopub.status.idle":"2024-08-24T14:16:45.851948Z","shell.execute_reply.started":"2024-08-24T14:16:45.842134Z","shell.execute_reply":"2024-08-24T14:16:45.850949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Train the LightGBM model\nmodel1_defog_SH = lgb.train(xgboost_params, train_dataset_tdcsfog_W, num_round, valid_sets=[train_dataset_tdcsfog_W])","metadata":{"execution":{"iopub.status.busy":"2024-08-24T13:57:11.371767Z","iopub.execute_input":"2024-08-24T13:57:11.372151Z","iopub.status.idle":"2024-08-24T13:57:11.677049Z","shell.execute_reply.started":"2024-08-24T13:57:11.37212Z","shell.execute_reply":"2024-08-24T13:57:11.675549Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Train the LightGBM model\nmodel2_defog_T = lgb.train(xgboost_params, train_dataset_defog_T, num_round, valid_sets=[test_dataset_defog_T])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Train the LightGBM model\nmodel3_defog_W = lgb.train(xgboost_params, train_dataset_defog_W, num_round, valid_sets=[test_dataset_defog_W])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Train the LightGBM model\nmodel4_tdcsfog_SH = lgb.train(xgboost_params, train_dataset_tdcsfog_SH, num_round, valid_sets=[test_dataset_tdcsfog_SH])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Train the LightGBM model\nmodel5_tdcsfog_T = lgb.train(xgboost_params, train_dataset_tdcsfog_T, num_round, valid_sets=[test_dataset_tdcsfog_T])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Train the LightGBM model\nmodel6_tdcsfog_W = lgb.train(xgboost_params, train_dataset_tdcsfog_W, num_round, valid_sets=[test_dataset_tdcsfog_W])","metadata":{"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    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":{"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":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"window_size = 200  # 2 seconds window for 100Hz sampling rate\n\n# Calculating rolling window features for each acceleration axis\nfor axis in ['AccV', 'AccML', 'AccAP']:\n    defog_test[f'{axis}_rolling_mean'] = defog_test[axis].rolling(window=window_size, min_periods=1).mean()\n    defog_test[f'{axis}_rolling_std'] = defog_test[axis].rolling(window=window_size, min_periods=1).std()\n    defog_test[f'{axis}_rolling_max'] = defog_test[axis].rolling(window=window_size, min_periods=1).max()\n    defog_test[f'{axis}_rolling_min'] = defog_test[axis].rolling(window=window_size, min_periods=1).min()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Calculating rolling window features for each acceleration axis\nfor axis in ['AccV', 'AccML', 'AccAP']:\n    tdcsfog_test[f'{axis}_rolling_mean'] = tdcsfog_test[axis].rolling(window=window_size, min_periods=1).mean()\n    tdcsfog_test[f'{axis}_rolling_std'] = tdcsfog_test[axis].rolling(window=window_size, min_periods=1).std()\n    tdcsfog_test[f'{axis}_rolling_max'] = tdcsfog_test[axis].rolling(window=window_size, min_periods=1).max()\n    tdcsfog_test[f'{axis}_rolling_min'] = tdcsfog_test[axis].rolling(window=window_size, min_periods=1).min()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Updating feature selection with rolling window features\nfeature_columns = ['Time','AccV', 'AccML', 'AccAP', \n                   'AccV_rolling_mean', 'AccV_rolling_std', 'AccV_rolling_max', 'AccV_rolling_min',\n                   'AccML_rolling_mean', 'AccML_rolling_std', 'AccML_rolling_max', 'AccML_rolling_min',\n                   'AccAP_rolling_mean', 'AccAP_rolling_std', 'AccAP_rolling_max', 'AccAP_rolling_min']\n\nX_defog = defog_test[feature_columns]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Updating feature selection with rolling window features\nfeature_columns = ['Time','AccV', 'AccML', 'AccAP', \n                   'AccV_rolling_mean', 'AccV_rolling_std', 'AccV_rolling_max', 'AccV_rolling_min',\n                   'AccML_rolling_mean', 'AccML_rolling_std', 'AccML_rolling_max', 'AccML_rolling_min',\n                   'AccAP_rolling_mean', 'AccAP_rolling_std', 'AccAP_rolling_max', 'AccAP_rolling_min']\n\nX_tdcsfog= tdcsfog_test[feature_columns]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_pred_defog = fog_model_defog.predict(X_defog)\ntest_pred_tdcsfog = fog_model_tdcsfog.predict(X_tdcsfog)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Add momentum to defog identification; FOG event continuity\nde_len = len(test_pred_defog)\ndefog_pred = np.insert(test_pred_defog, 0, 0)\ndefog_pred_fog = [(defog_pred[i]/8) + defog_pred[i+1] for i in range(de_len)]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Add momentum to defog identification; FOG event continuity\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":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tdcsfog_test['FogProb'] = tdcsfog_pred_fog","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"defog_test['FogProb'] = defog_pred_fog","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_defog","metadata":{"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":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_tdcsfog_SH_pred = model4_tdcsfog_SH.predict(X_tdcsfog)\ntest_tdcsfog_T_pred = model5_tdcsfog_T.predict(X_tdcsfog)\ntest_tdcsfog_W_pred = model6_tdcsfog_W.predict(X_tdcsfog)","metadata":{"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":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tdcsfog_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":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_defog = defog_test[['Id','StartHesitation','Turn','Walking']]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_tdcsfog = tdcsfog_test[['Id','StartHesitation','Turn','Walking']]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.concat([submission_defog, submission_tdcsfog], ignore_index=True)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv(\"submission.csv\", index = False)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}