{"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":"nvidiaTeslaT4","dataSources":[{"sourceId":102335,"databundleVersionId":12518947,"sourceType":"competition"}],"dockerImageVersionId":31040,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\n\nimport pandas as pd\nimport polars as pl\n\nimport kaggle_evaluation.cmi_inference_server","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-06-06T12:47:30.083036Z","iopub.execute_input":"2025-06-06T12:47:30.083306Z","iopub.status.idle":"2025-06-06T12:47:31.256177Z","shell.execute_reply.started":"2025-06-06T12:47:30.083288Z","shell.execute_reply":"2025-06-06T12:47:31.255226Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"The evaluation API requires that you set up a server which will respond to inference requests. We have already defined the server; you just need write the predict function. When we evaluate your submission on the hidden test set the client defined in the gateway will run in a different container with direct access to the hidden test set and hand off the one sequence at a time.\n\nYour code will always have access to the published copies of the files.","metadata":{"execution":{"iopub.status.busy":"2025-05-29T22:29:18.955791Z","iopub.execute_input":"2025-05-29T22:29:18.956193Z","iopub.status.idle":"2025-05-29T22:29:18.965179Z","shell.execute_reply.started":"2025-05-29T22:29:18.956169Z","shell.execute_reply":"2025-05-29T22:29:18.963797Z"}}},{"cell_type":"code","source":"df = pd.read_csv(\"/kaggle/input/cmi-detect-behavior-with-sensor-data/train.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-06T13:00:20.421672Z","iopub.execute_input":"2025-06-06T13:00:20.422376Z","iopub.status.idle":"2025-06-06T13:00:39.437507Z","shell.execute_reply.started":"2025-06-06T13:00:20.422351Z","shell.execute_reply":"2025-06-06T13:00:39.436945Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"column_list = []\n\nfor items in df.columns:\n    column_list.append(items)\n    ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-06T13:00:39.438642Z","iopub.execute_input":"2025-06-06T13:00:39.438907Z","iopub.status.idle":"2025-06-06T13:00:39.442661Z","shell.execute_reply.started":"2025-06-06T13:00:39.438883Z","shell.execute_reply":"2025-06-06T13:00:39.44204Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df['behavior'].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-06T13:00:39.493819Z","iopub.execute_input":"2025-06-06T13:00:39.494013Z","iopub.status.idle":"2025-06-06T13:00:39.531331Z","shell.execute_reply.started":"2025-06-06T13:00:39.493998Z","shell.execute_reply":"2025-06-06T13:00:39.530786Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df[\"phase\"].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-06T12:58:21.022074Z","iopub.execute_input":"2025-06-06T12:58:21.022914Z","iopub.status.idle":"2025-06-06T12:58:21.050095Z","shell.execute_reply.started":"2025-06-06T12:58:21.022884Z","shell.execute_reply":"2025-06-06T12:58:21.049415Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df[\"gesture\"].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-06T12:58:58.062802Z","iopub.execute_input":"2025-06-06T12:58:58.063076Z","iopub.status.idle":"2025-06-06T12:58:58.096609Z","shell.execute_reply.started":"2025-06-06T12:58:58.063059Z","shell.execute_reply":"2025-06-06T12:58:58.096092Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-06T12:51:56.46769Z","iopub.execute_input":"2025-06-06T12:51:56.468023Z","iopub.status.idle":"2025-06-06T12:51:56.472946Z","shell.execute_reply.started":"2025-06-06T12:51:56.468002Z","shell.execute_reply":"2025-06-06T12:51:56.472281Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_new = df.drop(['row_id' , 'sequence_type', 'sequence_id' , 'sequence_counter' , 'subject'],axis=1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-06T13:00:44.951651Z","iopub.execute_input":"2025-06-06T13:00:44.952359Z","iopub.status.idle":"2025-06-06T13:00:45.414292Z","shell.execute_reply.started":"2025-06-06T13:00:44.952334Z","shell.execute_reply":"2025-06-06T13:00:45.413477Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_new.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-06T13:00:52.607381Z","iopub.execute_input":"2025-06-06T13:00:52.607667Z","iopub.status.idle":"2025-06-06T13:00:52.627129Z","shell.execute_reply.started":"2025-06-06T13:00:52.607647Z","shell.execute_reply":"2025-06-06T13:00:52.626281Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\nle = LabelEncoder()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-06T13:01:21.321721Z","iopub.execute_input":"2025-06-06T13:01:21.322436Z","iopub.status.idle":"2025-06-06T13:01:21.812633Z","shell.execute_reply.started":"2025-06-06T13:01:21.322416Z","shell.execute_reply":"2025-06-06T13:01:21.812044Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def label_encoding(col:str):\n    df_new[col] = le.fit_transform(df_new[col])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-06T13:04:32.397137Z","iopub.execute_input":"2025-06-06T13:04:32.397653Z","iopub.status.idle":"2025-06-06T13:04:32.40109Z","shell.execute_reply.started":"2025-06-06T13:04:32.39763Z","shell.execute_reply":"2025-06-06T13:04:32.400492Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for items in df_new.columns:\n    label_encoding(items)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-06T13:04:34.276585Z","iopub.execute_input":"2025-06-06T13:04:34.276884Z","iopub.status.idle":"2025-06-06T13:04:44.520254Z","shell.execute_reply.started":"2025-06-06T13:04:34.276865Z","shell.execute_reply":"2025-06-06T13:04:44.519647Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_new.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-06T13:04:47.207083Z","iopub.execute_input":"2025-06-06T13:04:47.207362Z","iopub.status.idle":"2025-06-06T13:04:47.224036Z","shell.execute_reply.started":"2025-06-06T13:04:47.20734Z","shell.execute_reply":"2025-06-06T13:04:47.223461Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"x = df.drop(['phase'],axis=1)\ny = df['phase']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-06T13:05:54.552407Z","iopub.execute_input":"2025-06-06T13:05:54.553226Z","iopub.status.idle":"2025-06-06T13:05:55.038476Z","shell.execute_reply.started":"2025-06-06T13:05:54.553201Z","shell.execute_reply":"2025-06-06T13:05:55.037648Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\nx_train , y_train , x_test , y_test = train_test_split(x , y , test_size = 0.2)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-06T13:06:14.74721Z","iopub.execute_input":"2025-06-06T13:06:14.747902Z","iopub.status.idle":"2025-06-06T13:06:16.429728Z","shell.execute_reply.started":"2025-06-06T13:06:14.74788Z","shell.execute_reply":"2025-06-06T13:06:16.42902Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.ensemble import RandomFOR","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-06T13:06:40.441582Z","iopub.execute_input":"2025-06-06T13:06:40.442134Z","iopub.status.idle":"2025-06-06T13:06:40.752486Z","shell.execute_reply.started":"2025-06-06T13:06:40.442113Z","shell.execute_reply":"2025-06-06T13:06:40.751551Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-06T12:49:02.082171Z","iopub.execute_input":"2025-06-06T12:49:02.082457Z","iopub.status.idle":"2025-06-06T12:49:02.119168Z","shell.execute_reply.started":"2025-06-06T12:49:02.082436Z","shell.execute_reply":"2025-06-06T12:49:02.118591Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def predict(sequence: pl.DataFrame, demographics: pl.DataFrame) -> str:\n    # Replace this function with your inference code.\n    # You can return either a Pandas or Polars dataframe, though Polars is recommended.\n    # Each prediction (except the very first) must be returned within 30 minutes of the batch features being provided.\n    return 'Text on phone'","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-06T12:47:31.257524Z","iopub.execute_input":"2025-06-06T12:47:31.257924Z","iopub.status.idle":"2025-06-06T12:47:31.262835Z","shell.execute_reply.started":"2025-06-06T12:47:31.257902Z","shell.execute_reply":"2025-06-06T12:47:31.261802Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"inference_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-06-06T12:47:31.263747Z","iopub.execute_input":"2025-06-06T12:47:31.264165Z","iopub.status.idle":"2025-06-06T12:47:32.743718Z","shell.execute_reply.started":"2025-06-06T12:47:31.264129Z","shell.execute_reply":"2025-06-06T12:47:32.743094Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}