{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","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":[{"sourceId":102335,"databundleVersionId":12518947,"sourceType":"competition"}],"dockerImageVersionId":31089,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nimport polars as pl\nimport pandas as pd\nimport kaggle_evaluation.cmi_inference_server","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-07-19T05:24:30.657344Z","iopub.execute_input":"2025-07-19T05:24:30.661675Z","iopub.status.idle":"2025-07-19T05:24:31.770975Z","shell.execute_reply.started":"2025-07-19T05:24:30.661567Z","shell.execute_reply":"2025-07-19T05:24:31.769632Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Load and Explore the Training Data (Polars)","metadata":{}},{"cell_type":"code","source":"# Step 1: Load the training data from a CSV file\ntrain = pl.read_csv('/kaggle/input/cmi-detect-behavior-with-sensor-data/train.csv')\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-19T05:24:31.772948Z","iopub.execute_input":"2025-07-19T05:24:31.773514Z","iopub.status.idle":"2025-07-19T05:24:40.554734Z","shell.execute_reply.started":"2025-07-19T05:24:31.773470Z","shell.execute_reply":"2025-07-19T05:24:40.553667Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Step 2: Show the first few rows so we can see what the data looks like\nprint(\"Here's what our training data looks like:\")\nprint(train.head())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-19T05:24:40.556060Z","iopub.execute_input":"2025-07-19T05:24:40.556665Z","iopub.status.idle":"2025-07-19T05:24:40.568621Z","shell.execute_reply.started":"2025-07-19T05:24:40.556629Z","shell.execute_reply":"2025-07-19T05:24:40.566769Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Step 3: Let's see all the different gestures (actions) in our data\nprint(\"\\nAll unique gestures in the training data:\")\nprint(train['gesture'].unique())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-19T05:24:40.571263Z","iopub.execute_input":"2025-07-19T05:24:40.571619Z","iopub.status.idle":"2025-07-19T05:24:40.615766Z","shell.execute_reply.started":"2025-07-19T05:24:40.571585Z","shell.execute_reply":"2025-07-19T05:24:40.614389Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Step 4: Count how many times each gesture appears in the data\ngesture_counts = train['gesture'].value_counts()\nprint(\"\\nHow many times each gesture appears:\")\nprint(gesture_counts)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-19T05:24:40.616692Z","iopub.execute_input":"2025-07-19T05:24:40.616992Z","iopub.status.idle":"2025-07-19T05:24:40.747813Z","shell.execute_reply.started":"2025-07-19T05:24:40.616967Z","shell.execute_reply":"2025-07-19T05:24:40.746507Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Step 5: Find out which gesture happens the most in the training data\n# Count gestures and sort\ngesture_counts = train['gesture'].value_counts().sort('count', descending=True)\n\n# Show the value_counts result for clarity\nprint(gesture_counts)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-19T05:24:40.749298Z","iopub.execute_input":"2025-07-19T05:24:40.749703Z","iopub.status.idle":"2025-07-19T05:24:40.846021Z","shell.execute_reply.started":"2025-07-19T05:24:40.749678Z","shell.execute_reply":"2025-07-19T05:24:40.844721Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Take the gesture with the highest count (the first row)\nmost_common_gesture = gesture_counts.row(0)[0]  # [0] is the gesture, [1] is the count\nprint(\"\\nThe most common gesture is:\", most_common_gesture)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-19T05:24:40.846867Z","iopub.execute_input":"2025-07-19T05:24:40.847218Z","iopub.status.idle":"2025-07-19T05:24:40.853669Z","shell.execute_reply.started":"2025-07-19T05:24:40.847186Z","shell.execute_reply":"2025-07-19T05:24:40.852563Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Build the Easiest Possible Model (Baseline Prediction)","metadata":{}},{"cell_type":"code","source":"def predict(sequence: pl.DataFrame, demographics: pl.DataFrame) -> str:\n    # No matter what the input data is, always return the most common gesture\n    return most_common_gesture","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-19T05:24:40.855357Z","iopub.execute_input":"2025-07-19T05:24:40.855942Z","iopub.status.idle":"2025-07-19T05:24:40.877982Z","shell.execute_reply.started":"2025-07-19T05:24:40.855903Z","shell.execute_reply":"2025-07-19T05:24:40.876899Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Set Up the Official Grading System","metadata":{}},{"cell_type":"code","source":"# We give our simple prediction function to the competition's grading system\ninference_server = kaggle_evaluation.cmi_inference_server.CMIInferenceServer(predict)\n\nif os.getenv('KAGGLE_IS_COMPETITION_RERUN'):\n    inference_server.serve()\nelse:\n    inference_server.run_local_gateway(\n        data_paths=(\n            '/kaggle/input/cmi-detect-behavior-with-sensor-data/test.csv',\n            '/kaggle/input/cmi-detect-behavior-with-sensor-data/test_demographics.csv',\n        )\n    )","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-19T05:24:40.879204Z","iopub.execute_input":"2025-07-19T05:24:40.879522Z","iopub.status.idle":"2025-07-19T05:24:42.080716Z","shell.execute_reply.started":"2025-07-19T05:24:40.879500Z","shell.execute_reply":"2025-07-19T05:24:42.079020Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"","metadata":{}}]}