{"metadata":{"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"colab":{"provenance":[]},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":82611,"databundleVersionId":9553358,"sourceType":"competition"}],"dockerImageVersionId":30786,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# New Section","metadata":{"id":"oHzpdTVy61SV"}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt","metadata":{"id":"OTnA-ucYPhcJ","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:19.036763Z","iopub.execute_input":"2024-11-20T06:22:19.037246Z","iopub.status.idle":"2024-11-20T06:22:19.042909Z","shell.execute_reply.started":"2024-11-20T06:22:19.037200Z","shell.execute_reply":"2024-11-20T06:22:19.041438Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/brist1d/train.csv')\ntest = pd.read_csv('/kaggle/input/brist1d/test.csv')\nsubmission = pd.read_csv('/kaggle/input/brist1d/sample_submission.csv')\ntrain.shape, test.shape, submission.shape","metadata":{"id":"drZGZp3YX1Rm","outputId":"c8e04587-c17b-4488-c210-45bfbd3c4578","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:19.045266Z","iopub.execute_input":"2024-11-20T06:22:19.045686Z","iopub.status.idle":"2024-11-20T06:22:29.480313Z","shell.execute_reply.started":"2024-11-20T06:22:19.045647Z","shell.execute_reply":"2024-11-20T06:22:29.479132Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"id":"TufomCw8nRVl","outputId":"039b7db9-497a-4cba-bfc9-0f43018b6ae3","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:29.481515Z","iopub.execute_input":"2024-11-20T06:22:29.481826Z","iopub.status.idle":"2024-11-20T06:22:29.505749Z","shell.execute_reply.started":"2024-11-20T06:22:29.481794Z","shell.execute_reply":"2024-11-20T06:22:29.504545Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.describe()","metadata":{"id":"G9cJYpLwncK9","outputId":"5132a967-3ebd-4820-c4f7-c469de7dfdde","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:29.508510Z","iopub.execute_input":"2024-11-20T06:22:29.508918Z","iopub.status.idle":"2024-11-20T06:22:33.676843Z","shell.execute_reply.started":"2024-11-20T06:22:29.508879Z","shell.execute_reply":"2024-11-20T06:22:33.675653Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"id":"0YcpycoTng0N","outputId":"8d0f92b4-4282-4d52-a46c-91298c4c1131","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:33.678211Z","iopub.execute_input":"2024-11-20T06:22:33.678562Z","iopub.status.idle":"2024-11-20T06:22:34.171385Z","shell.execute_reply.started":"2024-11-20T06:22:33.678525Z","shell.execute_reply":"2024-11-20T06:22:34.170270Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info(show_counts=True, verbose=True)","metadata":{"id":"gxXrJv95nub1","outputId":"755a523f-e079-4d80-843a-055d089304b4","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:34.172879Z","iopub.execute_input":"2024-11-20T06:22:34.173338Z","iopub.status.idle":"2024-11-20T06:22:34.702529Z","shell.execute_reply.started":"2024-11-20T06:22:34.173283Z","shell.execute_reply":"2024-11-20T06:22:34.701234Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.time.value_counts()","metadata":{"id":"cgFc8hAQrH6g","outputId":"27435be7-e14a-4786-a790-253ee6b0097f","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:34.704189Z","iopub.execute_input":"2024-11-20T06:22:34.704596Z","iopub.status.idle":"2024-11-20T06:22:34.729983Z","shell.execute_reply.started":"2024-11-20T06:22:34.704556Z","shell.execute_reply":"2024-11-20T06:22:34.728632Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\n\n# Calculate the number of missing values per row for train and test datasets\ntrain['null_count'] = train.isnull().sum(axis=1)\ntest['null_count'] = test.isnull().sum(axis=1)\n\n# Set up the plot style\nsns.set_style('darkgrid')\n\n# Create subplots\nfig, axs = plt.subplots(nrows=2, ncols=1, figsize=(12, 12))\nfig.tight_layout(pad=5)\n\n# Plot for the train dataset\nsns.histplot(data=train, x='null_count', kde=True, ax=axs[0], color='blue')\naxs[0].set_title('Distribution of Null Values Per Row (Train Dataset)', fontsize=15)\naxs[0].set_xlabel('Number of Null Values')\naxs[0].set_ylabel('Count')\n\n# Plot for the test dataset\nsns.histplot(data=test, x='null_count', kde=True, ax=axs[1], color='green')\naxs[1].set_title('Distribution of Null Values Per Row (Test Dataset)', fontsize=15)\naxs[1].set_xlabel('Number of Null Values')\naxs[1].set_ylabel('Count')\n\nplt.show()","metadata":{"id":"Iz8jOrQ2n058","outputId":"dae3ffd4-239d-4db0-fa8a-e8563fc58aaf","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:34.731390Z","iopub.execute_input":"2024-11-20T06:22:34.731715Z","iopub.status.idle":"2024-11-20T06:22:36.874514Z","shell.execute_reply.started":"2024-11-20T06:22:34.731681Z","shell.execute_reply":"2024-11-20T06:22:36.873219Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\naverage_value = train['bg+1:00'].mean()\n\n# Plotting the bar plot\nplt.figure(figsize=(12, 4))\ntrain['bg+1:00'].value_counts().sort_index().plot(kind='bar', color='lightgreen')\n\n# Add a vertical line for the average value\nplt.axvline(average_value, color='red', linestyle='dashed', linewidth=2)\n\n# Add annotation for the average value\nplt.text(average_value, plt.gca().get_ylim()[1]*0.9, f'Avg: {average_value:.2f}', color='red', fontsize=12)\n\nplt.title('bg+1:00 Bar Plot')\nplt.grid()\nplt.show()\n\n# Basic statistics\nprint(train['bg+1:00'].describe())\n","metadata":{"id":"tvQ_RCA4pEpT","outputId":"70944e5f-d373-4f7a-fab0-a30a8e988b53","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:36.877885Z","iopub.execute_input":"2024-11-20T06:22:36.878399Z","iopub.status.idle":"2024-11-20T06:22:39.449369Z","shell.execute_reply.started":"2024-11-20T06:22:36.878353Z","shell.execute_reply":"2024-11-20T06:22:39.448121Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(12,5))\nsns.violinplot(data=train, x='p_num', y='bg+1:00')\nplt.title('Target by patient')\nplt.grid()\nplt.show()","metadata":{"id":"1sYZWPXtqtM5","outputId":"fcca32c7-920a-477c-f44b-06a1d24c0d90","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:39.450949Z","iopub.execute_input":"2024-11-20T06:22:39.451440Z","iopub.status.idle":"2024-11-20T06:22:40.810998Z","shell.execute_reply.started":"2024-11-20T06:22:39.451384Z","shell.execute_reply":"2024-11-20T06:22:40.809770Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\n\nplt.figure(figsize=(12, 5))\nsns.boxplot(data=train, x='p_num', y='bg+1:00')\n\n# Calculate the medians for each category in 'p_num'\nmedians = train.groupby('p_num')['bg+1:00'].median().values\npositions = range(len(medians))\n\n# Overlay the median values\nplt.scatter(positions, medians, color='red', marker='o', label='Median')\n\n# Annotate each median value\nfor i, median in enumerate(medians):\n    plt.text(i, median, f'{median:.2f}', color='black', ha='center', va='bottom')\n\n# Optionally, add a legend and grid\nplt.legend()\nplt.grid()\nplt.title('Boxplot of bg+1:00 by p_num with Median Overlay')\nplt.show()","metadata":{"id":"MEaaSjzGrslf","outputId":"acf219cb-3b41-4d75-ef9c-c664cde20587","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:40.812679Z","iopub.execute_input":"2024-11-20T06:22:40.813076Z","iopub.status.idle":"2024-11-20T06:22:41.394108Z","shell.execute_reply.started":"2024-11-20T06:22:40.813035Z","shell.execute_reply":"2024-11-20T06:22:41.392784Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"#EDA OF TEST SHEET","metadata":{"id":"nj9I_kAKeXTx"}},{"cell_type":"code","source":"test","metadata":{"id":"fL-8dWDWeoxJ","outputId":"7a4dcab4-cf87-497f-d613-66ecf7974ac0","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:41.395769Z","iopub.execute_input":"2024-11-20T06:22:41.396271Z","iopub.status.idle":"2024-11-20T06:22:41.439732Z","shell.execute_reply.started":"2024-11-20T06:22:41.396218Z","shell.execute_reply":"2024-11-20T06:22:41.438372Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.head()","metadata":{"id":"FsgS9su3eW6U","outputId":"59fd1d7d-619b-46ad-b2bc-b2dc256c40ec","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:41.441277Z","iopub.execute_input":"2024-11-20T06:22:41.441728Z","iopub.status.idle":"2024-11-20T06:22:41.470589Z","shell.execute_reply.started":"2024-11-20T06:22:41.441678Z","shell.execute_reply":"2024-11-20T06:22:41.469466Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.describe()","metadata":{"id":"UPbNipAaelJ7","outputId":"660f8a6a-1adc-4e0f-875b-cebd19354f75","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:41.471832Z","iopub.execute_input":"2024-11-20T06:22:41.472290Z","iopub.status.idle":"2024-11-20T06:22:42.310221Z","shell.execute_reply.started":"2024-11-20T06:22:41.472239Z","shell.execute_reply":"2024-11-20T06:22:42.309008Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.isnull().sum()","metadata":{"id":"s3fkNDRee4o1","outputId":"f099a92e-3a9f-4a76-fca5-90f936669c5e","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:42.311569Z","iopub.execute_input":"2024-11-20T06:22:42.311922Z","iopub.status.idle":"2024-11-20T06:22:42.333826Z","shell.execute_reply.started":"2024-11-20T06:22:42.311887Z","shell.execute_reply":"2024-11-20T06:22:42.332586Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.info(show_counts=True, verbose=True)","metadata":{"id":"5ZTHEQAxe-kK","outputId":"e6383dd1-c968-47d9-f9c1-fdb337c78063","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:42.335273Z","iopub.execute_input":"2024-11-20T06:22:42.335635Z","iopub.status.idle":"2024-11-20T06:22:42.381414Z","shell.execute_reply.started":"2024-11-20T06:22:42.335598Z","shell.execute_reply":"2024-11-20T06:22:42.380186Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.time.value_counts()","metadata":{"id":"Y9UeeQepfCtx","outputId":"201b60e0-2825-4757-cd31-0b952b4fbf85","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:42.382845Z","iopub.execute_input":"2024-11-20T06:22:42.383216Z","iopub.status.idle":"2024-11-20T06:22:42.394446Z","shell.execute_reply.started":"2024-11-20T06:22:42.383178Z","shell.execute_reply":"2024-11-20T06:22:42.393084Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nsns.heatmap(test.isnull(), cbar=False, cmap='viridis', yticklabels=False)\nplt.title('Missing Data Heatmap')\nplt.xlabel('Columns')\nplt.ylabel('Rows')\nplt.show()","metadata":{"id":"Q0mOk9frgNsP","outputId":"920089dd-15ad-4b98-cee1-e4ebb0f51581","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:42.396436Z","iopub.execute_input":"2024-11-20T06:22:42.396870Z","iopub.status.idle":"2024-11-20T06:22:44.977303Z","shell.execute_reply.started":"2024-11-20T06:22:42.396822Z","shell.execute_reply":"2024-11-20T06:22:44.976115Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"numerical_cols = test.select_dtypes(include=['float64']).columns[:10]\n\ntest[numerical_cols].hist(bins=20, figsize=(15, 10), color='skyblue', edgecolor='black')\nplt.suptitle('Distributions of Selected Numerical Columns', fontsize=16)\nplt.tight_layout(rect=[0, 0, 1, 0.96])\nplt.show()","metadata":{"id":"zzS_VDXegmez","outputId":"5e3ef1b5-c172-4560-affc-7bbc09f0925b","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:44.978779Z","iopub.execute_input":"2024-11-20T06:22:44.979240Z","iopub.status.idle":"2024-11-20T06:22:48.339860Z","shell.execute_reply.started":"2024-11-20T06:22:44.979194Z","shell.execute_reply":"2024-11-20T06:22:48.338682Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(12,5))\nsns.violinplot(data=test, x='p_num', y='bg-5:30')\nplt.title('Target by patient')\nplt.grid()\nplt.show()","metadata":{"id":"MbYxetTeifvu","outputId":"a105778e-8a76-4a13-e770-23563b9f1527","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:48.341273Z","iopub.execute_input":"2024-11-20T06:22:48.341627Z","iopub.status.idle":"2024-11-20T06:22:48.940482Z","shell.execute_reply.started":"2024-11-20T06:22:48.341588Z","shell.execute_reply":"2024-11-20T06:22:48.939267Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(12,5))\nsns.violinplot(data=test, x='p_num', y='bg-5:45')\nplt.title('Target by patient')\nplt.grid()\nplt.show()","metadata":{"id":"sIepkhzOizq_","outputId":"f84bb8bd-0cc7-452f-ad61-7a0993d4744f","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:48.942170Z","iopub.execute_input":"2024-11-20T06:22:48.942701Z","iopub.status.idle":"2024-11-20T06:22:49.539332Z","shell.execute_reply.started":"2024-11-20T06:22:48.942634Z","shell.execute_reply":"2024-11-20T06:22:49.538189Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"if 'p_num' in test.columns and 'bg-5:45' in test.columns:\n\n    filtered_data = test[['p_num', 'bg-5:45']].dropna()\n\n\n    filtered_data['bg-5:45'] = pd.to_numeric(filtered_data['bg-5:45'], errors='coerce')\n\n\n    medians = filtered_data.groupby('p_num')['bg-5:45'].median().values\n    positions = range(len(medians))\n\n\n    plt.figure(figsize=(12, 5))\n    sns.boxplot(data=filtered_data, x='p_num', y='bg-5:45', palette='viridis')\n\n\n    plt.scatter(positions, medians, color='red', marker='o', label='Median')\n\n\n    for i, median in enumerate(medians):\n        plt.text(i, median, f'{median:.2f}', color='black', ha='center', va='bottom')\n\n\n    plt.legend()\n    plt.grid(axis='y', linestyle='--', alpha=0.7)\n    plt.title('Boxplot of bg-5:45 by p_num with Median Overlay')\n    plt.xlabel('Participant (p_num)')\n    plt.ylabel('bg-5:45')\n    plt.show()\nelse:\n    print(\"The columns 'p_num' and/or 'bg-5:45' are missing in the dataset.\")","metadata":{"id":"CgrPh9bojZwb","outputId":"24479a2b-2fe8-4e62-e777-207e5aad5f0c","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:49.540888Z","iopub.execute_input":"2024-11-20T06:22:49.541338Z","iopub.status.idle":"2024-11-20T06:22:50.078067Z","shell.execute_reply.started":"2024-11-20T06:22:49.541286Z","shell.execute_reply":"2024-11-20T06:22:50.077004Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\ntrain.isnull().sum()","metadata":{"id":"c-rAmmNsCLU3","outputId":"7be479b0-a604-4906-8ef0-61856199418f","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:50.079884Z","iopub.execute_input":"2024-11-20T06:22:50.080387Z","iopub.status.idle":"2024-11-20T06:22:50.575904Z","shell.execute_reply.started":"2024-11-20T06:22:50.080313Z","shell.execute_reply":"2024-11-20T06:22:50.574701Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"bg_column_null = train[train['bg-5:55'].isnull()]","metadata":{"id":"rJJUWmvAHWXn","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:50.580719Z","iopub.execute_input":"2024-11-20T06:22:50.581153Z","iopub.status.idle":"2024-11-20T06:22:50.635320Z","shell.execute_reply.started":"2024-11-20T06:22:50.581079Z","shell.execute_reply":"2024-11-20T06:22:50.634150Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"null_rows=train.isnull().any(axis=1)","metadata":{"id":"Hx-pddQ0DZKz","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:50.636795Z","iopub.execute_input":"2024-11-20T06:22:50.637210Z","iopub.status.idle":"2024-11-20T06:22:51.079921Z","shell.execute_reply.started":"2024-11-20T06:22:50.637169Z","shell.execute_reply":"2024-11-20T06:22:51.078762Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"null_rows","metadata":{"id":"Op7WLNIMDnB1","outputId":"c00f5256-92c2-4aab-a573-975c6bb9dba7","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:51.081193Z","iopub.execute_input":"2024-11-20T06:22:51.081536Z","iopub.status.idle":"2024-11-20T06:22:51.090856Z","shell.execute_reply.started":"2024-11-20T06:22:51.081500Z","shell.execute_reply":"2024-11-20T06:22:51.089419Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"total_null_values = train.isnull().sum().sum()\nprint(f\"Total null values: {total_null_values}\")","metadata":{"id":"7F95sd29D1n9","outputId":"3a42fcbe-0fb1-41b3-9f94-f36d222842e2","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:51.092408Z","iopub.execute_input":"2024-11-20T06:22:51.092779Z","iopub.status.idle":"2024-11-20T06:22:51.591103Z","shell.execute_reply.started":"2024-11-20T06:22:51.092731Z","shell.execute_reply":"2024-11-20T06:22:51.589472Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"less_than_20 = 0.2 * len(train)\n\n\nfiltered_data = train.loc[:, train.isnull().sum() < less_than_20]\n\nfiltered_data.columns","metadata":{"id":"fIcMv5r8EAej","outputId":"25d1ea15-545c-4c6a-d1ae-35daf05bb3c9","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:51.592888Z","iopub.execute_input":"2024-11-20T06:22:51.593417Z","iopub.status.idle":"2024-11-20T06:22:52.148238Z","shell.execute_reply.started":"2024-11-20T06:22:51.593352Z","shell.execute_reply":"2024-11-20T06:22:52.147065Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(filtered_data)","metadata":{"id":"w5vOGW2jELB8","outputId":"079ca6f6-94d4-48bb-a4be-191611aa1654","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:52.149463Z","iopub.execute_input":"2024-11-20T06:22:52.149790Z","iopub.status.idle":"2024-11-20T06:22:52.190516Z","shell.execute_reply.started":"2024-11-20T06:22:52.149757Z","shell.execute_reply":"2024-11-20T06:22:52.189217Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(filtered_data.info())","metadata":{"id":"nZpWjZwXEp4U","outputId":"836e605d-0d18-45aa-8ae9-2240ad76b18f","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:52.192074Z","iopub.execute_input":"2024-11-20T06:22:52.192485Z","iopub.status.idle":"2024-11-20T06:22:52.209884Z","shell.execute_reply.started":"2024-11-20T06:22:52.192445Z","shell.execute_reply":"2024-11-20T06:22:52.208704Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"id":"a9cyXW3fF9UA","outputId":"a11751b1-02bb-49bd-ab25-725d4a90078d","trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"cleaned_unfiltered_data = train.dropna()\n\nprint(cleaned_unfiltered_data)\n\nprint(cleaned_unfiltered_data.info())","metadata":{"id":"fVhMJEbvI1lb","outputId":"02502a53-9e07-4dd5-8975-35525e7fd19e","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:52.211454Z","iopub.execute_input":"2024-11-20T06:22:52.211758Z","iopub.status.idle":"2024-11-20T06:22:52.710727Z","shell.execute_reply.started":"2024-11-20T06:22:52.211727Z","shell.execute_reply":"2024-11-20T06:22:52.709366Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"clean_train_dataset = filtered_data.dropna()\n\nprint(clean_train_dataset)\n\nprint(clean_train_dataset.info())","metadata":{"id":"E4qEh85UJBsB","outputId":"b6abd161-ed23-49c5-cefe-422ec75613d0","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:52.712237Z","iopub.execute_input":"2024-11-20T06:22:52.712598Z","iopub.status.idle":"2024-11-20T06:22:52.850260Z","shell.execute_reply.started":"2024-11-20T06:22:52.712561Z","shell.execute_reply":"2024-11-20T06:22:52.848828Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import xgboost as xgb\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import accuracy_score","metadata":{"id":"KN09UTDjKVZP","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:52.851975Z","iopub.execute_input":"2024-11-20T06:22:52.852475Z","iopub.status.idle":"2024-11-20T06:22:53.265083Z","shell.execute_reply.started":"2024-11-20T06:22:52.852422Z","shell.execute_reply":"2024-11-20T06:22:53.263540Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.columns","metadata":{"id":"jB-2P8A6KbLn","outputId":"6a313854-8448-44f3-f4a5-eb579df60c81","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:53.267409Z","iopub.execute_input":"2024-11-20T06:22:53.267792Z","iopub.status.idle":"2024-11-20T06:22:53.275657Z","shell.execute_reply.started":"2024-11-20T06:22:53.267754Z","shell.execute_reply":"2024-11-20T06:22:53.274320Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"less_than_20 = 0.2 * len(train)\n\ncolumns_to_impute = train.loc[:, train.isnull().sum() < less_than_20]\n\nnumeric_columns_to_impute = columns_to_impute.select_dtypes(include=[\"number\"])\n\nimputed_data = train.copy()\nfor column in numeric_columns_to_impute.columns:\n    imputed_data[column] = imputed_data[column].fillna(imputed_data[column].mean())\n\nprint(imputed_data)\n\nprint(imputed_data.isnull().sum())","metadata":{"id":"R3VP0nsEKe2n","outputId":"9d417a95-77e0-48da-b1c1-72f73172b188","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:53.277679Z","iopub.execute_input":"2024-11-20T06:22:53.278053Z","iopub.status.idle":"2024-11-20T06:22:55.387867Z","shell.execute_reply.started":"2024-11-20T06:22:53.278014Z","shell.execute_reply":"2024-11-20T06:22:55.386760Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"total_elements = imputed_data.size\n\ntotal_nan = imputed_data.isnull().sum().sum()\n\nnan_percentage = (total_nan / total_elements) * 100\n\nprint(f\"Percentage of NaN values in the imputed dataset: {nan_percentage:.2f}%\")","metadata":{"id":"sHXff9VVKrl_","outputId":"5761f04c-6cca-4004-8fc2-2154152b8269","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:55.389596Z","iopub.execute_input":"2024-11-20T06:22:55.389959Z","iopub.status.idle":"2024-11-20T06:22:55.918128Z","shell.execute_reply.started":"2024-11-20T06:22:55.389921Z","shell.execute_reply":"2024-11-20T06:22:55.916974Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"imputed_data.describe()","metadata":{"id":"aLulxgVHKzZe","outputId":"3908aed0-19a1-442d-98d7-10195d14f09f","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:22:55.919687Z","iopub.execute_input":"2024-11-20T06:22:55.920176Z","iopub.status.idle":"2024-11-20T06:23:00.655734Z","shell.execute_reply.started":"2024-11-20T06:22:55.920122Z","shell.execute_reply":"2024-11-20T06:23:00.654504Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nfrom sklearn.impute import SimpleImputer\nfrom sklearn.preprocessing import LabelEncoder\nfrom sklearn.metrics import accuracy_score\nfrom xgboost import XGBRegressor","metadata":{"id":"UcqqXWnOLo9P","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:23:00.657042Z","iopub.execute_input":"2024-11-20T06:23:00.657409Z","iopub.status.idle":"2024-11-20T06:23:00.837255Z","shell.execute_reply.started":"2024-11-20T06:23:00.657372Z","shell.execute_reply":"2024-11-20T06:23:00.835975Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"file_path = '/kaggle/input/brist1d/train.csv'  # Path to your dataset\ndata = pd.read_csv(file_path)\n\n# Identify target and irrelevant columns\ntarget_column = 'bg+1:00'  # Adjust this to your actual target column\nirrelevant_columns = ['id', 'p_num', 'time']  # Adjust as needed\nX = data.drop(columns=[target_column] + irrelevant_columns)\ny = data[target_column]\n\n# Separate numeric and categorical columns\nnumeric_cols = X.select_dtypes(include=['number']).columns\ncategorical_cols = X.select_dtypes(exclude=['number']).columns\n\n# Handle missing values\nnumeric_imputer = SimpleImputer(strategy='mean')\ncategorical_imputer = SimpleImputer(strategy='most_frequent')\n\nX[numeric_cols] = numeric_imputer.fit_transform(X[numeric_cols])\nX[categorical_cols] = categorical_imputer.fit_transform(X[categorical_cols])\n\n# Encode categorical data\nlabel_encoders = {}\nfor col in categorical_cols:\n    le = LabelEncoder()\n    X[col] = le.fit_transform(X[col])\n    label_encoders[col] = le\n\n# Split the data into training and testing sets\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n\n# Train an XGBoost model\nxgb_model = XGBRegressor()  # Use XGBClassifier for classification tasks\nxgb_model.fit(X_train, y_train)\n\n# Make predictions on the test set\ny_pred = xgb_model.predict(X_test)\n\n# Evaluate model performance\nrmse = np.sqrt(np.mean((y_test - y_pred) ** 2))\nprint(f\"Root Mean Squared Error (RMSE): {rmse:.2f}\")","metadata":{"id":"4kml12KiLbOV","outputId":"4367320f-de3f-4ac2-b840-ddd9c6b9694e","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:23:19.456538Z","iopub.execute_input":"2024-11-20T06:23:19.456946Z","iopub.status.idle":"2024-11-20T06:23:58.456788Z","shell.execute_reply.started":"2024-11-20T06:23:19.456912Z","shell.execute_reply":"2024-11-20T06:23:58.455789Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"baseline_pred = [y.mean()] * len(y_test)\nbaseline_rmse = np.sqrt(np.mean((y_test - baseline_pred) ** 2))\nprint(f\"Baseline RMSE: {baseline_rmse:.2f}\")","metadata":{"id":"wI6c1QVVMGpt","outputId":"5cbca50c-2241-4fa6-d7ca-1c3a75a13c0e","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:23:01.273757Z","iopub.status.idle":"2024-11-20T06:23:01.274392Z","shell.execute_reply.started":"2024-11-20T06:23:01.274069Z","shell.execute_reply":"2024-11-20T06:23:01.274124Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"mean_target = y.mean()\naccuracy = (1 - (rmse / mean_target)) * 100\nprint(f\"Accuracy: {accuracy:.2f}%\")","metadata":{"id":"jXo8xR5MMHrk","outputId":"5d15ff62-723d-4a91-81cd-ec75a0d8f913","trusted":true,"execution":{"iopub.status.busy":"2024-11-20T06:23:01.275942Z","iopub.status.idle":"2024-11-20T06:23:01.276505Z","shell.execute_reply.started":"2024-11-20T06:23:01.276230Z","shell.execute_reply":"2024-11-20T06:23:01.276257Z"}},"outputs":[],"execution_count":null}]}