{"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":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-06-11T04:45:09.559375Z","iopub.execute_input":"2025-06-11T04:45:09.560475Z","iopub.status.idle":"2025-06-11T04:45:09.565706Z","shell.execute_reply.started":"2025-06-11T04:45:09.560408Z","shell.execute_reply":"2025-06-11T04:45:09.564552Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# loading data\ntrain_df = pd.read_csv('/kaggle/input/cmi-detect-behavior-with-sensor-data/train.csv')\ntrain_demo_df = pd.read_csv('/kaggle/input/cmi-detect-behavior-with-sensor-data/train_demographics.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-11T04:45:10.085420Z","iopub.execute_input":"2025-06-11T04:45:10.085801Z","iopub.status.idle":"2025-06-11T04:45:37.721080Z","shell.execute_reply.started":"2025-06-11T04:45:10.085774Z","shell.execute_reply":"2025-06-11T04:45:37.720121Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Displaying data\ntrain_df.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-11T04:45:37.722531Z","iopub.execute_input":"2025-06-11T04:45:37.722856Z","iopub.status.idle":"2025-06-11T04:45:37.729242Z","shell.execute_reply.started":"2025-06-11T04:45:37.722822Z","shell.execute_reply":"2025-06-11T04:45:37.728245Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.sequence_type.value_counts(normalize=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-11T04:45:37.730111Z","iopub.execute_input":"2025-06-11T04:45:37.730393Z","iopub.status.idle":"2025-06-11T04:45:37.795459Z","shell.execute_reply.started":"2025-06-11T04:45:37.730368Z","shell.execute_reply":"2025-06-11T04:45:37.794325Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.head(100)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-11T04:48:32.384850Z","iopub.execute_input":"2025-06-11T04:48:32.385203Z","iopub.status.idle":"2025-06-11T04:48:32.417117Z","shell.execute_reply.started":"2025-06-11T04:48:32.385178Z","shell.execute_reply":"2025-06-11T04:48:32.415991Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.behavior.value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-11T04:45:37.837125Z","iopub.execute_input":"2025-06-11T04:45:37.837589Z","iopub.status.idle":"2025-06-11T04:45:37.902089Z","shell.execute_reply.started":"2025-06-11T04:45:37.837550Z","shell.execute_reply":"2025-06-11T04:45:37.901032Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.columns[:50]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-11T04:45:37.903165Z","iopub.execute_input":"2025-06-11T04:45:37.903626Z","iopub.status.idle":"2025-06-11T04:45:37.925904Z","shell.execute_reply.started":"2025-06-11T04:45:37.903598Z","shell.execute_reply":"2025-06-11T04:45:37.924672Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df[['acc_x', 'acc_y','acc_z', 'rot_w', 'rot_x', 'rot_y']].head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-11T04:45:37.927338Z","iopub.execute_input":"2025-06-11T04:45:37.927595Z","iopub.status.idle":"2025-06-11T04:45:37.961217Z","shell.execute_reply.started":"2025-06-11T04:45:37.927575Z","shell.execute_reply":"2025-06-11T04:45:37.960160Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.orientation.unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-11T05:01:33.588671Z","iopub.execute_input":"2025-06-11T05:01:33.588995Z","iopub.status.idle":"2025-06-11T05:01:33.639548Z","shell.execute_reply.started":"2025-06-11T05:01:33.588970Z","shell.execute_reply":"2025-06-11T05:01:33.638536Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.gesture.unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-11T05:02:17.405515Z","iopub.execute_input":"2025-06-11T05:02:17.405983Z","iopub.status.idle":"2025-06-11T05:02:17.451764Z","shell.execute_reply.started":"2025-06-11T05:02:17.405948Z","shell.execute_reply":"2025-06-11T05:02:17.449518Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.loc[train_df.sequence_id == 'SEQ_000007',:].head(1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-11T05:00:12.250275Z","iopub.execute_input":"2025-06-11T05:00:12.250622Z","iopub.status.idle":"2025-06-11T05:00:12.332113Z","shell.execute_reply.started":"2025-06-11T05:00:12.250595Z","shell.execute_reply":"2025-06-11T05:00:12.330871Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.loc[(train_df.gesture == 'Cheek - pinch skin') & (train_df.orientation=='Seated Lean Non Dom - FACE DOWN'), 'sequence_id'].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-11T05:02:27.148674Z","iopub.execute_input":"2025-06-11T05:02:27.149012Z","iopub.status.idle":"2025-06-11T05:02:27.246915Z","shell.execute_reply.started":"2025-06-11T05:02:27.148986Z","shell.execute_reply":"2025-06-11T05:02:27.245452Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Choosing couple of gestures\ncheek_pinch_gest_exmp_1 = (\n    train_df\n    .loc[\n    (train_df.sequence_id == 'SEQ_000007') & \n    (train_df.phase=='Gesture'),\n    ['rot_w', 'rot_x', 'rot_y', 'thm_1', 'thm_2', 'thm_3','thm_4', 'thm_5']]\n)\ncheek_pinch_gest_exmp_1['avg_temp'] = cheek_pinch_gest_exmp_1[['thm_1', 'thm_2', 'thm_3','thm_4', 'thm_5']].median(axis=1)\n\ncheek_pinch_gest_exmp_2 = (\n    train_df\n    .loc[\n    (train_df.sequence_id == 'SEQ_010026') & \n    (train_df.phase=='Gesture'),\n    ['rot_w', 'rot_x', 'rot_y', 'thm_1', 'thm_2', 'thm_3','thm_4', 'thm_5']]\n)\ncheek_pinch_gest_exmp_2['avg_temp'] = cheek_pinch_gest_exmp_2[['thm_1', 'thm_2', 'thm_3','thm_4', 'thm_5']].median(axis=1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-11T05:05:29.914073Z","iopub.execute_input":"2025-06-11T05:05:29.914477Z","iopub.status.idle":"2025-06-11T05:05:30.131790Z","shell.execute_reply.started":"2025-06-11T05:05:29.914451Z","shell.execute_reply":"2025-06-11T05:05:30.130594Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"cheek_pinch_gest_exmp = pd.concat([cheek_pinch_gest_exmp_1, cheek_pinch_gest_exmp_2])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-11T05:05:37.626841Z","iopub.execute_input":"2025-06-11T05:05:37.627193Z","iopub.status.idle":"2025-06-11T05:05:37.634076Z","shell.execute_reply.started":"2025-06-11T05:05:37.627168Z","shell.execute_reply":"2025-06-11T05:05:37.632906Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"cheek_pinch_gest_exmp.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-11T05:05:37.636212Z","iopub.execute_input":"2025-06-11T05:05:37.636577Z","iopub.status.idle":"2025-06-11T05:05:37.669845Z","shell.execute_reply.started":"2025-06-11T05:05:37.636549Z","shell.execute_reply":"2025-06-11T05:05:37.668377Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# plotting\nfrom matplotlib import cm\nfrom mpl_toolkits.mplot3d.art3d import Line3DCollection\n\nx = cheek_pinch_gest_exmp_1['rot_x'].values\ny = cheek_pinch_gest_exmp_1['rot_y'].values\nw = cheek_pinch_gest_exmp_1['rot_w'].values\nt = cheek_pinch_gest_exmp_1['avg_temp'].values\n\npoints = np.array([x, y, w]).T.reshape(-1, 1, 3)\nsegments = np.concatenate([points[:-1], points[1:]], axis=1)\n\nnorm = plt.Normalize(t.min(), t.max())\ncolors = cm.plasma(norm(t))\n\nlc = Line3DCollection(segments, cmap='plasma', norm=norm)\nlc.set_array(t)\nlc.set_linewidth(2)\n\n# Crear figura 3D\nfig = plt.figure(figsize=(10, 7))\nax = fig.add_subplot(111, projection='3d')\nax.add_collection3d(lc)\n\n# Ajustar límites\nax.set_xlim(x.min(), x.max())\nax.set_ylim(y.min(), y.max())\nax.set_zlim(w.min(), w.max())\n\n# Etiquetas\nax.set_xlabel('X')\nax.set_ylabel('Y')\nax.set_zlabel('Z')\nfig.colorbar(lc, ax=ax, label='Temperature')\n\nplt.title(\"3D trajectory colored by temperature\")\nplt.tight_layout()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-11T05:05:37.671056Z","iopub.execute_input":"2025-06-11T05:05:37.671377Z","iopub.status.idle":"2025-06-11T05:05:37.964488Z","shell.execute_reply.started":"2025-06-11T05:05:37.671343Z","shell.execute_reply":"2025-06-11T05:05:37.963428Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# plotting\nfrom matplotlib import cm\nfrom mpl_toolkits.mplot3d.art3d import Line3DCollection\n\nx = cheek_pinch_gest_exmp_2['rot_x'].values\ny = cheek_pinch_gest_exmp_2['rot_y'].values\nw = cheek_pinch_gest_exmp_2['rot_w'].values\nt = cheek_pinch_gest_exmp_2['avg_temp'].values\n\npoints = np.array([x, y, w]).T.reshape(-1, 1, 3)\nsegments = np.concatenate([points[:-1], points[1:]], axis=1)\n\nnorm = plt.Normalize(t.min(), t.max())\ncolors = cm.plasma(norm(t))\n\nlc = Line3DCollection(segments, cmap='plasma', norm=norm)\nlc.set_array(t)\nlc.set_linewidth(2)\n\n# Crear figura 3D\nfig = plt.figure(figsize=(10, 7))\nax = fig.add_subplot(111, projection='3d')\nax.add_collection3d(lc)\n\n# Ajustar límites\nax.set_xlim(x.min(), x.max())\nax.set_ylim(y.min(), y.max())\nax.set_zlim(w.min(), w.max())\n\n# Etiquetas\nax.set_xlabel('X')\nax.set_ylabel('Y')\nax.set_zlabel('Z')\nfig.colorbar(lc, ax=ax, label='Temperature')\n\nplt.title(\"3D trajectory colored by temperature\")\nplt.tight_layout()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-11T05:05:37.965691Z","iopub.execute_input":"2025-06-11T05:05:37.965989Z","iopub.status.idle":"2025-06-11T05:05:38.281565Z","shell.execute_reply.started":"2025-06-11T05:05:37.965966Z","shell.execute_reply":"2025-06-11T05:05:38.280529Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}