{"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-04T17:00:16.229715Z","iopub.execute_input":"2025-06-04T17:00:16.230022Z","iopub.status.idle":"2025-06-04T17:00:18.785543Z","shell.execute_reply.started":"2025-06-04T17:00:16.23Z","shell.execute_reply":"2025-06-04T17:00:18.784613Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# load data_train\n\ndf_train = pd.read_csv('/kaggle/input/cmi-detect-behavior-with-sensor-data/train.csv')\ndf_train","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-04T17:20:02.967286Z","iopub.execute_input":"2025-06-04T17:20:02.968426Z","iopub.status.idle":"2025-06-04T17:20:24.755374Z","shell.execute_reply.started":"2025-06-04T17:20:02.968399Z","shell.execute_reply":"2025-06-04T17:20:24.754307Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Mengetahui tentang banyaknya data_train\ndf_train.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-04T17:13:37.282015Z","iopub.execute_input":"2025-06-04T17:13:37.28263Z","iopub.status.idle":"2025-06-04T17:13:37.288149Z","shell.execute_reply.started":"2025-06-04T17:13:37.282603Z","shell.execute_reply":"2025-06-04T17:13:37.287416Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Informasi mengenai type data dan missing value pada data_train\ndf_train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-04T17:14:26.916114Z","iopub.execute_input":"2025-06-04T17:14:26.916489Z","iopub.status.idle":"2025-06-04T17:14:26.970298Z","shell.execute_reply.started":"2025-06-04T17:14:26.916466Z","shell.execute_reply":"2025-06-04T17:14:26.969316Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Mengetahui nilai statistik deskriptif pada data_train\ndf_train.describe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-04T17:15:40.575273Z","iopub.execute_input":"2025-06-04T17:15:40.576335Z","iopub.status.idle":"2025-06-04T17:15:48.996645Z","shell.execute_reply.started":"2025-06-04T17:15:40.576208Z","shell.execute_reply":"2025-06-04T17:15:48.99568Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Mengecek apakah ada missing value atau tidak \ndf_train.isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-04T17:17:06.383295Z","iopub.execute_input":"2025-06-04T17:17:06.384367Z","iopub.status.idle":"2025-06-04T17:17:07.115369Z","shell.execute_reply.started":"2025-06-04T17:17:06.384337Z","shell.execute_reply":"2025-06-04T17:17:07.114446Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Mengetahui presentase missing value\nmissing_percent = (df_train.isnull().sum() / len(df_train)) * 100\nmissing_percent[missing_percent > 0].sort_values(ascending=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-04T17:37:24.345754Z","iopub.execute_input":"2025-06-04T17:37:24.346078Z","iopub.status.idle":"2025-06-04T17:37:25.09425Z","shell.execute_reply.started":"2025-06-04T17:37:24.346052Z","shell.execute_reply":"2025-06-04T17:37:25.093471Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Sebagian besar kolom memiliki missing value di bawah 6%, sehingga masih dapat ditoleransi.\n# Oleh karena itu, kita memilih untuk mengisi nilai yang hilang dengan median dari setiap kolom,\n# agar data tetap utuh dan model dapat dilatih tanpa error.\n\n# Isi semua missing value dengan median masing-masing kolom\ndf_train_filled = df_train.fillna(df_train.median(numeric_only=True))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-04T17:41:59.576619Z","iopub.execute_input":"2025-06-04T17:41:59.577732Z","iopub.status.idle":"2025-06-04T17:42:03.4256Z","shell.execute_reply.started":"2025-06-04T17:41:59.577692Z","shell.execute_reply":"2025-06-04T17:42:03.424541Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_train_filled.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-04T17:43:50.389487Z","iopub.execute_input":"2025-06-04T17:43:50.390387Z","iopub.status.idle":"2025-06-04T17:43:50.418096Z","shell.execute_reply.started":"2025-06-04T17:43:50.390352Z","shell.execute_reply":"2025-06-04T17:43:50.417198Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Mengecek apakah masih ada missing value atau tidak \ndf_train_filled.isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-04T17:42:42.914323Z","iopub.execute_input":"2025-06-04T17:42:42.915015Z","iopub.status.idle":"2025-06-04T17:42:43.741391Z","shell.execute_reply.started":"2025-06-04T17:42:42.914989Z","shell.execute_reply":"2025-06-04T17:42:43.740498Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Mengecek apakah ada data duplicate atau tidak\ndf_train_filled.duplicated().sum()  ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-04T17:48:58.999782Z","iopub.execute_input":"2025-06-04T17:48:59.001034Z","iopub.status.idle":"2025-06-04T17:49:05.058668Z","shell.execute_reply.started":"2025-06-04T17:48:59.000999Z","shell.execute_reply":"2025-06-04T17:49:05.057662Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"Dimensi Data ini adalah \", df_train_filled.shape)\nprint(\"\\nInfo Data : \")\ndf_train_filled.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-04T17:53:34.368313Z","iopub.execute_input":"2025-06-04T17:53:34.368659Z","iopub.status.idle":"2025-06-04T17:53:34.38273Z","shell.execute_reply.started":"2025-06-04T17:53:34.368637Z","shell.execute_reply":"2025-06-04T17:53:34.381783Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns\n\nsample_cols = df_train_filled.select_dtypes(include='number').columns[:4]\n\nplt.figure(figsize=(12, 8))\nfor i, col in enumerate(sample_cols):\n    plt.subplot(2, 2, i+1)\n    sns.histplot(df_train_filled[col], kde=True)\n    plt.title(f'Distribusi {col}')\nplt.tight_layout()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-04T17:54:41.943687Z","iopub.execute_input":"2025-06-04T17:54:41.944142Z","iopub.status.idle":"2025-06-04T17:54:58.570561Z","shell.execute_reply.started":"2025-06-04T17:54:41.944113Z","shell.execute_reply":"2025-06-04T17:54:58.569499Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# korelasi antar fitur\nplt.figure(figsize=(12, 10))\nsns.heatmap(df_train_filled[sample_cols].corr(), cmap='coolwarm', annot=False)\nplt.title('Korelasi antar fitur (20 fitur pertama)')\nplt.show()\n\nplt.figure(figsize=(6,4))\nsns.heatmap(df.corr(numeric_only=True), annot=True, cmap='coolwarm')\nplt.title('Correlation Matrix')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-04T17:55:40.548357Z","iopub.execute_input":"2025-06-04T17:55:40.549551Z","iopub.status.idle":"2025-06-04T17:55:40.859384Z","shell.execute_reply.started":"2025-06-04T17:55:40.549517Z","shell.execute_reply":"2025-06-04T17:55:40.858386Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(df_train_filled.columns)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pip install ydata-profiling","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-04T17:02:23.197647Z","iopub.execute_input":"2025-06-04T17:02:23.198283Z","iopub.status.idle":"2025-06-04T17:02:28.847645Z","shell.execute_reply.started":"2025-06-04T17:02:23.198253Z","shell.execute_reply":"2025-06-04T17:02:28.846454Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from ydata_profiling import ProfileReport\n\nprofile = ProfileReport(df_train, title=\"EDA Report\", explorative=True)\nprofile.to_notebook_iframe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-04T17:29:09.851322Z","iopub.execute_input":"2025-06-04T17:29:09.851668Z","iopub.status.idle":"2025-06-04T17:37:06.211169Z","shell.execute_reply.started":"2025-06-04T17:29:09.851645Z","shell.execute_reply":"2025-06-04T17:37:06.209741Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}