{"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceType":"competition","sourceId":102335,"databundleVersionId":12518947},{"sourceType":"datasetVersion","sourceId":12907690,"datasetId":7925274,"databundleVersionId":13558532},{"sourceType":"kernelVersion","sourceId":255504528},{"sourceType":"kernelVersion","sourceId":259076387}],"dockerImageVersionId":31089,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false},"papermill":{"default_parameters":{},"duration":253.234321,"end_time":"2025-08-13T10:57:15.548857","environment_variables":{},"exception":null,"input_path":"__notebook__.ipynb","output_path":"__notebook__.ipynb","parameters":{},"start_time":"2025-08-13T10:53:02.314536","version":"2.6.0"}},"nbformat_minor":4,"nbformat":4,"cells":[{"id":"f2f7290b","cell_type":"markdown","source":"**Library - Packages**","metadata":{"papermill":{"duration":0.028924,"end_time":"2025-08-13T10:53:07.036635","exception":false,"start_time":"2025-08-13T10:53:07.007711","status":"completed"},"tags":[]}},{"id":"c51e6b9e","cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport pathlib\nfrom pathlib import Path","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","execution":{"iopub.status.busy":"2025-09-01T17:11:48.168854Z","iopub.execute_input":"2025-09-01T17:11:48.169176Z","iopub.status.idle":"2025-09-01T17:11:48.184390Z","shell.execute_reply.started":"2025-09-01T17:11:48.169149Z","shell.execute_reply":"2025-09-01T17:11:48.183388Z"},"papermill":{"duration":3.620421,"end_time":"2025-08-13T10:53:10.683659","exception":false,"start_time":"2025-08-13T10:53:07.063238","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"0557385b","cell_type":"code","source":"import kagglehub\nfrom kagglehub import KaggleDatasetAdapter","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.185687Z","iopub.execute_input":"2025-09-01T17:11:48.186010Z","iopub.status.idle":"2025-09-01T17:11:48.201054Z","shell.execute_reply.started":"2025-09-01T17:11:48.185990Z","shell.execute_reply":"2025-09-01T17:11:48.200053Z"},"papermill":{"duration":0.363976,"end_time":"2025-08-13T10:53:11.073939","exception":false,"start_time":"2025-08-13T10:53:10.709963","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"f6f988ef","cell_type":"markdown","source":"**Load and annex notebook**","metadata":{"papermill":{"duration":0.027858,"end_time":"2025-08-13T10:53:11.883004","exception":false,"start_time":"2025-08-13T10:53:11.855146","status":"completed"},"tags":[]}},{"id":"b136ee10","cell_type":"code","source":"#%run annex-notebook.ipynb\nimport cmi_sensor_data_utility_functions as my_utils","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.202033Z","iopub.execute_input":"2025-09-01T17:11:48.202648Z","iopub.status.idle":"2025-09-01T17:11:48.216753Z","shell.execute_reply.started":"2025-09-01T17:11:48.202588Z","shell.execute_reply":"2025-09-01T17:11:48.215875Z"},"papermill":{"duration":0.571138,"end_time":"2025-08-13T10:53:12.480000","exception":false,"start_time":"2025-08-13T10:53:11.908862","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"8d8a3426","cell_type":"code","source":"print(my_utils.notebook_folder) \ndata_folders_dictionary = my_utils.data_folder(my_utils.notebook_folder)","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.217654Z","iopub.execute_input":"2025-09-01T17:11:48.217912Z","iopub.status.idle":"2025-09-01T17:11:48.233775Z","shell.execute_reply.started":"2025-09-01T17:11:48.217894Z","shell.execute_reply":"2025-09-01T17:11:48.232901Z"},"papermill":{"duration":0.035563,"end_time":"2025-08-13T10:53:12.542538","exception":false,"start_time":"2025-08-13T10:53:12.506975","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"030404cd","cell_type":"markdown","source":"<hr>\n\n##   **1. Dataset preparation**","metadata":{"papermill":{"duration":0.026586,"end_time":"2025-08-13T10:53:12.597684","exception":false,"start_time":"2025-08-13T10:53:12.571098","status":"completed"},"tags":[]}},{"id":"020735c3","cell_type":"markdown","source":"###   **1.1 Gesture categorical dataset**","metadata":{"papermill":{"duration":0.025848,"end_time":"2025-08-13T10:53:12.650768","exception":false,"start_time":"2025-08-13T10:53:12.624920","status":"completed"},"tags":[]}},{"id":"977c072b","cell_type":"markdown","source":"- **load raw train dataset**","metadata":{"papermill":{"duration":0.026395,"end_time":"2025-08-13T10:53:12.703536","exception":false,"start_time":"2025-08-13T10:53:12.677141","status":"completed"},"tags":[]}},{"id":"4a44e058","cell_type":"code","source":"# filepath = Path('/kaggle/input/cmi-detect-behavior-with-sensor-data/train.csv')\n# raw_train_df = pd.read_csv(filepath, sep=',', encoding='utf-8', na_filter=True)","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.234769Z","iopub.execute_input":"2025-09-01T17:11:48.235076Z","iopub.status.idle":"2025-09-01T17:11:48.248497Z","shell.execute_reply.started":"2025-09-01T17:11:48.235055Z","shell.execute_reply":"2025-09-01T17:11:48.247699Z"},"papermill":{"duration":0.033196,"end_time":"2025-08-13T10:53:12.763023","exception":false,"start_time":"2025-08-13T10:53:12.729827","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"ecb76681","cell_type":"code","source":"# CAT_COLUMNS = [\n#     'row_id', \n#     'sequence_type', \t\n#     'sequence_id', \t\n#     'sequence_counter', \t\n#     'subject', \t\n#     'orientation', \t\n#     'behavior', \t\n#     'phase', \t\n#     'gesture'\n# ]\n# gesture_cat_df = raw_train_df[CAT_COLUMNS]","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.249388Z","iopub.execute_input":"2025-09-01T17:11:48.249662Z","iopub.status.idle":"2025-09-01T17:11:48.262854Z","shell.execute_reply.started":"2025-09-01T17:11:48.249632Z","shell.execute_reply":"2025-09-01T17:11:48.262003Z"},"papermill":{"duration":0.033431,"end_time":"2025-08-13T10:53:12.826007","exception":false,"start_time":"2025-08-13T10:53:12.792576","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"7c13333c","cell_type":"code","source":"# gesture_cat_df.head(5)","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.263949Z","iopub.execute_input":"2025-09-01T17:11:48.264279Z","iopub.status.idle":"2025-09-01T17:11:48.281556Z","shell.execute_reply.started":"2025-09-01T17:11:48.264252Z","shell.execute_reply":"2025-09-01T17:11:48.280484Z"},"papermill":{"duration":0.033087,"end_time":"2025-08-13T10:53:12.885682","exception":false,"start_time":"2025-08-13T10:53:12.852595","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"d0387f51","cell_type":"markdown","source":"- **Load dictionaries** ","metadata":{"papermill":{"duration":0.026128,"end_time":"2025-08-13T10:53:12.939208","exception":false,"start_time":"2025-08-13T10:53:12.913080","status":"completed"},"tags":[]}},{"id":"17688cb5","cell_type":"code","source":"folder = '/kaggle/usr/lib/cmi-detect-gesture-with-a-wrist-worm-device/competition-data/process-data'\nloaded_sequence_type_dictionary = my_utils.handle_pickle_dict(folder=folder, pickle_filename='sequence_type_dictionary.pkl')\nloaded_sequence_ids_dictionary = my_utils.handle_pickle_dict(folder=folder, pickle_filename='sequence_ids_dictionary.pkl')\nloaded_subject_dictionary = my_utils.handle_pickle_dict(folder=folder, pickle_filename='subjects_dictionary.pkl')\nloaded_orientation_type_dictionary = my_utils.handle_pickle_dict(folder=folder, pickle_filename='orientation_type_dictionary.pkl')\nloaded_behavior_type_dictionary = my_utils.handle_pickle_dict(folder=folder, pickle_filename='behavior_type_dictionary.pkl')\nloaded_phase_type_dictionary = my_utils.handle_pickle_dict(folder=folder, pickle_filename='phase_type_dictionary.pkl')\nloaded_gesture_type_dictionary = my_utils.handle_pickle_dict(folder=folder, pickle_filename='gesture_type_dictionary.pkl')\nloaded_bfrb_gesture_type_dictionary = my_utils.handle_pickle_dict(folder=folder, pickle_filename='bfrb_type_dictionary.pkl')\nloaded_nbfrb_gesture_type_dictionary = my_utils.handle_pickle_dict(folder=folder, pickle_filename='nbfrb_type_dictionary.pkl')","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.282423Z","iopub.execute_input":"2025-09-01T17:11:48.282732Z","iopub.status.idle":"2025-09-01T17:11:48.309654Z","shell.execute_reply.started":"2025-09-01T17:11:48.282697Z","shell.execute_reply":"2025-09-01T17:11:48.308780Z"},"papermill":{"duration":0.139645,"end_time":"2025-08-13T10:53:13.105602","exception":false,"start_time":"2025-08-13T10:53:12.965957","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"970d2b8f-b700-4c4c-88b7-9e86cbc3b286","cell_type":"markdown","source":"- **Check the content of a loaded dictionary**","metadata":{}},{"id":"88996ee8-6bb3-48c8-8e24-a6a849baac66","cell_type":"code","source":"print(loaded_bfrb_gesture_type_dictionary)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-01T17:11:48.310687Z","iopub.execute_input":"2025-09-01T17:11:48.310968Z","iopub.status.idle":"2025-09-01T17:11:48.315873Z","shell.execute_reply.started":"2025-09-01T17:11:48.310949Z","shell.execute_reply":"2025-09-01T17:11:48.314945Z"}},"outputs":[],"execution_count":null},{"id":"d19f5b1e","cell_type":"markdown","source":"- **add nbfrb and bfrb gesture columns**","metadata":{"papermill":{"duration":0.026057,"end_time":"2025-08-13T10:53:13.158423","exception":false,"start_time":"2025-08-13T10:53:13.132366","status":"completed"},"tags":[]}},{"id":"0161d21b","cell_type":"code","source":"# def update_bfrb_columns(df, update_bfrb_gesture_dictionary, update_nbfrb_gesture_dictionary):\n#     # Initialize the new columns with zeros\n#     df['bfrb_gesture'] = 0\n#     df['nbfrb_gesture'] = 0\n\n#     # Get gesture lists\n#     bfrb_keys = update_bfrb_gesture_dictionary['bfrb_gesture']\n#     nbfrb_keys = update_nbfrb_gesture_dictionary['nbfrb_gesture']\n\n#     # Apply BFRB gesture mapping\n#     df.loc[df['gesture'].isin(bfrb_keys.keys()), 'bfrb_gesture'] = df['gesture'].map(bfrb_keys)\n\n#     # Apply non-BFRB gesture mapping\n#     df.loc[df['gesture'].isin(nbfrb_keys.keys()), 'nbfrb_gesture'] = df['gesture'].map(nbfrb_keys)\n\n#     return df","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.316770Z","iopub.execute_input":"2025-09-01T17:11:48.317090Z","iopub.status.idle":"2025-09-01T17:11:48.334589Z","shell.execute_reply.started":"2025-09-01T17:11:48.317064Z","shell.execute_reply":"2025-09-01T17:11:48.333595Z"},"papermill":{"duration":0.03317,"end_time":"2025-08-13T10:53:13.217831","exception":false,"start_time":"2025-08-13T10:53:13.184661","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"4cce7240","cell_type":"code","source":"# updated_df = update_bfrb_columns(gesture_cat_df, loaded_bfrb_gesture_type_dictionary, loaded_nbfrb_gesture_type_dictionary)","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.335582Z","iopub.execute_input":"2025-09-01T17:11:48.335873Z","iopub.status.idle":"2025-09-01T17:11:48.354883Z","shell.execute_reply.started":"2025-09-01T17:11:48.335835Z","shell.execute_reply":"2025-09-01T17:11:48.353913Z"},"papermill":{"duration":0.032587,"end_time":"2025-08-13T10:53:13.276990","exception":false,"start_time":"2025-08-13T10:53:13.244403","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"8065c83b","cell_type":"code","source":"# # Number of random rows\n# n = 10\n# # Subset with n random rows\n# df_random_subset = updated_df.sample(n=n, random_state=42)  # Set random_state for reproducibility\n# df_random_subset.head(10)","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.355703Z","iopub.execute_input":"2025-09-01T17:11:48.355966Z","iopub.status.idle":"2025-09-01T17:11:48.372181Z","shell.execute_reply.started":"2025-09-01T17:11:48.355947Z","shell.execute_reply":"2025-09-01T17:11:48.371079Z"},"papermill":{"duration":0.032914,"end_time":"2025-08-13T10:53:13.336595","exception":false,"start_time":"2025-08-13T10:53:13.303681","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"c3687222","cell_type":"markdown","source":"- **Update all categorical columns to their numerical values based on value mapping dictionary**","metadata":{"papermill":{"duration":0.026028,"end_time":"2025-08-13T10:53:13.389003","exception":false,"start_time":"2025-08-13T10:53:13.362975","status":"completed"},"tags":[]}},{"id":"c5e37ccb","cell_type":"code","source":"# folder = '/kaggle/usr/lib/cmi-detect-gesture-with-a-wrist-worm-device/competition-data/final-data'\n# loaded_cat_value_map = my_utils.handle_pickle_dict(folder=folder, pickle_filename='cat_value_mapping_dictionary.pkl')\n# gesture_cat_df = my_utils.update_dataframe_values(updated_df, columns_to_update=CAT_COLUMNS, value_map=loaded_cat_value_map)","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.373271Z","iopub.execute_input":"2025-09-01T17:11:48.373643Z","iopub.status.idle":"2025-09-01T17:11:48.387649Z","shell.execute_reply.started":"2025-09-01T17:11:48.373616Z","shell.execute_reply":"2025-09-01T17:11:48.386684Z"},"papermill":{"duration":0.033089,"end_time":"2025-08-13T10:53:13.449152","exception":false,"start_time":"2025-08-13T10:53:13.416063","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"623c5015","cell_type":"code","source":"# # Number of random rows\n# n = 10\n# # Subset with n random rows\n# df_random_subset = gesture_cat_df.sample(n=n, random_state=42)  # Set random_state for reproducibility\n# df_random_subset.head(10)","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.388654Z","iopub.execute_input":"2025-09-01T17:11:48.388959Z","iopub.status.idle":"2025-09-01T17:11:48.405445Z","shell.execute_reply.started":"2025-09-01T17:11:48.388933Z","shell.execute_reply":"2025-09-01T17:11:48.404656Z"},"papermill":{"duration":0.032822,"end_time":"2025-08-13T10:53:13.508823","exception":false,"start_time":"2025-08-13T10:53:13.476001","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"8c44ed55","cell_type":"markdown","source":"- **Save categories dataset**","metadata":{"papermill":{"duration":0.027212,"end_time":"2025-08-13T10:53:13.562744","exception":false,"start_time":"2025-08-13T10:53:13.535532","status":"completed"},"tags":[]}},{"id":"6bf3cd12","cell_type":"code","source":"# # Save to CSV\n# filepath = data_folders_dictionary['final_data'] / Path('cat_dataset.csv')\n# gesture_cat_df.to_csv(filepath, index=False)","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.406465Z","iopub.execute_input":"2025-09-01T17:11:48.406798Z","iopub.status.idle":"2025-09-01T17:11:48.419861Z","shell.execute_reply.started":"2025-09-01T17:11:48.406772Z","shell.execute_reply":"2025-09-01T17:11:48.418941Z"},"papermill":{"duration":0.033488,"end_time":"2025-08-13T10:53:13.623547","exception":false,"start_time":"2025-08-13T10:53:13.590059","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"75e72cce","cell_type":"markdown","source":"###   **1.2 CAT+IMU DATASET**","metadata":{"papermill":{"duration":0.026216,"end_time":"2025-08-13T10:53:13.676690","exception":false,"start_time":"2025-08-13T10:53:13.650474","status":"completed"},"tags":[]}},{"id":"20678c07","cell_type":"code","source":"# filepath = Path('/kaggle/usr/lib/cmi-detect-gesture-with-a-wrist-worm-device/competition-data/process-data/full_rot_imu_merged_dataset.csv')\n# imu_df = pd.read_csv(filepath, sep=',', encoding='utf-8', na_filter=True)","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.420879Z","iopub.execute_input":"2025-09-01T17:11:48.421496Z","iopub.status.idle":"2025-09-01T17:11:48.436183Z","shell.execute_reply.started":"2025-09-01T17:11:48.421471Z","shell.execute_reply":"2025-09-01T17:11:48.434789Z"},"papermill":{"duration":0.032663,"end_time":"2025-08-13T10:53:13.736438","exception":false,"start_time":"2025-08-13T10:53:13.703775","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"9c418e3d","cell_type":"markdown","source":"**Compute orientation invariant imu features**","metadata":{"papermill":{"duration":0.026905,"end_time":"2025-08-13T10:53:13.791688","exception":false,"start_time":"2025-08-13T10:53:13.764783","status":"completed"},"tags":[]}},{"id":"0b5aa53e","cell_type":"code","source":"# imu_orientation_invariant_df = my_utils.compute_orientation_invariant_features(imu_df)","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.437676Z","iopub.execute_input":"2025-09-01T17:11:48.438002Z","iopub.status.idle":"2025-09-01T17:11:48.450672Z","shell.execute_reply.started":"2025-09-01T17:11:48.437979Z","shell.execute_reply":"2025-09-01T17:11:48.449859Z"},"papermill":{"duration":0.033013,"end_time":"2025-08-13T10:53:13.851487","exception":false,"start_time":"2025-08-13T10:53:13.818474","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"249d008d","cell_type":"code","source":"# imu_orientation_invariant_df.head(5)","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.451682Z","iopub.execute_input":"2025-09-01T17:11:48.452392Z","iopub.status.idle":"2025-09-01T17:11:48.466371Z","shell.execute_reply.started":"2025-09-01T17:11:48.452365Z","shell.execute_reply":"2025-09-01T17:11:48.465324Z"},"papermill":{"duration":0.034124,"end_time":"2025-08-13T10:53:13.912593","exception":false,"start_time":"2025-08-13T10:53:13.878469","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"fce9a138","cell_type":"code","source":"# print(len(imu_orientation_invariant_df))","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.467327Z","iopub.execute_input":"2025-09-01T17:11:48.467663Z","iopub.status.idle":"2025-09-01T17:11:48.485771Z","shell.execute_reply.started":"2025-09-01T17:11:48.467642Z","shell.execute_reply":"2025-09-01T17:11:48.484735Z"},"papermill":{"duration":0.033481,"end_time":"2025-08-13T10:53:13.973766","exception":false,"start_time":"2025-08-13T10:53:13.940285","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"88aea911","cell_type":"code","source":"# # Number of random rows\n# n = 10\n# # Subset with n random rows\n# df_random_subset = imu_orientation_invariant_df.sample(n=n, random_state=42)  # Set random_state for reproducibility\n# df_random_subset.head(10)","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.486860Z","iopub.execute_input":"2025-09-01T17:11:48.487168Z","iopub.status.idle":"2025-09-01T17:11:48.503097Z","shell.execute_reply.started":"2025-09-01T17:11:48.487141Z","shell.execute_reply":"2025-09-01T17:11:48.502312Z"},"papermill":{"duration":0.034637,"end_time":"2025-08-13T10:53:14.036759","exception":false,"start_time":"2025-08-13T10:53:14.002122","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"5c91164f","cell_type":"markdown","source":"**Merge category dataset and imu dataset**","metadata":{"papermill":{"duration":0.026569,"end_time":"2025-08-13T10:53:14.090392","exception":false,"start_time":"2025-08-13T10:53:14.063823","status":"completed"},"tags":[]}},{"id":"b2e5f14a","cell_type":"code","source":"# gesture_cat_df = kagglehub.dataset_load(KaggleDatasetAdapter.PANDAS,\"pira245/cmi-dataset\",\"mapped_categorical_dataset.csv\",)\n# gesture_cat_df.head(5)","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.503988Z","iopub.execute_input":"2025-09-01T17:11:48.504278Z","iopub.status.idle":"2025-09-01T17:11:48.519759Z","shell.execute_reply.started":"2025-09-01T17:11:48.504253Z","shell.execute_reply":"2025-09-01T17:11:48.518783Z"},"papermill":{"duration":0.03418,"end_time":"2025-08-13T10:53:14.267349","exception":false,"start_time":"2025-08-13T10:53:14.233169","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"f529542c","cell_type":"code","source":"# # Example: check shape and index\n# for df in [gesture_cat_df, imu_orientation_invariant_df]:\n#     print(len(df), df.index.is_unique)","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.520797Z","iopub.execute_input":"2025-09-01T17:11:48.521118Z","iopub.status.idle":"2025-09-01T17:11:48.535162Z","shell.execute_reply.started":"2025-09-01T17:11:48.521092Z","shell.execute_reply":"2025-09-01T17:11:48.534299Z"},"papermill":{"duration":0.033137,"end_time":"2025-08-13T10:53:14.389888","exception":false,"start_time":"2025-08-13T10:53:14.356751","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"183d6c4e","cell_type":"code","source":"# # Reset index before concatenation to align rows by position, not by index label\n# full_imu_merged_df = pd.concat([\n#     gesture_cat_df.reset_index(drop=True),\n#     imu_orientation_invariant_df.reset_index(drop=True),\n# ], axis=1)\n# print(len(full_imu_merged_df))","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.536183Z","iopub.execute_input":"2025-09-01T17:11:48.536482Z","iopub.status.idle":"2025-09-01T17:11:48.552675Z","shell.execute_reply.started":"2025-09-01T17:11:48.536457Z","shell.execute_reply":"2025-09-01T17:11:48.551822Z"},"papermill":{"duration":0.034087,"end_time":"2025-08-13T10:53:14.457931","exception":false,"start_time":"2025-08-13T10:53:14.423844","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"1cdb3720","cell_type":"code","source":"# full_imu_merged_df.head(5)","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.553573Z","iopub.execute_input":"2025-09-01T17:11:48.553804Z","iopub.status.idle":"2025-09-01T17:11:48.567184Z","shell.execute_reply.started":"2025-09-01T17:11:48.553786Z","shell.execute_reply":"2025-09-01T17:11:48.566299Z"},"papermill":{"duration":0.040468,"end_time":"2025-08-13T10:53:14.525934","exception":false,"start_time":"2025-08-13T10:53:14.485466","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"6b295854","cell_type":"markdown","source":"- **Save to csv**","metadata":{"papermill":{"duration":0.034097,"end_time":"2025-08-13T10:53:14.601017","exception":false,"start_time":"2025-08-13T10:53:14.566920","status":"completed"},"tags":[]}},{"id":"fab3860a","cell_type":"code","source":"# # # Save to CSV\n# filepath = data_folders_dictionary['final_data'] / Path('full_rot_imu_merged_df.csv')\n# full_imu_merged_df.to_csv(filepath, index=False)","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.568135Z","iopub.execute_input":"2025-09-01T17:11:48.568453Z","iopub.status.idle":"2025-09-01T17:11:48.583788Z","shell.execute_reply.started":"2025-09-01T17:11:48.568421Z","shell.execute_reply":"2025-09-01T17:11:48.582770Z"},"papermill":{"duration":0.033306,"end_time":"2025-08-13T10:53:14.661456","exception":false,"start_time":"2025-08-13T10:53:14.628150","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"669943e0","cell_type":"markdown","source":"###   **1.3 CAT+IMU+TEMPERATURE DATASET**","metadata":{"papermill":{"duration":0.027294,"end_time":"2025-08-13T10:53:14.716145","exception":false,"start_time":"2025-08-13T10:53:14.688851","status":"completed"},"tags":[]}},{"id":"a18c55e6","cell_type":"markdown","source":"- **Temperature dataset**","metadata":{"papermill":{"duration":0.026422,"end_time":"2025-08-13T10:53:14.769358","exception":false,"start_time":"2025-08-13T10:53:14.742936","status":"completed"},"tags":[]}},{"id":"c594a2d3","cell_type":"code","source":"# filepath = Path('/kaggle/usr/lib/cmi-detect-gesture-with-a-wrist-worm-device/competition-data/process-data/corrected_temperature_data.csv')\n# temp_df = pd.read_csv(filepath, sep=',', encoding='utf-8', na_filter=True)","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.584762Z","iopub.execute_input":"2025-09-01T17:11:48.585083Z","iopub.status.idle":"2025-09-01T17:11:48.599561Z","shell.execute_reply.started":"2025-09-01T17:11:48.585054Z","shell.execute_reply":"2025-09-01T17:11:48.598611Z"},"papermill":{"duration":0.03352,"end_time":"2025-08-13T10:53:14.830027","exception":false,"start_time":"2025-08-13T10:53:14.796507","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"902c9a5a","cell_type":"code","source":"# # Number of random rows\n# n = 10\n# # Subset with n random rows\n# df_random_subset = temp_df.sample(n=n, random_state=42)  # Set random_state for reproducibility\n# df_random_subset.head(10)","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.600670Z","iopub.execute_input":"2025-09-01T17:11:48.600983Z","iopub.status.idle":"2025-09-01T17:11:48.617092Z","shell.execute_reply.started":"2025-09-01T17:11:48.600956Z","shell.execute_reply":"2025-09-01T17:11:48.616163Z"},"papermill":{"duration":0.033588,"end_time":"2025-08-13T10:53:14.891929","exception":false,"start_time":"2025-08-13T10:53:14.858341","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"c08d4cab","cell_type":"code","source":"# # Example: check shape and index\n# for df in [full_imu_merged_df, temp_df]:\n#     print(len(df), df.index.is_unique)","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.622877Z","iopub.execute_input":"2025-09-01T17:11:48.623123Z","iopub.status.idle":"2025-09-01T17:11:48.636342Z","shell.execute_reply.started":"2025-09-01T17:11:48.623106Z","shell.execute_reply":"2025-09-01T17:11:48.635350Z"},"papermill":{"duration":0.033455,"end_time":"2025-08-13T10:53:15.127793","exception":false,"start_time":"2025-08-13T10:53:15.094338","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"65bedef0","cell_type":"code","source":"# # Reset index before concatenation to align rows by position, not by index label\n# full_imu_temp_merged_df = pd.concat([\n#     full_imu_merged_df.reset_index(drop=True),\n#     temp_df.reset_index(drop=True),\n# ], axis=1)\n# print(len(full_imu_temp_merged_df))","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.637219Z","iopub.execute_input":"2025-09-01T17:11:48.637513Z","iopub.status.idle":"2025-09-01T17:11:48.651336Z","shell.execute_reply.started":"2025-09-01T17:11:48.637484Z","shell.execute_reply":"2025-09-01T17:11:48.650489Z"},"papermill":{"duration":0.032881,"end_time":"2025-08-13T10:53:15.188118","exception":false,"start_time":"2025-08-13T10:53:15.155237","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"68aa2dd6","cell_type":"code","source":"# full_imu_temp_merged_df.head(5)","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.652349Z","iopub.execute_input":"2025-09-01T17:11:48.652829Z","iopub.status.idle":"2025-09-01T17:11:48.668708Z","shell.execute_reply.started":"2025-09-01T17:11:48.652798Z","shell.execute_reply":"2025-09-01T17:11:48.667512Z"},"papermill":{"duration":0.032958,"end_time":"2025-08-13T10:53:15.248514","exception":false,"start_time":"2025-08-13T10:53:15.215556","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"63ce211e","cell_type":"markdown","source":"- **Save to csv**","metadata":{"papermill":{"duration":0.027596,"end_time":"2025-08-13T10:53:15.304327","exception":false,"start_time":"2025-08-13T10:53:15.276731","status":"completed"},"tags":[]}},{"id":"7ed12660","cell_type":"code","source":"# # # Save to CSV\n# filepath = data_folders_dictionary['final_data'] / Path('full_rot_imu_temp_merged_df.csv')\n# full_imu_temp_merged_df.to_csv(filepath, index=False)","metadata":{"execution":{"iopub.status.busy":"2025-09-01T17:11:48.670161Z","iopub.execute_input":"2025-09-01T17:11:48.670461Z","iopub.status.idle":"2025-09-01T17:11:48.686303Z","shell.execute_reply.started":"2025-09-01T17:11:48.670429Z","shell.execute_reply":"2025-09-01T17:11:48.685174Z"},"papermill":{"duration":0.034049,"end_time":"2025-08-13T10:53:15.365739","exception":false,"start_time":"2025-08-13T10:53:15.331690","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"2f7bb921","cell_type":"markdown","source":"<hr>","metadata":{"papermill":{"duration":0.02741,"end_time":"2025-08-13T10:53:15.420589","exception":false,"start_time":"2025-08-13T10:53:15.393179","status":"completed"},"tags":[]}}]}