{"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":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-07-27T13:27:20.992458Z","iopub.execute_input":"2025-07-27T13:27:20.993155Z","iopub.status.idle":"2025-07-27T13:27:23.537178Z","shell.execute_reply.started":"2025-07-27T13:27:20.993120Z","shell.execute_reply":"2025-07-27T13:27:23.536119Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#upload the file, it's csv file (means it's saved in excel file as extension csv\nMentalHealth_test = pd.read_csv(\"/kaggle/input/cmi-detect-behavior-with-sensor-data/test.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-27T09:32:46.476573Z","iopub.execute_input":"2025-07-27T09:32:46.477496Z","iopub.status.idle":"2025-07-27T09:32:46.515165Z","shell.execute_reply.started":"2025-07-27T09:32:46.477453Z","shell.execute_reply":"2025-07-27T09:32:46.514176Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"MentalHealth_TestDemograp= pd.read_csv(\"/kaggle/input/cmi-detect-behavior-with-sensor-data/test_demographics.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-27T09:32:55.443582Z","iopub.execute_input":"2025-07-27T09:32:55.443989Z","iopub.status.idle":"2025-07-27T09:32:55.451322Z","shell.execute_reply.started":"2025-07-27T09:32:55.443937Z","shell.execute_reply":"2025-07-27T09:32:55.450478Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"MentalHealth_test.dtypes","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-27T09:34:40.791094Z","iopub.execute_input":"2025-07-27T09:34:40.791378Z","iopub.status.idle":"2025-07-27T09:34:40.812461Z","shell.execute_reply.started":"2025-07-27T09:34:40.791350Z","shell.execute_reply":"2025-07-27T09:34:40.811455Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"MentalHealth_test.isna().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-27T09:34:45.463596Z","iopub.execute_input":"2025-07-27T09:34:45.464425Z","iopub.status.idle":"2025-07-27T09:34:45.474035Z","shell.execute_reply.started":"2025-07-27T09:34:45.464396Z","shell.execute_reply":"2025-07-27T09:34:45.472904Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"MentalHealth_TestDemograp.isna().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-27T09:34:49.521216Z","iopub.execute_input":"2025-07-27T09:34:49.521519Z","iopub.status.idle":"2025-07-27T09:34:49.529104Z","shell.execute_reply.started":"2025-07-27T09:34:49.521493Z","shell.execute_reply":"2025-07-27T09:34:49.527902Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"MentalHealth_TestDemograp.dtypes","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-27T09:34:54.538251Z","iopub.execute_input":"2025-07-27T09:34:54.538569Z","iopub.status.idle":"2025-07-27T09:34:54.545960Z","shell.execute_reply.started":"2025-07-27T09:34:54.538543Z","shell.execute_reply":"2025-07-27T09:34:54.544847Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"MentalHealth_TestDemograp.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-27T09:37:00.305998Z","iopub.execute_input":"2025-07-27T09:37:00.306583Z","iopub.status.idle":"2025-07-27T09:37:00.317218Z","shell.execute_reply.started":"2025-07-27T09:37:00.306559Z","shell.execute_reply":"2025-07-27T09:37:00.316335Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"I am working with a multi-sensor time-series dataset collected from a wrist-worn device to detect Body-Focused Repetitive Behavior (BFRB) using:\n\nInertial data (IMU) – acc_*, rot_*\n\nThermal data (Thermopile) – thm_*\n\nDistance data (Time-of-Flight) – tof_*\n\nThe other dataset has these attributes: age, sex, handedness, etc., and a target goal: to classify time-series sequences as BFRB-like or non-BFRB-like.\n\nLet’s build a baseline pipeline with preprocessing, feature extraction, model training, and prediction using Python.","metadata":{}},{"cell_type":"markdown","source":"# First Merge the both dataset ","metadata":{}},{"cell_type":"code","source":"# Subject is the column name which exits on both dataset which is the primary key in \n# the mental health test deompgraph and subject coloumn is unique identifier\n\n# the how is the used as a join so used as a \"left join\"\n\nMentalHealth_test = MentalHealth_test.merge(MentalHealth_TestDemograp, on =\"subject\", how = \"left\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-27T10:25:01.654798Z","iopub.execute_input":"2025-07-27T10:25:01.655220Z","iopub.status.idle":"2025-07-27T10:25:01.666031Z","shell.execute_reply.started":"2025-07-27T10:25:01.655191Z","shell.execute_reply":"2025-07-27T10:25:01.664934Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Removing the missing values, First check the missing values because we merge the both dataset\n# There are chances to having a missing values  ","metadata":{}},{"cell_type":"code","source":"MentalHealth_test.isna().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-27T11:35:30.764031Z","iopub.execute_input":"2025-07-27T11:35:30.764939Z","iopub.status.idle":"2025-07-27T11:35:30.777227Z","shell.execute_reply.started":"2025-07-27T11:35:30.764905Z","shell.execute_reply":"2025-07-27T11:35:30.776314Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# MISSING VALUES METHODS \n\nmany columns are not showing so there is possiblity have a missing values. There are different ways to fill the missing values either through statistical like imputation (mean, media, mode or group)\n\nML: K-Neareast Negibour, MICE (Multivariate Imputation by Chained Equation {I didn't use this one}),\nRegression Imputation (Linear Regression),\n\nDL: Like Tensorflow, PyTorch, FancyImpute and Datawig (Didn't use these two before)\n\nThis dataset is A time series dataset. All observations collected over time, usually at regular intervals (e.g., hourly, daily, monthly).\n\nTO FILL THE MISSING VALUES IN THE TIMESERIES ARE FORWARD OR BACKWARD FILL\n\n1.  FWD FILL: df['col name'].fillna(method = \"ffill\" inplace = \"True\")\n2.  Bckward Fill: df['col name'].fillna(method =\"bfill\" inplace = \"True\")\n3.  Interpolation: df['col name'].interpolate(method = \"linear\" inplace = \"True\")\n4.  Mean/Median Imputation: df['col name'].fillna(df['col name'].mean().inplace = \"True\")\n5.  Placeholder like -1: df['col name'].fillna(-1, inplace = \"True\")\n\nusing a -1 placeholder to fill the missing values, I am not confident to use this because you have to make sure that it won't affect the analysis because it creates the artifical or fake anomoloies & it can create the misleading result\n","metadata":{}},{"cell_type":"code","source":"#  I USE THE FORWARD FILL IN THIS TIME SERIES DATASET \n\nMentalHealth_test.fillna(method=\"ffill\", inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-27T11:40:22.755338Z","iopub.execute_input":"2025-07-27T11:40:22.755705Z","iopub.status.idle":"2025-07-27T11:40:22.768281Z","shell.execute_reply.started":"2025-07-27T11:40:22.755680Z","shell.execute_reply":"2025-07-27T11:40:22.766863Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}