{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.11","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":102335,"databundleVersionId":12518947,"sourceType":"competition"}],"dockerImageVersionId":31040,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:02.243421Z","iopub.execute_input":"2025-06-05T15:49:02.243646Z","iopub.status.idle":"2025-06-05T15:49:02.522461Z","shell.execute_reply.started":"2025-06-05T15:49:02.243604Z","shell.execute_reply":"2025-06-05T15:49:02.521726Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:02.523134Z","iopub.execute_input":"2025-06-05T15:49:02.523426Z","iopub.status.idle":"2025-06-05T15:49:02.998796Z","shell.execute_reply.started":"2025-06-05T15:49:02.523410Z","shell.execute_reply":"2025-06-05T15:49:02.997866Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\ndf_train = pd.read_csv('/kaggle/input/cmi-detect-behavior-with-sensor-data/train.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:03.000584Z","iopub.execute_input":"2025-06-05T15:49:03.000996Z","iopub.status.idle":"2025-06-05T15:49:28.403152Z","shell.execute_reply.started":"2025-06-05T15:49:03.000974Z","shell.execute_reply":"2025-06-05T15:49:28.402406Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_demographics = pd.read_csv('/kaggle/input/cmi-detect-behavior-with-sensor-data/train_demographics.csv')\n\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:28.403775Z","iopub.execute_input":"2025-06-05T15:49:28.403966Z","iopub.status.idle":"2025-06-05T15:49:28.411773Z","shell.execute_reply.started":"2025-06-05T15:49:28.403951Z","shell.execute_reply":"2025-06-05T15:49:28.410924Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:28.412850Z","iopub.execute_input":"2025-06-05T15:49:28.413182Z","iopub.status.idle":"2025-06-05T15:49:28.479713Z","shell.execute_reply.started":"2025-06-05T15:49:28.413162Z","shell.execute_reply":"2025-06-05T15:49:28.479016Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_demographics.head(20)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:28.480815Z","iopub.execute_input":"2025-06-05T15:49:28.481110Z","iopub.status.idle":"2025-06-05T15:49:28.493985Z","shell.execute_reply.started":"2025-06-05T15:49:28.481084Z","shell.execute_reply":"2025-06-05T15:49:28.493323Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_test = pd.read_csv('/kaggle/input/cmi-detect-behavior-with-sensor-data/test.csv')\ndf_test.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:28.494650Z","iopub.execute_input":"2025-06-05T15:49:28.494868Z","iopub.status.idle":"2025-06-05T15:49:28.539338Z","shell.execute_reply.started":"2025-06-05T15:49:28.494848Z","shell.execute_reply":"2025-06-05T15:49:28.538553Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_train['gesture'].value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:28.540048Z","iopub.execute_input":"2025-06-05T15:49:28.540299Z","iopub.status.idle":"2025-06-05T15:49:28.579477Z","shell.execute_reply.started":"2025-06-05T15:49:28.540280Z","shell.execute_reply":"2025-06-05T15:49:28.578666Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_merged = df_train.merge(df_demographics, on='subject')\ndf_merged.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:28.582818Z","iopub.execute_input":"2025-06-05T15:49:28.583115Z","iopub.status.idle":"2025-06-05T15:49:28.915945Z","shell.execute_reply.started":"2025-06-05T15:49:28.583090Z","shell.execute_reply":"2025-06-05T15:49:28.915100Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_merged.columns","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:28.916811Z","iopub.execute_input":"2025-06-05T15:49:28.917005Z","iopub.status.idle":"2025-06-05T15:49:28.922131Z","shell.execute_reply.started":"2025-06-05T15:49:28.916982Z","shell.execute_reply":"2025-06-05T15:49:28.921540Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_merged.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:28.922915Z","iopub.execute_input":"2025-06-05T15:49:28.923183Z","iopub.status.idle":"2025-06-05T15:49:28.958451Z","shell.execute_reply.started":"2025-06-05T15:49:28.923165Z","shell.execute_reply":"2025-06-05T15:49:28.957275Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\n\npd.set_option('display.max_rows', 400)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:28.959680Z","iopub.execute_input":"2025-06-05T15:49:28.960678Z","iopub.status.idle":"2025-06-05T15:49:28.975395Z","shell.execute_reply.started":"2025-06-05T15:49:28.960636Z","shell.execute_reply":"2025-06-05T15:49:28.974498Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"missing_data = df_merged.isnull().sum()\nmissing_data","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:28.976323Z","iopub.execute_input":"2025-06-05T15:49:28.976593Z","iopub.status.idle":"2025-06-05T15:49:29.402228Z","shell.execute_reply.started":"2025-06-05T15:49:28.976578Z","shell.execute_reply":"2025-06-05T15:49:29.401554Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_merged.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:29.402914Z","iopub.execute_input":"2025-06-05T15:49:29.403117Z","iopub.status.idle":"2025-06-05T15:49:29.409674Z","shell.execute_reply.started":"2025-06-05T15:49:29.403101Z","shell.execute_reply":"2025-06-05T15:49:29.408454Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pd.set_option('display.max_rows', 400)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:29.410659Z","iopub.execute_input":"2025-06-05T15:49:29.410927Z","iopub.status.idle":"2025-06-05T15:49:29.430701Z","shell.execute_reply.started":"2025-06-05T15:49:29.410902Z","shell.execute_reply":"2025-06-05T15:49:29.429395Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(df_merged.columns.tolist())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:29.431815Z","iopub.execute_input":"2025-06-05T15:49:29.432051Z","iopub.status.idle":"2025-06-05T15:49:29.454308Z","shell.execute_reply.started":"2025-06-05T15:49:29.432033Z","shell.execute_reply":"2025-06-05T15:49:29.453084Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"columns_to_drop = ['thm_1', 'thm_2', 'thm_3', 'thm_4', 'thm_5', 'tof_1_v0', 'tof_1_v1', 'tof_1_v2', 'tof_1_v3', 'tof_1_v4', 'tof_1_v5', 'tof_1_v6', 'tof_1_v7', 'tof_1_v8', 'tof_1_v9', 'tof_1_v10', 'tof_1_v11', 'tof_1_v12', 'tof_1_v13', 'tof_1_v14', 'tof_1_v15', 'tof_1_v16', 'tof_1_v17', 'tof_1_v18', 'tof_1_v19', 'tof_1_v20', 'tof_1_v21', 'tof_1_v22', 'tof_1_v23', 'tof_1_v24', 'tof_1_v25', 'tof_1_v26', 'tof_1_v27', 'tof_1_v28', 'tof_1_v29', 'tof_1_v30', 'tof_1_v31', 'tof_1_v32', 'tof_1_v33', 'tof_1_v34', 'tof_1_v35', 'tof_1_v36', 'tof_1_v37', 'tof_1_v38', 'tof_1_v39', 'tof_1_v40', 'tof_1_v41', 'tof_1_v42', 'tof_1_v43', 'tof_1_v44', 'tof_1_v45', 'tof_1_v46', 'tof_1_v47', 'tof_1_v48', 'tof_1_v49', 'tof_1_v50', 'tof_1_v51', 'tof_1_v52', 'tof_1_v53', 'tof_1_v54', 'tof_1_v55', 'tof_1_v56', 'tof_1_v57', 'tof_1_v58', 'tof_1_v59', 'tof_1_v60', 'tof_1_v61', 'tof_1_v62', 'tof_1_v63', 'tof_2_v0', 'tof_2_v1', 'tof_2_v2', 'tof_2_v3', 'tof_2_v4', 'tof_2_v5', 'tof_2_v6', 'tof_2_v7', 'tof_2_v8', 'tof_2_v9', 'tof_2_v10', 'tof_2_v11', 'tof_2_v12', 'tof_2_v13', 'tof_2_v14', 'tof_2_v15', 'tof_2_v16', 'tof_2_v17', 'tof_2_v18', 'tof_2_v19', 'tof_2_v20', 'tof_2_v21', 'tof_2_v22', 'tof_2_v23', 'tof_2_v24', 'tof_2_v25', 'tof_2_v26', 'tof_2_v27', 'tof_2_v28', 'tof_2_v29', 'tof_2_v30', 'tof_2_v31', 'tof_2_v32', 'tof_2_v33', 'tof_2_v34', 'tof_2_v35', 'tof_2_v36', 'tof_2_v37', 'tof_2_v38', 'tof_2_v39', 'tof_2_v40', 'tof_2_v41', 'tof_2_v42', 'tof_2_v43', 'tof_2_v44', 'tof_2_v45', 'tof_2_v46', 'tof_2_v47', 'tof_2_v48', 'tof_2_v49', 'tof_2_v50', 'tof_2_v51', 'tof_2_v52', 'tof_2_v53', 'tof_2_v54', 'tof_2_v55', 'tof_2_v56', 'tof_2_v57', 'tof_2_v58', 'tof_2_v59', 'tof_2_v60', 'tof_2_v61', 'tof_2_v62', 'tof_2_v63', 'tof_3_v0', 'tof_3_v1', 'tof_3_v2', 'tof_3_v3', 'tof_3_v4', 'tof_3_v5', 'tof_3_v6', 'tof_3_v7', 'tof_3_v8', 'tof_3_v9', 'tof_3_v10', 'tof_3_v11', 'tof_3_v12', 'tof_3_v13', 'tof_3_v14', 'tof_3_v15', 'tof_3_v16', 'tof_3_v17', 'tof_3_v18', 'tof_3_v19', 'tof_3_v20', 'tof_3_v21', 'tof_3_v22', 'tof_3_v23', 'tof_3_v24', 'tof_3_v25', 'tof_3_v26', 'tof_3_v27', 'tof_3_v28', 'tof_3_v29', 'tof_3_v30', 'tof_3_v31', 'tof_3_v32', 'tof_3_v33', 'tof_3_v34', 'tof_3_v35', 'tof_3_v36', 'tof_3_v37', 'tof_3_v38', 'tof_3_v39', 'tof_3_v40', 'tof_3_v41', 'tof_3_v42', 'tof_3_v43', 'tof_3_v44', 'tof_3_v45', 'tof_3_v46', 'tof_3_v47', 'tof_3_v48', 'tof_3_v49', 'tof_3_v50', 'tof_3_v51', 'tof_3_v52', 'tof_3_v53', 'tof_3_v54', 'tof_3_v55', 'tof_3_v56', 'tof_3_v57', 'tof_3_v58', 'tof_3_v59', 'tof_3_v60', 'tof_3_v61', 'tof_3_v62', 'tof_3_v63', 'tof_4_v0', 'tof_4_v1', 'tof_4_v2', 'tof_4_v3', 'tof_4_v4', 'tof_4_v5', 'tof_4_v6', 'tof_4_v7', 'tof_4_v8', 'tof_4_v9', 'tof_4_v10', 'tof_4_v11', 'tof_4_v12', 'tof_4_v13', 'tof_4_v14', 'tof_4_v15', 'tof_4_v16', 'tof_4_v17', 'tof_4_v18', 'tof_4_v19', 'tof_4_v20', 'tof_4_v21', 'tof_4_v22', 'tof_4_v23', 'tof_4_v24', 'tof_4_v25', 'tof_4_v26', 'tof_4_v27', 'tof_4_v28', 'tof_4_v29', 'tof_4_v30', 'tof_4_v31', 'tof_4_v32', 'tof_4_v33', 'tof_4_v34', 'tof_4_v35', 'tof_4_v36', 'tof_4_v37', 'tof_4_v38', 'tof_4_v39', 'tof_4_v40', 'tof_4_v41', 'tof_4_v42', 'tof_4_v43', 'tof_4_v44', 'tof_4_v45', 'tof_4_v46', 'tof_4_v47', 'tof_4_v48', 'tof_4_v49', 'tof_4_v50', 'tof_4_v51', 'tof_4_v52', 'tof_4_v53', 'tof_4_v54', 'tof_4_v55', 'tof_4_v56', 'tof_4_v57', 'tof_4_v58', 'tof_4_v59', 'tof_4_v60', 'tof_4_v61', 'tof_4_v62', 'tof_4_v63', 'tof_5_v0', 'tof_5_v1', 'tof_5_v2', 'tof_5_v3', 'tof_5_v4', 'tof_5_v5', 'tof_5_v6', 'tof_5_v7', 'tof_5_v8', 'tof_5_v9', 'tof_5_v10', 'tof_5_v11', 'tof_5_v12', 'tof_5_v13', 'tof_5_v14', 'tof_5_v15', 'tof_5_v16', 'tof_5_v17', 'tof_5_v18', 'tof_5_v19', 'tof_5_v20', 'tof_5_v21', 'tof_5_v22', 'tof_5_v23', 'tof_5_v24', 'tof_5_v25', 'tof_5_v26', 'tof_5_v27', 'tof_5_v28', 'tof_5_v29', 'tof_5_v30', 'tof_5_v31', 'tof_5_v32', 'tof_5_v33', 'tof_5_v34', 'tof_5_v35', 'tof_5_v36', 'tof_5_v37', 'tof_5_v38', 'tof_5_v39', 'tof_5_v40', 'tof_5_v41', 'tof_5_v42', 'tof_5_v43', 'tof_5_v44', 'tof_5_v45', 'tof_5_v46', 'tof_5_v47', 'tof_5_v48', 'tof_5_v49', 'tof_5_v50', 'tof_5_v51', 'tof_5_v52', 'tof_5_v53', 'tof_5_v54', 'tof_5_v55', 'tof_5_v56', 'tof_5_v57', 'tof_5_v58', 'tof_5_v59', 'tof_5_v60', 'tof_5_v61', 'tof_5_v62', 'tof_5_v63']\nprint(columns_to_drop)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:29.455317Z","iopub.execute_input":"2025-06-05T15:49:29.455585Z","iopub.status.idle":"2025-06-05T15:49:29.481312Z","shell.execute_reply.started":"2025-06-05T15:49:29.455566Z","shell.execute_reply":"2025-06-05T15:49:29.480415Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_imu = df_merged.drop(columns=columns_to_drop, axis=1)\ndf_imu.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:29.482441Z","iopub.execute_input":"2025-06-05T15:49:29.482716Z","iopub.status.idle":"2025-06-05T15:49:29.535307Z","shell.execute_reply.started":"2025-06-05T15:49:29.482695Z","shell.execute_reply":"2025-06-05T15:49:29.534249Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"missing_data_imu = df_imu.isnull().sum()\nmissing_data_imu","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:29.536504Z","iopub.execute_input":"2025-06-05T15:49:29.536865Z","iopub.status.idle":"2025-06-05T15:49:29.707780Z","shell.execute_reply.started":"2025-06-05T15:49:29.536841Z","shell.execute_reply":"2025-06-05T15:49:29.706912Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"msk = df_imu['rot_w'].isna()\ntemp = df_imu[msk]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:29.708538Z","iopub.execute_input":"2025-06-05T15:49:29.708766Z","iopub.status.idle":"2025-06-05T15:49:29.716056Z","shell.execute_reply.started":"2025-06-05T15:49:29.708750Z","shell.execute_reply":"2025-06-05T15:49:29.715080Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"temp['sequence_id'].value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:29.717347Z","iopub.execute_input":"2025-06-05T15:49:29.717703Z","iopub.status.idle":"2025-06-05T15:49:29.738877Z","shell.execute_reply.started":"2025-06-05T15:49:29.717677Z","shell.execute_reply":"2025-06-05T15:49:29.738063Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_imu['sequence_id'].unique().shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:29.740096Z","iopub.execute_input":"2025-06-05T15:49:29.740503Z","iopub.status.idle":"2025-06-05T15:49:29.783717Z","shell.execute_reply.started":"2025-06-05T15:49:29.740482Z","shell.execute_reply":"2025-06-05T15:49:29.782658Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Summary of the Situation\nWe have:\n\nTotal sequences: 8,151\n\nSequences with missing rotation data: 49\n\n% Affected: ~0.60%\n\nMissing values per sequence: 46–114 rows each","metadata":{}},{"cell_type":"code","source":"sequences_to_remove = temp['sequence_id'].unique().tolist()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:29.784694Z","iopub.execute_input":"2025-06-05T15:49:29.784979Z","iopub.status.idle":"2025-06-05T15:49:29.790646Z","shell.execute_reply.started":"2025-06-05T15:49:29.784948Z","shell.execute_reply":"2025-06-05T15:49:29.789378Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_imu = df_imu[~df_imu['sequence_id'].isin(sequences_to_remove)].reset_index(drop=True)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:29.791467Z","iopub.execute_input":"2025-06-05T15:49:29.791780Z","iopub.status.idle":"2025-06-05T15:49:29.925906Z","shell.execute_reply.started":"2025-06-05T15:49:29.791756Z","shell.execute_reply":"2025-06-05T15:49:29.925158Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"missing_data = df_imu.isnull().sum()\nmissing_data","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:29.926690Z","iopub.execute_input":"2025-06-05T15:49:29.926909Z","iopub.status.idle":"2025-06-05T15:49:30.096188Z","shell.execute_reply.started":"2025-06-05T15:49:29.926891Z","shell.execute_reply":"2025-06-05T15:49:30.095156Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_imu.dtypes","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:30.097183Z","iopub.execute_input":"2025-06-05T15:49:30.097415Z","iopub.status.idle":"2025-06-05T15:49:30.103715Z","shell.execute_reply.started":"2025-06-05T15:49:30.097395Z","shell.execute_reply":"2025-06-05T15:49:30.102959Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"le = LabelEncoder()\ndf_imu['gesture_encoded'] = le.fit_transform(df_imu['gesture'])\ndf_imu[['gesture_encoded', 'gesture']].value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:30.108521Z","iopub.execute_input":"2025-06-05T15:49:30.108821Z","iopub.status.idle":"2025-06-05T15:49:30.235606Z","shell.execute_reply.started":"2025-06-05T15:49:30.108799Z","shell.execute_reply":"2025-06-05T15:49:30.234551Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_imu[df_imu['sequence_id']=='SEQ_000008']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:30.236400Z","iopub.execute_input":"2025-06-05T15:49:30.236656Z","iopub.status.idle":"2025-06-05T15:49:30.297488Z","shell.execute_reply.started":"2025-06-05T15:49:30.236596Z","shell.execute_reply":"2025-06-05T15:49:30.296853Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_imu.dtypes","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:30.298126Z","iopub.execute_input":"2025-06-05T15:49:30.298287Z","iopub.status.idle":"2025-06-05T15:49:30.304852Z","shell.execute_reply.started":"2025-06-05T15:49:30.298274Z","shell.execute_reply":"2025-06-05T15:49:30.303880Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_new = df_imu.copy()\ndf_new.columns","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:30.305365Z","iopub.execute_input":"2025-06-05T15:49:30.305566Z","iopub.status.idle":"2025-06-05T15:49:30.355345Z","shell.execute_reply.started":"2025-06-05T15:49:30.305553Z","shell.execute_reply":"2025-06-05T15:49:30.354322Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.preprocessing import OneHotEncoder","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:30.356074Z","iopub.execute_input":"2025-06-05T15:49:30.356310Z","iopub.status.idle":"2025-06-05T15:49:30.359903Z","shell.execute_reply.started":"2025-06-05T15:49:30.356289Z","shell.execute_reply":"2025-06-05T15:49:30.359298Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_imu.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:30.360654Z","iopub.execute_input":"2025-06-05T15:49:30.360929Z","iopub.status.idle":"2025-06-05T15:49:30.389780Z","shell.execute_reply.started":"2025-06-05T15:49:30.360909Z","shell.execute_reply":"2025-06-05T15:49:30.388640Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"cat_col = df_imu.select_dtypes(include=['object'])\ncat_col.columns","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:30.390591Z","iopub.execute_input":"2025-06-05T15:49:30.390862Z","iopub.status.idle":"2025-06-05T15:49:30.425312Z","shell.execute_reply.started":"2025-06-05T15:49:30.390842Z","shell.execute_reply":"2025-06-05T15:49:30.424541Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# !pip install numpy==1.24.3 --force-reinstall\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:30.426571Z","iopub.execute_input":"2025-06-05T15:49:30.426896Z","iopub.status.idle":"2025-06-05T15:49:30.430211Z","shell.execute_reply.started":"2025-06-05T15:49:30.426862Z","shell.execute_reply":"2025-06-05T15:49:30.429538Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import seaborn as sns\nimport matplotlib.pyplot as plt\n\nfor col in ['orientation', 'behavior', 'phase']:\n    plt.figure(figsize=(10, 5))\n    sns.countplot(data=df_imu, x=col, hue='gesture', order=df_imu[col].value_counts().index)\n    plt.title(f'Gesture distribution over {col}')\n    plt.xticks(rotation=45)\n    plt.tight_layout()\n    plt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:30.431023Z","iopub.execute_input":"2025-06-05T15:49:30.431268Z","iopub.status.idle":"2025-06-05T15:49:34.422763Z","shell.execute_reply.started":"2025-06-05T15:49:30.431244Z","shell.execute_reply":"2025-06-05T15:49:34.421814Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"num_col = df_imu.select_dtypes(include=['number'])\nnum_col.columns","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:34.423535Z","iopub.execute_input":"2025-06-05T15:49:34.423946Z","iopub.status.idle":"2025-06-05T15:49:34.444592Z","shell.execute_reply.started":"2025-06-05T15:49:34.423928Z","shell.execute_reply":"2025-06-05T15:49:34.443936Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for col in ['acc_x', 'acc_y', 'acc_z', 'rot_w', 'rot_x',\n       'rot_y', 'rot_z', 'adult_child', 'age', 'sex', 'handedness',\n       'height_cm', 'shoulder_to_wrist_cm', 'elbow_to_wrist_cm']:\n    plt.figure(figsize=(10, 5))\n    sns.boxplot(data=df_imu, x='gesture', y=col)\n    plt.title(f'{col} distribution per gesture')\n    plt.xticks(rotation=45)\n    plt.tight_layout()\n    plt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:34.445342Z","iopub.execute_input":"2025-06-05T15:49:34.445587Z","iopub.status.idle":"2025-06-05T15:49:41.326779Z","shell.execute_reply.started":"2025-06-05T15:49:34.445573Z","shell.execute_reply":"2025-06-05T15:49:41.325843Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_imu.groupby('sequence_id')['orientation'].nunique().value_counts()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:41.327890Z","iopub.execute_input":"2025-06-05T15:49:41.328129Z","iopub.status.idle":"2025-06-05T15:49:41.401635Z","shell.execute_reply.started":"2025-06-05T15:49:41.328107Z","shell.execute_reply":"2025-06-05T15:49:41.400673Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_imu[num_col.columns].corr()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:41.402332Z","iopub.execute_input":"2025-06-05T15:49:41.402550Z","iopub.status.idle":"2025-06-05T15:49:41.733221Z","shell.execute_reply.started":"2025-06-05T15:49:41.402532Z","shell.execute_reply":"2025-06-05T15:49:41.732485Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sequence_labels = df_imu[['sequence_id', 'gesture_encoded']].drop_duplicates()\n\nsequence_labels","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:41.734133Z","iopub.execute_input":"2025-06-05T15:49:41.734470Z","iopub.status.idle":"2025-06-05T15:49:41.787024Z","shell.execute_reply.started":"2025-06-05T15:49:41.734442Z","shell.execute_reply":"2025-06-05T15:49:41.786267Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.model_selection import StratifiedShuffleSplit\n\nstrat_split = StratifiedShuffleSplit(n_splits=1, test_size=0.2, random_state=42)\n\n# Step 3: Generate train/val sequence IDs\nfor train_idx, val_idx in strat_split.split(sequence_labels['sequence_id'], sequence_labels['gesture_encoded']):\n    train_ids = sequence_labels.iloc[train_idx]\n    val_ids = sequence_labels.iloc[val_idx]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:41.787866Z","iopub.execute_input":"2025-06-05T15:49:41.788114Z","iopub.status.idle":"2025-06-05T15:49:41.917445Z","shell.execute_reply.started":"2025-06-05T15:49:41.788093Z","shell.execute_reply":"2025-06-05T15:49:41.916595Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_seq_ids = train_ids['sequence_id'].values\nval_seq_ids = val_ids['sequence_id'].values\n\ndf_train_imu = df_imu[df_imu['sequence_id'].isin(train_seq_ids)]\ndf_val_imu = df_imu[df_imu['sequence_id'].isin(val_seq_ids)]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:41.918639Z","iopub.execute_input":"2025-06-05T15:49:41.918882Z","iopub.status.idle":"2025-06-05T15:49:41.994660Z","shell.execute_reply.started":"2025-06-05T15:49:41.918862Z","shell.execute_reply":"2025-06-05T15:49:41.993850Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(df_train_imu.shape)\nprint(df_val_imu.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:41.995595Z","iopub.execute_input":"2025-06-05T15:49:41.995899Z","iopub.status.idle":"2025-06-05T15:49:42.000901Z","shell.execute_reply.started":"2025-06-05T15:49:41.995876Z","shell.execute_reply":"2025-06-05T15:49:42.000083Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def aggregate_features(df):\n    agg = df.groupby('sequence_id').agg({\n        'acc_x': ['mean', 'std'],\n        'acc_y': ['mean', 'std'],\n        'acc_z': ['mean', 'std'],\n        'rot_w': ['mean', 'std'],\n        'rot_x': ['mean', 'std'],\n        'rot_y': ['mean', 'std'],\n        'rot_z': ['mean', 'std'],\n        # Add other sensor features here\n    }).reset_index()\n    agg.columns = ['_'.join(col).strip('_') for col in agg.columns]\n    return agg\n\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:42.001556Z","iopub.execute_input":"2025-06-05T15:49:42.001940Z","iopub.status.idle":"2025-06-05T15:49:42.018442Z","shell.execute_reply.started":"2025-06-05T15:49:42.001920Z","shell.execute_reply":"2025-06-05T15:49:42.017705Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train = aggregate_features(df_train_imu)\nX_val = aggregate_features(df_val_imu)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:42.019872Z","iopub.execute_input":"2025-06-05T15:49:42.020189Z","iopub.status.idle":"2025-06-05T15:49:42.160778Z","shell.execute_reply.started":"2025-06-05T15:49:42.020143Z","shell.execute_reply":"2025-06-05T15:49:42.160088Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:42.161476Z","iopub.execute_input":"2025-06-05T15:49:42.161689Z","iopub.status.idle":"2025-06-05T15:49:42.173683Z","shell.execute_reply.started":"2025-06-05T15:49:42.161671Z","shell.execute_reply":"2025-06-05T15:49:42.172871Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"seq_id_train = df_train_imu[['sequence_id', 'gesture_encoded']].drop_duplicates()\nseq_id_val = df_val_imu[['sequence_id', 'gesture_encoded']].drop_duplicates()\n\ndf_training = X_train.merge(seq_id_train, on='sequence_id', how='left')\ndf_validation = X_val.merge(seq_id_val, on='sequence_id', how='left')\ndf_training.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:42.174642Z","iopub.execute_input":"2025-06-05T15:49:42.174865Z","iopub.status.idle":"2025-06-05T15:49:42.240961Z","shell.execute_reply.started":"2025-06-05T15:49:42.174846Z","shell.execute_reply":"2025-06-05T15:49:42.239784Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def frequency_encode_categoricals(df, categorical_cols):\n    freq_features = []\n    for col in categorical_cols:\n        counts = pd.crosstab(df['sequence_id'], df[col], normalize='index')\n        counts.columns = [f'{col}_freq_{c}' for c in counts.columns]\n        freq_features.append(counts)\n    return pd.concat(freq_features, axis=1).reset_index()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:42.242175Z","iopub.execute_input":"2025-06-05T15:49:42.242550Z","iopub.status.idle":"2025-06-05T15:49:42.247104Z","shell.execute_reply.started":"2025-06-05T15:49:42.242527Z","shell.execute_reply":"2025-06-05T15:49:42.246401Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"cat_train = frequency_encode_categoricals(df_train_imu, ['behavior', 'phase'])\ncat_val = frequency_encode_categoricals(df_val_imu, ['behavior', 'phase'])\n\ncat_train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:42.247730Z","iopub.execute_input":"2025-06-05T15:49:42.247926Z","iopub.status.idle":"2025-06-05T15:49:42.922863Z","shell.execute_reply.started":"2025-06-05T15:49:42.247909Z","shell.execute_reply":"2025-06-05T15:49:42.921923Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_train_final = df_training.merge(cat_train, on='sequence_id', how='left')\ndf_val_final = df_validation.merge(cat_val, on='sequence_id', how='left')\n\ndf_train_final.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:42.923633Z","iopub.execute_input":"2025-06-05T15:49:42.923881Z","iopub.status.idle":"2025-06-05T15:49:42.948039Z","shell.execute_reply.started":"2025-06-05T15:49:42.923861Z","shell.execute_reply":"2025-06-05T15:49:42.946976Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sequence_ids_train = df_train_final['sequence_id'].copy()\nsequence_ids_val = df_val_final['sequence_id'].copy()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:42.948990Z","iopub.execute_input":"2025-06-05T15:49:42.949392Z","iopub.status.idle":"2025-06-05T15:49:42.954378Z","shell.execute_reply.started":"2025-06-05T15:49:42.949361Z","shell.execute_reply":"2025-06-05T15:49:42.953550Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train = df_train_final.drop(['gesture_encoded', 'sequence_id'], axis=1)\ny_train = df_train_final['gesture_encoded']\n\nX_val = df_val_final.drop(['gesture_encoded', 'sequence_id'], axis=1)\ny_val = df_val_final['gesture_encoded']\n\nprint(X_train.shape)\nprint(y_train.shape)\nprint(X_val.shape)\nprint(y_val.shape)\n\nX_train.head()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:42.955301Z","iopub.execute_input":"2025-06-05T15:49:42.955530Z","iopub.status.idle":"2025-06-05T15:49:42.989727Z","shell.execute_reply.started":"2025-06-05T15:49:42.955509Z","shell.execute_reply":"2025-06-05T15:49:42.988974Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.preprocessing import StandardScaler\nscaler = StandardScaler()\nX_train_scaled = scaler.fit_transform(X_train)\nX_val_scaled = scaler.transform(X_val)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:42.990371Z","iopub.execute_input":"2025-06-05T15:49:42.990647Z","iopub.status.idle":"2025-06-05T15:49:43.016392Z","shell.execute_reply.started":"2025-06-05T15:49:42.990603Z","shell.execute_reply":"2025-06-05T15:49:43.015679Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# !pip install scikit-learn==1.5.0\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:43.017352Z","iopub.execute_input":"2025-06-05T15:49:43.017573Z","iopub.status.idle":"2025-06-05T15:49:43.021946Z","shell.execute_reply.started":"2025-06-05T15:49:43.017557Z","shell.execute_reply":"2025-06-05T15:49:43.021008Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# !pip install -U scikit-learn imbalanced-learn\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:43.022744Z","iopub.execute_input":"2025-06-05T15:49:43.022984Z","iopub.status.idle":"2025-06-05T15:49:43.041056Z","shell.execute_reply.started":"2025-06-05T15:49:43.022962Z","shell.execute_reply":"2025-06-05T15:49:43.039750Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression\nfrom sklearn.svm import SVC\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.ensemble import GradientBoostingClassifier\nfrom sklearn.tree import DecisionTreeClassifier\nfrom sklearn.metrics import f1_score\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:43.042013Z","iopub.execute_input":"2025-06-05T15:49:43.042249Z","iopub.status.idle":"2025-06-05T15:49:43.441905Z","shell.execute_reply.started":"2025-06-05T15:49:43.042229Z","shell.execute_reply":"2025-06-05T15:49:43.441104Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"gesture_to_type = df_imu.drop_duplicates('gesture')[['gesture', 'sequence_type']].set_index('gesture')['sequence_type'].to_dict()\ngesture_to_type","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:43.442587Z","iopub.execute_input":"2025-06-05T15:49:43.442813Z","iopub.status.idle":"2025-06-05T15:49:43.463792Z","shell.execute_reply.started":"2025-06-05T15:49:43.442798Z","shell.execute_reply":"2025-06-05T15:49:43.463001Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def evaluate_bfrb_f1(y_true_encoded, y_pred_encoded, label_encoder, target_gestures):\n    \"\"\"\n    Evaluates Binary F1 and Macro F1 as per the BFRB competition rules.\n    \n    Parameters:\n    - y_true_encoded: array-like of encoded true gesture labels\n    - y_pred_encoded: array-like of encoded predicted gesture labels\n    - label_encoder: fitted sklearn.preprocessing.LabelEncoder\n    - target_gestures: list of gesture names considered as target gestures (BFRB)\n    \n    Returns:\n    - A dictionary with binary_f1, macro_f1, and final_score\n    \"\"\"\n    # Decode labels back to gesture names\n    y_true = label_encoder.inverse_transform(y_true_encoded)\n    y_pred = label_encoder.inverse_transform(y_pred_encoded)\n    \n    # Convert to binary: 'target' vs 'non_target'\n    y_true_binary = ['target' if gesture in target_gestures else 'non_target' for gesture in y_true]\n    y_pred_binary = ['target' if gesture in target_gestures else 'non_target' for gesture in y_pred]\n\n    binary_f1 = f1_score(y_true_binary, y_pred_binary, average='binary', pos_label='target')\n\n    # Collapse all non-target gestures into 'non_target' for macro F1\n    y_true_collapsed = [gesture if gesture in target_gestures else 'non_target' for gesture in y_true]\n    y_pred_collapsed = [gesture if gesture in target_gestures else 'non_target' for gesture in y_pred]\n\n    macro_f1 = f1_score(y_true_collapsed, y_pred_collapsed, average='macro')\n\n    final_score = (binary_f1 + macro_f1) / 2\n\n    return {\n        'binary_f1': binary_f1,\n        'macro_f1': macro_f1,\n        'final_score': final_score\n    }    ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:43.464646Z","iopub.execute_input":"2025-06-05T15:49:43.464905Z","iopub.status.idle":"2025-06-05T15:49:43.482436Z","shell.execute_reply.started":"2025-06-05T15:49:43.464884Z","shell.execute_reply":"2025-06-05T15:49:43.481708Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"temp = df_imu[df_imu['sequence_type']=='Target']\ntemp['gesture'].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:43.483137Z","iopub.execute_input":"2025-06-05T15:49:43.483309Z","iopub.status.idle":"2025-06-05T15:49:43.576145Z","shell.execute_reply.started":"2025-06-05T15:49:43.483296Z","shell.execute_reply":"2025-06-05T15:49:43.575105Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"target_gesture_names = ['Cheek - pinch skin', 'Forehead - pull hairline', 'Neck - scratch',\n       'Neck - pinch skin', 'Eyelash - pull hair', 'Eyebrow - pull hair',\n       'Forehead - scratch', 'Above ear - pull hair']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:43.577181Z","iopub.execute_input":"2025-06-05T15:49:43.577454Z","iopub.status.idle":"2025-06-05T15:49:43.582271Z","shell.execute_reply.started":"2025-06-05T15:49:43.577434Z","shell.execute_reply":"2025-06-05T15:49:43.581425Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"gbc = GradientBoostingClassifier(learning_rate=0.1, n_estimators=100, max_depth=10, subsample=0.5)\ngbc.fit(X_train, y_train)\n# y_pred_gbc = gbc.predict(X_val_scaled)\n\n# scores_gbc = evaluate_bfrb_f1(y_val, y_pred_gbc, le, target_gesture_names)\n\n# print(f\"Binary F1: {scores_gbc['binary_f1']:.4f}\")\n# print(f\"Macro F1: {scores_gbc['macro_f1']:.4f}\")\n# print(f\"Final Score: {scores_gbc['final_score']:.4f}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:49:43.582976Z","iopub.execute_input":"2025-06-05T15:49:43.583192Z","iopub.status.idle":"2025-06-05T15:51:29.611595Z","shell.execute_reply.started":"2025-06-05T15:49:43.583170Z","shell.execute_reply":"2025-06-05T15:51:29.610797Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model_rf = RandomForestClassifier(n_estimators=600, max_features='sqrt', min_samples_split=2, class_weight='balanced_subsample', max_depth=15, bootstrap=True)\nmodel_rf.fit(X_train, y_train)\n# y_pred_rf = model_rf.predict(X_val_scaled)\n# scores_rf = evaluate_bfrb_f1(y_val, y_pred_rf, le, target_gesture_names)\n\n# print(f\"Binary F1: {scores_rf['binary_f1']:.4f}\")\n# print(f\"Macro F1: {scores_rf['macro_f1']:.4f}\")\n# print(f\"Final Score: {scores_rf['final_score']:.4f}\")\n\n# train_pred = model_rf.predict(X_train_resampled)\n# f1_score(y_train_resampled, train_pred, average='macro')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:51:29.612599Z","iopub.execute_input":"2025-06-05T15:51:29.612960Z","iopub.status.idle":"2025-06-05T15:51:45.036164Z","shell.execute_reply.started":"2025-06-05T15:51:29.612933Z","shell.execute_reply":"2025-06-05T15:51:45.035441Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import polars as pl\nimport joblib  # or pickle\nimport os\n\njoblib.dump(gbc, 'gbc.joblib')\n#joblib.dump(model_rf, 'rf.joblib')\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:51:45.036890Z","iopub.execute_input":"2025-06-05T15:51:45.037092Z","iopub.status.idle":"2025-06-05T15:51:45.707766Z","shell.execute_reply.started":"2025-06-05T15:51:45.037077Z","shell.execute_reply":"2025-06-05T15:51:45.706974Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"joblib.dump(le, \"label_encoder.joblib\")\njoblib.dump(model_rf, 'rf.joblib')\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-05T15:51:45.708438Z","iopub.execute_input":"2025-06-05T15:51:45.708666Z","iopub.status.idle":"2025-06-05T15:51:46.291825Z","shell.execute_reply.started":"2025-06-05T15:51:45.708646Z","shell.execute_reply":"2025-06-05T15:51:46.291093Z"}},"outputs":[],"execution_count":null}]}