{"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":"# EDA OF TRAIN DATASET","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-16T13:38:27.916837Z","iopub.execute_input":"2024-11-16T13:38:27.917348Z","iopub.status.idle":"2024-11-16T13:38:31.303840Z","shell.execute_reply.started":"2024-11-16T13:38:27.917291Z","shell.execute_reply":"2024-11-16T13:38:31.302162Z"}},"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":"3f5f9670-fa28-49b5-e00f-a69cbcd2ddd7","trusted":true,"execution":{"iopub.status.busy":"2024-11-16T13:38:31.307332Z","iopub.execute_input":"2024-11-16T13:38:31.307964Z","iopub.status.idle":"2024-11-16T13:38:44.168945Z","shell.execute_reply.started":"2024-11-16T13:38:31.307911Z","shell.execute_reply":"2024-11-16T13:38:44.167628Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"id":"TufomCw8nRVl","outputId":"b2d6aa78-00e6-48ea-e206-61243de2f0c7","trusted":true,"execution":{"iopub.status.busy":"2024-11-16T13:38:44.170364Z","iopub.execute_input":"2024-11-16T13:38:44.170708Z","iopub.status.idle":"2024-11-16T13:38:44.208950Z","shell.execute_reply.started":"2024-11-16T13:38:44.170670Z","shell.execute_reply":"2024-11-16T13:38:44.207572Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.describe()","metadata":{"id":"G9cJYpLwncK9","outputId":"0de746f1-e7fe-4e51-9cf8-4880abded2f6","trusted":true,"execution":{"iopub.status.busy":"2024-11-16T13:38:44.211591Z","iopub.execute_input":"2024-11-16T13:38:44.211978Z","iopub.status.idle":"2024-11-16T13:38:48.586510Z","shell.execute_reply.started":"2024-11-16T13:38:44.211937Z","shell.execute_reply":"2024-11-16T13:38:48.584962Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"id":"0YcpycoTng0N","outputId":"3286de08-23cc-417f-b160-c458e527c270","trusted":true,"execution":{"iopub.status.busy":"2024-11-16T13:38:48.587858Z","iopub.execute_input":"2024-11-16T13:38:48.588246Z","iopub.status.idle":"2024-11-16T13:38:49.154395Z","shell.execute_reply.started":"2024-11-16T13:38:48.588207Z","shell.execute_reply":"2024-11-16T13:38:49.153160Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info(show_counts=True, verbose=True)","metadata":{"id":"gxXrJv95nub1","outputId":"7f5ab711-0a82-4ddd-c98c-ec1a40aa58fe","trusted":true,"execution":{"iopub.status.busy":"2024-11-16T13:38:49.155838Z","iopub.execute_input":"2024-11-16T13:38:49.156444Z","iopub.status.idle":"2024-11-16T13:38:49.799455Z","shell.execute_reply.started":"2024-11-16T13:38:49.156392Z","shell.execute_reply":"2024-11-16T13:38:49.798188Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.time.value_counts()","metadata":{"id":"cgFc8hAQrH6g","outputId":"f12eed78-8e28-41f2-b0ca-843463a4f704","trusted":true,"execution":{"iopub.status.busy":"2024-11-16T13:38:49.800767Z","iopub.execute_input":"2024-11-16T13:38:49.801155Z","iopub.status.idle":"2024-11-16T13:38:49.827797Z","shell.execute_reply.started":"2024-11-16T13:38:49.801115Z","shell.execute_reply":"2024-11-16T13:38:49.826384Z"}},"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":"8953dd0e-b02e-4f5f-b19c-6dc7c8934145","trusted":true,"execution":{"iopub.status.busy":"2024-11-16T13:38:49.829571Z","iopub.execute_input":"2024-11-16T13:38:49.830633Z","iopub.status.idle":"2024-11-16T13:38:52.527428Z","shell.execute_reply.started":"2024-11-16T13:38:49.830583Z","shell.execute_reply":"2024-11-16T13:38:52.524828Z"}},"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":"a9a729de-0b44-4795-f5ba-09ccac5fbb9b","trusted":true,"execution":{"iopub.status.busy":"2024-11-16T13:38:52.529343Z","iopub.execute_input":"2024-11-16T13:38:52.529795Z","iopub.status.idle":"2024-11-16T13:38:55.790177Z","shell.execute_reply.started":"2024-11-16T13:38:52.529748Z","shell.execute_reply":"2024-11-16T13:38:55.788682Z"}},"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":"453abdb3-4247-4fc0-9494-e7593e1826f7","trusted":true,"execution":{"iopub.status.busy":"2024-11-16T13:38:55.795238Z","iopub.execute_input":"2024-11-16T13:38:55.795697Z","iopub.status.idle":"2024-11-16T13:38:57.280819Z","shell.execute_reply.started":"2024-11-16T13:38:55.795651Z","shell.execute_reply":"2024-11-16T13:38:57.279417Z"}},"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":"922afbd0-eda8-43e7-99e6-119cd497e9b3","trusted":true,"execution":{"iopub.status.busy":"2024-11-16T13:38:57.282199Z","iopub.execute_input":"2024-11-16T13:38:57.282579Z","iopub.status.idle":"2024-11-16T13:38:57.915408Z","shell.execute_reply.started":"2024-11-16T13:38:57.282538Z","shell.execute_reply":"2024-11-16T13:38:57.914149Z"}},"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":"9b30b4b9-b761-46f1-f7a9-4e4517fcd9e2","trusted":true,"execution":{"iopub.status.busy":"2024-11-16T13:38:57.917559Z","iopub.execute_input":"2024-11-16T13:38:57.918028Z","iopub.status.idle":"2024-11-16T13:38:57.959842Z","shell.execute_reply.started":"2024-11-16T13:38:57.917983Z","shell.execute_reply":"2024-11-16T13:38:57.958710Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.head()","metadata":{"id":"FsgS9su3eW6U","outputId":"844e5389-479a-4217-f4ec-eaddf0e152b7","trusted":true,"execution":{"iopub.status.busy":"2024-11-16T13:38:57.961487Z","iopub.execute_input":"2024-11-16T13:38:57.961975Z","iopub.status.idle":"2024-11-16T13:38:57.989344Z","shell.execute_reply.started":"2024-11-16T13:38:57.961917Z","shell.execute_reply":"2024-11-16T13:38:57.987858Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.describe()","metadata":{"id":"UPbNipAaelJ7","outputId":"db7baa93-ffb0-479f-afab-7618892a1612","trusted":true,"execution":{"iopub.status.busy":"2024-11-16T13:38:57.990947Z","iopub.execute_input":"2024-11-16T13:38:57.991461Z","iopub.status.idle":"2024-11-16T13:38:58.980787Z","shell.execute_reply.started":"2024-11-16T13:38:57.991404Z","shell.execute_reply":"2024-11-16T13:38:58.979616Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.isnull().sum()","metadata":{"id":"s3fkNDRee4o1","outputId":"b6bafcb3-2ca2-4ff3-b1f5-de1e87ae7ace","trusted":true,"execution":{"iopub.status.busy":"2024-11-16T13:38:58.982484Z","iopub.execute_input":"2024-11-16T13:38:58.982954Z","iopub.status.idle":"2024-11-16T13:38:59.006826Z","shell.execute_reply.started":"2024-11-16T13:38:58.982908Z","shell.execute_reply":"2024-11-16T13:38:59.005489Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.info(show_counts=True, verbose=True)","metadata":{"id":"5ZTHEQAxe-kK","outputId":"14109ea2-e4bd-458c-cc10-50af945acd93","trusted":true,"execution":{"iopub.status.busy":"2024-11-16T13:38:59.008481Z","iopub.execute_input":"2024-11-16T13:38:59.008959Z","iopub.status.idle":"2024-11-16T13:38:59.064855Z","shell.execute_reply.started":"2024-11-16T13:38:59.008904Z","shell.execute_reply":"2024-11-16T13:38:59.063360Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.time.value_counts()","metadata":{"id":"Y9UeeQepfCtx","outputId":"9941c556-bf63-44de-e591-8627e2277a6d","trusted":true,"execution":{"iopub.status.busy":"2024-11-16T13:38:59.066597Z","iopub.execute_input":"2024-11-16T13:38:59.067000Z","iopub.status.idle":"2024-11-16T13:38:59.078950Z","shell.execute_reply.started":"2024-11-16T13:38:59.066956Z","shell.execute_reply":"2024-11-16T13:38:59.077554Z"}},"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":"c9da22d6-052e-4058-f277-fdbd5d353f17","trusted":true,"execution":{"iopub.status.busy":"2024-11-16T13:38:59.081029Z","iopub.execute_input":"2024-11-16T13:38:59.081497Z","iopub.status.idle":"2024-11-16T13:39:02.160752Z","shell.execute_reply.started":"2024-11-16T13:38:59.081447Z","shell.execute_reply":"2024-11-16T13:39:02.159639Z"}},"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":"308b8e6b-bd56-4c00-927c-7ba50f180c1c","trusted":true,"execution":{"iopub.status.busy":"2024-11-16T13:39:02.162240Z","iopub.execute_input":"2024-11-16T13:39:02.162627Z","iopub.status.idle":"2024-11-16T13:39:05.996215Z","shell.execute_reply.started":"2024-11-16T13:39:02.162587Z","shell.execute_reply":"2024-11-16T13:39:05.994959Z"}},"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":"98b2401a-682d-4df2-c2e9-2f33c368379c","trusted":true,"execution":{"iopub.status.busy":"2024-11-16T13:39:05.997717Z","iopub.execute_input":"2024-11-16T13:39:05.998082Z","iopub.status.idle":"2024-11-16T13:39:06.726160Z","shell.execute_reply.started":"2024-11-16T13:39:05.998043Z","shell.execute_reply":"2024-11-16T13:39:06.724597Z"}},"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":"0e46f0e3-ea81-4fd2-e63f-b45f3b48a7e3","trusted":true,"execution":{"iopub.status.busy":"2024-11-16T13:39:06.728683Z","iopub.execute_input":"2024-11-16T13:39:06.729315Z","iopub.status.idle":"2024-11-16T13:39:07.593717Z","shell.execute_reply.started":"2024-11-16T13:39:06.729252Z","shell.execute_reply":"2024-11-16T13:39:07.592534Z"}},"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":"3c4e73a1-f8e1-4baf-a696-8d802c6d108e","trusted":true,"execution":{"iopub.status.busy":"2024-11-16T13:39:07.597428Z","iopub.execute_input":"2024-11-16T13:39:07.597825Z","iopub.status.idle":"2024-11-16T13:39:08.279165Z","shell.execute_reply.started":"2024-11-16T13:39:07.597784Z","shell.execute_reply":"2024-11-16T13:39:08.277903Z"}},"outputs":[],"execution_count":null}]}