{"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":"# 必要なライブラリのインポート\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport os\nimport polars as pl","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-06-21T13:05:21.346627Z","iopub.execute_input":"2025-06-21T13:05:21.347233Z","iopub.status.idle":"2025-06-21T13:05:21.607808Z","shell.execute_reply.started":"2025-06-21T13:05:21.347204Z","shell.execute_reply":"2025-06-21T13:05:21.606960Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# def of file paths\ndata_path = \"/kaggle/input/cmi-detect-behavior-with-sensor-data/\"\n\n# load datasets\ntrain = pl.read_csv(os.path.join(data_path, \"train.csv\"))\ntest = pl.read_csv(os.path.join(data_path, \"test.csv\"))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-21T13:05:22.422921Z","iopub.execute_input":"2025-06-21T13:05:22.424015Z","iopub.status.idle":"2025-06-21T13:05:27.457020Z","shell.execute_reply.started":"2025-06-21T13:05:22.423980Z","shell.execute_reply":"2025-06-21T13:05:27.456172Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Text on phone","metadata":{}},{"cell_type":"code","source":"# センサー列の抽出\nacc_columns = [col for col in train.columns if col.startswith('acc_')]\nthm_columns = [col for col in train.columns if col.startswith('thm_')]\ntof_columns = [col for col in train.columns if col.startswith('tof_')]\n\ngesture_name = 'Text on phone'\ngesture_data = train.filter(pl.col('gesture') == gesture_name)\n\n# 特定のsequence_idを選択\nsequence_id = gesture_data['sequence_id'].unique()[0]\nsequence_data = gesture_data.filter(pl.col('sequence_id') == sequence_id).to_pandas()\n\n# 加速度データのプロット\nplt.figure(figsize=(12, 6))\nfor axis in ['acc_x', 'acc_y', 'acc_z']:\n    plt.plot(sequence_data['sequence_counter'], sequence_data[axis], label=axis)\nplt.title(f'Accelerometer Data for Gesture: {gesture_name} (Sequence ID: {sequence_id})')\nplt.xlabel('Sequence Counter')\nplt.ylabel('Acceleration (m/s^2)')\nplt.legend()\nplt.show()\n\n# 温度センサーデータのプロット\nplt.figure(figsize=(12, 6))\nfor sensor in thm_columns:\n    plt.plot(sequence_data['sequence_counter'], sequence_data[sensor], label=sensor)\nplt.title(f'Thermopile Sensor Data for Gesture: {gesture_name} (Sequence ID: {sequence_id})')\nplt.xlabel('Sequence Counter')\nplt.ylabel('Temperature (°C)')\nplt.legend()\nplt.show()\n\n# ToFセンサーデータの平均値を計算しプロット\ntof_avg = sequence_data[tof_columns].replace(-1, np.nan).mean(axis=1)\nplt.figure(figsize=(12, 6))\nplt.plot(sequence_data['sequence_counter'], tof_avg)\nplt.title(f'Average ToF Sensor Data for Gesture: {gesture_name} (Sequence ID: {sequence_id})')\nplt.xlabel('Sequence Counter')\nplt.ylabel('Average ToF Value')\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-21T13:05:27.458740Z","iopub.execute_input":"2025-06-21T13:05:27.459056Z","iopub.status.idle":"2025-06-21T13:05:28.446131Z","shell.execute_reply.started":"2025-06-21T13:05:27.459024Z","shell.execute_reply":"2025-06-21T13:05:28.445253Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Cheek - pinch skin","metadata":{}},{"cell_type":"code","source":"# センサー列の抽出\nacc_columns = [col for col in train.columns if col.startswith('acc_')]\nthm_columns = [col for col in train.columns if col.startswith('thm_')]\ntof_columns = [col for col in train.columns if col.startswith('tof_')]\n\ngesture_name = 'Cheek - pinch skin'\ngesture_data = train.filter(pl.col('gesture') == gesture_name)\n\n# 特定のsequence_idを選択\nsequence_id = gesture_data['sequence_id'].unique()[0]\nsequence_data = gesture_data.filter(pl.col('sequence_id') == sequence_id).to_pandas()\n\n# 加速度データのプロット\nplt.figure(figsize=(12, 6))\nfor axis in ['acc_x', 'acc_y', 'acc_z']:\n    plt.plot(sequence_data['sequence_counter'], sequence_data[axis], label=axis)\nplt.title(f'Accelerometer Data for Gesture: {gesture_name} (Sequence ID: {sequence_id})')\nplt.xlabel('Sequence Counter')\nplt.ylabel('Acceleration (m/s^2)')\nplt.legend()\nplt.show()\n\n# 温度センサーデータのプロット\nplt.figure(figsize=(12, 6))\nfor sensor in thm_columns:\n    plt.plot(sequence_data['sequence_counter'], sequence_data[sensor], label=sensor)\nplt.title(f'Thermopile Sensor Data for Gesture: {gesture_name} (Sequence ID: {sequence_id})')\nplt.xlabel('Sequence Counter')\nplt.ylabel('Temperature (°C)')\nplt.legend()\nplt.show()\n\n# ToFセンサーデータの平均値を計算しプロット\ntof_avg = sequence_data[tof_columns].replace(-1, np.nan).mean(axis=1)\nplt.figure(figsize=(12, 6))\nplt.plot(sequence_data['sequence_counter'], tof_avg)\nplt.title(f'Average ToF Sensor Data for Gesture: {gesture_name} (Sequence ID: {sequence_id})')\nplt.xlabel('Sequence Counter')\nplt.ylabel('Average ToF Value')\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-21T13:06:21.220871Z","iopub.execute_input":"2025-06-21T13:06:21.221326Z","iopub.status.idle":"2025-06-21T13:06:22.015043Z","shell.execute_reply.started":"2025-06-21T13:06:21.221297Z","shell.execute_reply":"2025-06-21T13:06:22.013870Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# 目的変数をtarget/non-targetに分けて、同じことを行う","metadata":{}},{"cell_type":"code","source":"# ▼ Step 1: ターゲット動作の定義\ntarget_gestures = [\n    'Above ear - pull hair',\n    'Cheek - pinch skin',\n    'Eyebrow - pull hair',\n    'Eyelash - pull hair',\n    'Forehead - pull hairline',\n    'Forehead - scratch',\n    'Neck - pinch skin',\n    'Neck - scratch'\n    ]\n\n# ▼ Step 2: ターゲット vs 非ターゲット の二値ラベルを作成\ntrain = train.with_columns(\n    pl.when(pl.col(\"gesture\").is_in(target_gestures))\n    .then(pl.lit(\"target\"))\n    .otherwise(pl.lit(\"non_target\"))\n    .alias(\"is_target\")\n)\ntrain[\"is_target\"]\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-21T13:07:37.789782Z","iopub.execute_input":"2025-06-21T13:07:37.790222Z","iopub.status.idle":"2025-06-21T13:07:37.843287Z","shell.execute_reply.started":"2025-06-21T13:07:37.790192Z","shell.execute_reply":"2025-06-21T13:07:37.842432Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ジェスチャーの分布\ngesture_counts = train.group_by('is_target').count().sort('count', descending=True).to_pandas()\nplt.figure(figsize=(12,6))\nsns.barplot(x=gesture_counts['is_target'], y=gesture_counts['count'])\nplt.title('Gesture Distribution in Training Data')\nplt.xlabel('Gesture')\nplt.ylabel('Count')\nplt.xticks(rotation=45)\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-21T13:08:08.830042Z","iopub.execute_input":"2025-06-21T13:08:08.830939Z","iopub.status.idle":"2025-06-21T13:08:09.080203Z","shell.execute_reply.started":"2025-06-21T13:08:08.830868Z","shell.execute_reply":"2025-06-21T13:08:09.079363Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Target","metadata":{}},{"cell_type":"code","source":"# センサー列の抽出\nacc_columns = [col for col in train.columns if col.startswith('acc_')]\nthm_columns = [col for col in train.columns if col.startswith('thm_')]\ntof_columns = [col for col in train.columns if col.startswith('tof_')]\n\ngesture_name = 'target'\ngesture_data = train.filter(pl.col('is_target') == gesture_name)\n\n# 特定のsequence_idを選択\nsequence_id = gesture_data['sequence_id'].unique()[0]\nsequence_data = gesture_data.filter(pl.col('sequence_id') == sequence_id).to_pandas()\n\n# 加速度データのプロット\nplt.figure(figsize=(12, 6))\nfor axis in ['acc_x', 'acc_y', 'acc_z']:\n    plt.plot(sequence_data['sequence_counter'], sequence_data[axis], label=axis)\nplt.title(f'Accelerometer Data for Gesture: {gesture_name} (Sequence ID: {sequence_id})')\nplt.xlabel('Sequence Counter')\nplt.ylabel('Acceleration (m/s^2)')\nplt.legend()\nplt.show()\n\n# 温度センサーデータのプロット\nplt.figure(figsize=(12, 6))\nfor sensor in thm_columns:\n    plt.plot(sequence_data['sequence_counter'], sequence_data[sensor], label=sensor)\nplt.title(f'Thermopile Sensor Data for Gesture: {gesture_name} (Sequence ID: {sequence_id})')\nplt.xlabel('Sequence Counter')\nplt.ylabel('Temperature (°C)')\nplt.legend()\nplt.show()\n\n# ToFセンサーデータの平均値を計算しプロット\ntof_avg = sequence_data[tof_columns].replace(-1, np.nan).mean(axis=1)\nplt.figure(figsize=(12, 6))\nplt.plot(sequence_data['sequence_counter'], tof_avg)\nplt.title(f'Average ToF Sensor Data for Gesture: {gesture_name} (Sequence ID: {sequence_id})')\nplt.xlabel('Sequence Counter')\nplt.ylabel('Average ToF Value')\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-21T13:08:57.678527Z","iopub.execute_input":"2025-06-21T13:08:57.678829Z","iopub.status.idle":"2025-06-21T13:08:58.699451Z","shell.execute_reply.started":"2025-06-21T13:08:57.678807Z","shell.execute_reply":"2025-06-21T13:08:58.698608Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Non-target","metadata":{}},{"cell_type":"code","source":"# センサー列の抽出\nacc_columns = [col for col in train.columns if col.startswith('acc_')]\nthm_columns = [col for col in train.columns if col.startswith('thm_')]\ntof_columns = [col for col in train.columns if col.startswith('tof_')]\n\ngesture_name = 'non_target'\ngesture_data = train.filter(pl.col('is_target') == gesture_name)\n\n# 特定のsequence_idを選択\nsequence_id = gesture_data['sequence_id'].unique()[0]\nsequence_data = gesture_data.filter(pl.col('sequence_id') == sequence_id).to_pandas()\n\n# 加速度データのプロット\nplt.figure(figsize=(12, 6))\nfor axis in ['acc_x', 'acc_y', 'acc_z']:\n    plt.plot(sequence_data['sequence_counter'], sequence_data[axis], label=axis)\nplt.title(f'Accelerometer Data for Gesture: {gesture_name} (Sequence ID: {sequence_id})')\nplt.xlabel('Sequence Counter')\nplt.ylabel('Acceleration (m/s^2)')\nplt.legend()\nplt.show()\n\n# 温度センサーデータのプロット\nplt.figure(figsize=(12, 6))\nfor sensor in thm_columns:\n    plt.plot(sequence_data['sequence_counter'], sequence_data[sensor], label=sensor)\nplt.title(f'Thermopile Sensor Data for Gesture: {gesture_name} (Sequence ID: {sequence_id})')\nplt.xlabel('Sequence Counter')\nplt.ylabel('Temperature (°C)')\nplt.legend()\nplt.show()\n\n# ToFセンサーデータの平均値を計算しプロット\ntof_avg = sequence_data[tof_columns].replace(-1, np.nan).mean(axis=1)\nplt.figure(figsize=(12, 6))\nplt.plot(sequence_data['sequence_counter'], tof_avg)\nplt.title(f'Average ToF Sensor Data for Gesture: {gesture_name} (Sequence ID: {sequence_id})')\nplt.xlabel('Sequence Counter')\nplt.ylabel('Average ToF Value')\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-21T13:10:18.939385Z","iopub.execute_input":"2025-06-21T13:10:18.939740Z","iopub.status.idle":"2025-06-21T13:10:19.933219Z","shell.execute_reply.started":"2025-06-21T13:10:18.939718Z","shell.execute_reply":"2025-06-21T13:10:19.932227Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# 特徴量の追加","metadata":{}},{"cell_type":"code","source":"train_filtered = train.filter(pl.col(\"sequence_counter\") < 30)\ntrain_filtered.head(1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-21T13:10:45.547841Z","iopub.execute_input":"2025-06-21T13:10:45.548200Z","iopub.status.idle":"2025-06-21T13:10:45.738877Z","shell.execute_reply.started":"2025-06-21T13:10:45.548179Z","shell.execute_reply":"2025-06-21T13:10:45.738096Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### delta_acc","metadata":{}},{"cell_type":"code","source":"train_filtered = train_filtered.with_columns([\n        # delta_acc = √(Δx² + Δy² + Δz²)\n        ((pl.col(\"acc_x\").diff().pow(2) +\n          pl.col(\"acc_y\").diff().pow(2) +\n          pl.col(\"acc_z\").diff().pow(2)).sqrt()).alias(\"delta_acc\"),\n    ])\ntrain_filtered['delta_acc'].head(3)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-21T13:11:03.952993Z","iopub.execute_input":"2025-06-21T13:11:03.953312Z","iopub.status.idle":"2025-06-21T13:11:03.987091Z","shell.execute_reply.started":"2025-06-21T13:11:03.953288Z","shell.execute_reply":"2025-06-21T13:11:03.986176Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### avm","metadata":{}},{"cell_type":"code","source":"train_filtered = train_filtered.with_columns([\n        # AVM = √(x² + y² + z²)\n        ((pl.col(\"acc_x\").pow(2) +\n          pl.col(\"acc_y\").pow(2) +\n          pl.col(\"acc_z\").pow(2)).sqrt()).alias(\"avm\")\n    ])\ntrain_filtered['avm'].head(3)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-21T13:11:19.096740Z","iopub.execute_input":"2025-06-21T13:11:19.097652Z","iopub.status.idle":"2025-06-21T13:11:19.347276Z","shell.execute_reply.started":"2025-06-21T13:11:19.097623Z","shell.execute_reply":"2025-06-21T13:11:19.346207Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### gm","metadata":{}},{"cell_type":"code","source":"# ---- 姿勢変化 GM ----\ngm_df = (\n    train_filtered.group_by(\"sequence_id\")\n    .agg([\n        pl.mean(\"acc_x\").alias(\"mean_x\"),\n        pl.mean(\"acc_y\").alias(\"mean_y\"),\n        pl.mean(\"acc_z\").alias(\"mean_z\"),\n    ])\n    .with_columns([\n        ((pl.col(\"mean_x\").pow(2) + pl.col(\"mean_y\").pow(2) + pl.col(\"mean_z\").pow(2)).sqrt()).alias(\"gm\")\n    ])\n    .select([\"sequence_id\", \"gm\"])\n)\ngm_df.head(3)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-21T13:11:34.644239Z","iopub.execute_input":"2025-06-21T13:11:34.644596Z","iopub.status.idle":"2025-06-21T13:11:34.668055Z","shell.execute_reply.started":"2025-06-21T13:11:34.644570Z","shell.execute_reply":"2025-06-21T13:11:34.667195Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### 閾値ベース特徴量","metadata":{}},{"cell_type":"code","source":"train_filtered = train_filtered.with_columns([\n        # 閾値フラグ\n        (pl.col(\"delta_acc\") > 0.2).cast(pl.Int8).alias(\"motion_gt_0.2g\"),\n        (pl.col(\"avm\") > 1.5).cast(pl.Int8).alias(\"high_intensity_flag\")\n    ])\n\n# ---- 閾値ベース特徴量集約 ----\nagg_exprs = [\n    pl.sum(\"motion_gt_0.2g\").alias(\"motion_count_gt_0.2g\"),\n    pl.sum(\"high_intensity_flag\").alias(\"high_intensity_count\"),\n    pl.mean(\"high_intensity_flag\").alias(\"high_intensity_ratio\"),\n]\n\nthresh_features = train_filtered.group_by(\"sequence_id\").agg(agg_exprs)\nthresh_features.head(1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-21T13:11:52.295675Z","iopub.execute_input":"2025-06-21T13:11:52.296059Z","iopub.status.idle":"2025-06-21T13:11:52.371993Z","shell.execute_reply.started":"2025-06-21T13:11:52.296036Z","shell.execute_reply":"2025-06-21T13:11:52.371254Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ---- 結合 ----\ntrain_filtered = train_filtered.join(gm_df, on=\"sequence_id\", how=\"left\")\ntrain_filtered = train_filtered.join(thresh_features, on= \"sequence_id\", how=\"left\")\ntrain_filtered[['motion_gt_0.2g', 'high_intensity_count', 'high_intensity_ratio']].head(3)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-21T13:11:57.785589Z","iopub.execute_input":"2025-06-21T13:11:57.785876Z","iopub.status.idle":"2025-06-21T13:11:57.833192Z","shell.execute_reply.started":"2025-06-21T13:11:57.785856Z","shell.execute_reply":"2025-06-21T13:11:57.832202Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# 追加した特徴量で可視化","metadata":{}},{"cell_type":"markdown","source":"## Text on phone","metadata":{}},{"cell_type":"code","source":"# センサー列の抽出\nacc_columns = ['delta_acc', 'avm', 'gm', 'motion_count_gt_0.2g', 'high_intensity_count', 'high_intensity_ratio']\n\ngesture_name = 'Text on phone'\nexp_train_filtered = train_filtered.to_pandas()\ngesture_data = exp_train_filtered[exp_train_filtered['gesture'] == gesture_name]\n\n# 特定のsequence_idを選択\nsequence_id = gesture_data['sequence_id'].unique()[0]\nsequence_data = gesture_data[gesture_data['sequence_id'] == sequence_id]\n\n# 加速度データのプロット\nplt.figure(figsize=(12, 6))\nfor axis in acc_columns:\n    plt.plot(sequence_data['sequence_counter'], sequence_data[axis], label=axis)\nplt.title(f'Accelerometer Data for Gesture: {gesture_name} (Sequence ID: {sequence_id})')\nplt.xlabel('Sequence Counter')\nplt.ylabel('Values')\nplt.legend()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-21T13:14:35.445962Z","iopub.execute_input":"2025-06-21T13:14:35.446283Z","iopub.status.idle":"2025-06-21T13:14:36.383693Z","shell.execute_reply.started":"2025-06-21T13:14:35.446259Z","shell.execute_reply":"2025-06-21T13:14:36.382780Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Cheek - pinch skin","metadata":{}},{"cell_type":"code","source":"# センサー列の抽出\nacc_columns = ['delta_acc', 'avm', 'gm', 'motion_count_gt_0.2g', 'high_intensity_count', 'high_intensity_ratio']\n\ngesture_name = 'Cheek - pinch skin'\nexp_train_filtered = train_filtered.to_pandas()\ngesture_data = exp_train_filtered[exp_train_filtered['gesture'] == gesture_name]\n\n# 特定のsequence_idを選択\nsequence_id = gesture_data['sequence_id'].unique()[0]\nsequence_data = gesture_data[gesture_data['sequence_id'] == sequence_id]\n\n# 加速度データのプロット\nplt.figure(figsize=(12, 6))\nfor axis in acc_columns:\n    plt.plot(sequence_data['sequence_counter'], sequence_data[axis], label=axis)\nplt.title(f'Accelerometer Data for Gesture: {gesture_name} (Sequence ID: {sequence_id})')\nplt.xlabel('Sequence Counter')\nplt.ylabel('Values')\nplt.legend()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-21T13:16:04.772305Z","iopub.execute_input":"2025-06-21T13:16:04.772684Z","iopub.status.idle":"2025-06-21T13:16:05.679055Z","shell.execute_reply.started":"2025-06-21T13:16:04.772660Z","shell.execute_reply":"2025-06-21T13:16:05.678205Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## ターゲットと非ターゲットで可視化","metadata":{}},{"cell_type":"code","source":"# ▼ Step 1: ターゲット動作の定義\ntarget_gestures = [\n    'Above ear - pull hair',\n    'Cheek - pinch skin',\n    'Eyebrow - pull hair',\n    'Eyelash - pull hair',\n    'Forehead - pull hairline',\n    'Forehead - scratch',\n    'Neck - pinch skin',\n    'Neck - scratch'\n    ]\n\n# ▼ Step 2: ターゲット vs 非ターゲット の二値ラベルを作成\ntrain_filtered = train_filtered.with_columns(\n    pl.when(pl.col(\"gesture\").is_in(target_gestures))\n    .then(pl.lit(\"target\"))\n    .otherwise(pl.lit(\"non_target\"))\n    .alias(\"is_target\")\n)\ntrain_filtered[\"is_target\"]\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-21T13:15:29.969939Z","iopub.execute_input":"2025-06-21T13:15:29.970288Z","iopub.status.idle":"2025-06-21T13:15:29.993961Z","shell.execute_reply.started":"2025-06-21T13:15:29.970264Z","shell.execute_reply":"2025-06-21T13:15:29.992754Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### target","metadata":{}},{"cell_type":"code","source":"# センサー列の抽出\nacc_columns = ['delta_acc', 'avm', 'gm', 'motion_count_gt_0.2g', 'high_intensity_count', 'high_intensity_ratio']\n\ngesture_name = 'target'\nexp_train_filtered = train_filtered.to_pandas()\ngesture_data = exp_train_filtered[exp_train_filtered['is_target'] == gesture_name]\n\n# 特定のsequence_idを選択\nsequence_id = gesture_data['sequence_id'].unique()[0]\nsequence_data = gesture_data[gesture_data['sequence_id'] == sequence_id]\n\n# 加速度データのプロット\nplt.figure(figsize=(12, 6))\nfor axis in acc_columns:\n    plt.plot(sequence_data['sequence_counter'], sequence_data[axis], label=axis)\nplt.title(f'Accelerometer Data for Gesture: {gesture_name} (Sequence ID: {sequence_id})')\nplt.xlabel('Sequence Counter')\nplt.ylabel('Values')\nplt.legend()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-21T13:16:14.051085Z","iopub.execute_input":"2025-06-21T13:16:14.051395Z","iopub.status.idle":"2025-06-21T13:16:15.039933Z","shell.execute_reply.started":"2025-06-21T13:16:14.051374Z","shell.execute_reply":"2025-06-21T13:16:15.039089Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# センサー列の抽出\nacc_columns = ['delta_acc', 'avm', 'gm', 'motion_count_gt_0.2g', 'high_intensity_count', 'high_intensity_ratio']\n\ngesture_name = 'target'\nexp_train_filtered = train_filtered.to_pandas()\nsequence_data = exp_train_filtered[exp_train_filtered['is_target'] == gesture_name]\n\n# 加速度データのプロット\nplt.figure(figsize=(12, 6))\nfor axis in acc_columns:\n    plt.plot(sequence_data['sequence_counter'], sequence_data[axis], label=axis)\nplt.title(f'Accelerometer Data for Gesture: {gesture_name} (Sequence ID: {sequence_id})')\nplt.xlabel('Sequence Counter')\nplt.ylabel('values')\nplt.legend()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-21T13:16:29.833524Z","iopub.execute_input":"2025-06-21T13:16:29.833847Z","iopub.status.idle":"2025-06-21T13:16:41.710312Z","shell.execute_reply.started":"2025-06-21T13:16:29.833821Z","shell.execute_reply":"2025-06-21T13:16:41.709279Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### non_target","metadata":{}},{"cell_type":"code","source":"# センサー列の抽出\nacc_columns = ['delta_acc', 'avm', 'gm', 'motion_count_gt_0.2g', 'high_intensity_count', 'high_intensity_ratio']\n\ngesture_name = 'non_target'\nexp_train_filtered = train_filtered.to_pandas()\ngesture_data = exp_train_filtered[exp_train_filtered['is_target'] == gesture_name]\n\n# 特定のsequence_idを選択\nsequence_id = gesture_data['sequence_id'].unique()[0]\nsequence_data = gesture_data[gesture_data['sequence_id'] == sequence_id]\n\n# 加速度データのプロット\nplt.figure(figsize=(12, 6))\nfor axis in acc_columns:\n    plt.plot(sequence_data['sequence_counter'], sequence_data[axis], label=axis)\nplt.title(f'Accelerometer Data for Gesture: {gesture_name} (Sequence ID: {sequence_id})')\nplt.xlabel('Sequence Counter')\nplt.ylabel('Acceleration (m/s^2)')\nplt.legend()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-21T13:17:01.941378Z","iopub.execute_input":"2025-06-21T13:17:01.941682Z","iopub.status.idle":"2025-06-21T13:17:03.346941Z","shell.execute_reply.started":"2025-06-21T13:17:01.941660Z","shell.execute_reply":"2025-06-21T13:17:03.345954Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# センサー列の抽出\nacc_columns = ['delta_acc', 'avm', 'gm', 'motion_count_gt_0.2g', 'high_intensity_count', 'high_intensity_ratio']\n\ngesture_name = 'non_target'\nexp_train_filtered = train_filtered.to_pandas()\nsequence_data = exp_train_filtered[exp_train_filtered['is_target'] == gesture_name]\n\n# 加速度データのプロット\nplt.figure(figsize=(12, 6))\nfor axis in acc_columns:\n    plt.plot(sequence_data['sequence_counter'], sequence_data[axis], label=axis)\nplt.title(f'Accelerometer Data for Gesture: {gesture_name} (Sequence ID: {sequence_id})')\nplt.xlabel('Sequence Counter')\nplt.ylabel('Acceleration (m/s^2)')\nplt.legend()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-21T13:17:11.784181Z","iopub.execute_input":"2025-06-21T13:17:11.784839Z","iopub.status.idle":"2025-06-21T13:17:18.166098Z","shell.execute_reply.started":"2025-06-21T13:17:11.784813Z","shell.execute_reply":"2025-06-21T13:17:18.165216Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}