{"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-02T05:26:26.946425Z","iopub.execute_input":"2025-06-02T05:26:26.946734Z","iopub.status.idle":"2025-06-02T05:26:29.141946Z","shell.execute_reply.started":"2025-06-02T05:26:26.946705Z","shell.execute_reply":"2025-06-02T05:26:29.140974Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df = pd.read_csv(\"/kaggle/input/cmi-detect-behavior-with-sensor-data/test.csv\")\ndf.head()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-02T05:29:54.917962Z","iopub.execute_input":"2025-06-02T05:29:54.918857Z","iopub.status.idle":"2025-06-02T05:29:54.976817Z","shell.execute_reply.started":"2025-06-02T05:29:54.918823Z","shell.execute_reply":"2025-06-02T05:29:54.975922Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Info about data","metadata":{}},{"cell_type":"code","source":"df.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-02T05:30:11.032441Z","iopub.execute_input":"2025-06-02T05:30:11.032757Z","iopub.status.idle":"2025-06-02T05:30:11.066597Z","shell.execute_reply.started":"2025-06-02T05:30:11.032733Z","shell.execute_reply":"2025-06-02T05:30:11.065673Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Description about data","metadata":{}},{"cell_type":"code","source":"df.describe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-02T05:30:49.152162Z","iopub.execute_input":"2025-06-02T05:30:49.152473Z","iopub.status.idle":"2025-06-02T05:30:49.639722Z","shell.execute_reply.started":"2025-06-02T05:30:49.152453Z","shell.execute_reply":"2025-06-02T05:30:49.638997Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Shape about data","metadata":{}},{"cell_type":"code","source":"df.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-02T05:31:17.026401Z","iopub.execute_input":"2025-06-02T05:31:17.026759Z","iopub.status.idle":"2025-06-02T05:31:17.032208Z","shell.execute_reply.started":"2025-06-02T05:31:17.026735Z","shell.execute_reply":"2025-06-02T05:31:17.031405Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"#  What is the average acceleration (acc_x, acc_y, acc_z) for the sequence?","metadata":{}},{"cell_type":"code","source":"import pandas as pd\n\n\n\n# Calculate average acceleration values\navg_acc = df[['acc_x', 'acc_y', 'acc_z']].mean()\nprint(\"Average Acceleration:\")\nprint(avg_acc)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-02T05:34:13.261045Z","iopub.execute_input":"2025-06-02T05:34:13.261417Z","iopub.status.idle":"2025-06-02T05:34:13.269870Z","shell.execute_reply.started":"2025-06-02T05:34:13.261383Z","shell.execute_reply":"2025-06-02T05:34:13.268865Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# How many missing values (-1.0) are there in the tof_5_* columns?","metadata":{}},{"cell_type":"code","source":"tof_cols = [col for col in df.columns if col.startswith('tof_5_')]\nmissing_counts = (df[tof_cols] == -1.0).sum()\nprint(\"Missing Values in tof_5_* columns:\")\nprint(missing_counts)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-02T05:34:45.994776Z","iopub.execute_input":"2025-06-02T05:34:45.995511Z","iopub.status.idle":"2025-06-02T05:34:46.003607Z","shell.execute_reply.started":"2025-06-02T05:34:45.995466Z","shell.execute_reply":"2025-06-02T05:34:46.002632Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Which tof_5_* column has the most missing values?","metadata":{}},{"cell_type":"code","source":"most_missing = missing_counts.idxmax()\nprint(f\"Column with most missing values: {most_missing} ({missing_counts[most_missing]})\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-02T05:35:22.828178Z","iopub.execute_input":"2025-06-02T05:35:22.828491Z","iopub.status.idle":"2025-06-02T05:35:22.833568Z","shell.execute_reply.started":"2025-06-02T05:35:22.828469Z","shell.execute_reply":"2025-06-02T05:35:22.832623Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# 4. What is the total number of unique sequences and subjects in the dataset?","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"unique_sequences = df['sequence_id'].nunique()\nunique_subjects = df['subject'].nunique()\nprint(f\"Unique sequences: {unique_sequences}\")\nprint(f\"Unique subjects: {unique_subjects}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-02T05:36:16.878896Z","iopub.execute_input":"2025-06-02T05:36:16.879206Z","iopub.status.idle":"2025-06-02T05:36:16.885524Z","shell.execute_reply.started":"2025-06-02T05:36:16.879183Z","shell.execute_reply":"2025-06-02T05:36:16.884402Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\n# Filter one sequence\nsequence_df = df[df['sequence_id'] == 'SEQ_000001']\n\n# Plot\nplt.figure(figsize=(10, 5))\nplt.plot(sequence_df['sequence_counter'], sequence_df['acc_x'], label='acc_x')\nplt.plot(sequence_df['sequence_counter'], sequence_df['acc_y'], label='acc_y')\nplt.plot(sequence_df['sequence_counter'], sequence_df['acc_z'], label='acc_z')\nplt.xlabel('Sequence Counter')\nplt.ylabel('Acceleration')\nplt.title('Acceleration over Time for SEQ_000001')\nplt.legend()\nplt.grid(True)\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-02T05:37:12.247090Z","iopub.execute_input":"2025-06-02T05:37:12.247753Z","iopub.status.idle":"2025-06-02T05:37:12.642871Z","shell.execute_reply.started":"2025-06-02T05:37:12.247729Z","shell.execute_reply":"2025-06-02T05:37:12.641760Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}