{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"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"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":84896,"databundleVersionId":10305135,"sourceType":"competition"}],"dockerImageVersionId":30804,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"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":"2024-12-10T08:45:34.743912Z","iopub.execute_input":"2024-12-10T08:45:34.744958Z","iopub.status.idle":"2024-12-10T08:45:35.163514Z","shell.execute_reply.started":"2024-12-10T08:45:34.74488Z","shell.execute_reply":"2024-12-10T08:45:35.162091Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train=pd.read_csv(\"/kaggle/input/playground-series-s4e12/train.csv\")\ntrain.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:45:35.165727Z","iopub.execute_input":"2024-12-10T08:45:35.166825Z","iopub.status.idle":"2024-12-10T08:45:40.293636Z","shell.execute_reply.started":"2024-12-10T08:45:35.166783Z","shell.execute_reply":"2024-12-10T08:45:40.292295Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test=pd.read_csv(\"/kaggle/input/playground-series-s4e12/test.csv\")\ntest.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:45:40.295227Z","iopub.execute_input":"2024-12-10T08:45:40.295752Z","iopub.status.idle":"2024-12-10T08:45:43.662186Z","shell.execute_reply.started":"2024-12-10T08:45:40.295674Z","shell.execute_reply":"2024-12-10T08:45:43.660968Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:45:43.664381Z","iopub.execute_input":"2024-12-10T08:45:43.66479Z","iopub.status.idle":"2024-12-10T08:45:44.321851Z","shell.execute_reply.started":"2024-12-10T08:45:43.664746Z","shell.execute_reply":"2024-12-10T08:45:44.320595Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:45:44.323137Z","iopub.execute_input":"2024-12-10T08:45:44.323603Z","iopub.status.idle":"2024-12-10T08:45:44.758944Z","shell.execute_reply.started":"2024-12-10T08:45:44.323552Z","shell.execute_reply":"2024-12-10T08:45:44.757725Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import seaborn as sns\nimport matplotlib.pyplot as plt\n\n# Assuming your DataFrame is 'df'\navg_premium_by_gender = train.groupby('Gender')['Premium Amount'].mean().reset_index()\nsns.barplot(x='Gender', y='Premium Amount', data=avg_premium_by_gender)\nplt.title('Average Premium Amount by Gender')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:45:44.760367Z","iopub.execute_input":"2024-12-10T08:45:44.760807Z","iopub.status.idle":"2024-12-10T08:45:45.875937Z","shell.execute_reply.started":"2024-12-10T08:45:44.760758Z","shell.execute_reply":"2024-12-10T08:45:45.874594Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"**In this visuals we see that gender col doesn't make any changes**","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(8, 6))\nsns.lineplot(x='Policy Type', y='Premium Amount', data=train)\nplt.title('Policy Type vs Premium Amount')\nplt.xlabel('Policy Type')\nplt.ylabel('Premium Amount')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:45:45.877532Z","iopub.execute_input":"2024-12-10T08:45:45.878055Z","iopub.status.idle":"2024-12-10T08:46:01.338189Z","shell.execute_reply.started":"2024-12-10T08:45:45.878018Z","shell.execute_reply":"2024-12-10T08:46:01.336815Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:46:01.339839Z","iopub.execute_input":"2024-12-10T08:46:01.340308Z","iopub.status.idle":"2024-12-10T08:46:01.989922Z","shell.execute_reply.started":"2024-12-10T08:46:01.340261Z","shell.execute_reply":"2024-12-10T08:46:01.988583Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\n","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# performing EDA for train and test data simultanoeously","metadata":{}},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:46:01.991205Z","iopub.execute_input":"2024-12-10T08:46:01.991526Z","iopub.status.idle":"2024-12-10T08:46:02.641751Z","shell.execute_reply.started":"2024-12-10T08:46:01.991496Z","shell.execute_reply":"2024-12-10T08:46:02.640568Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:46:02.644946Z","iopub.execute_input":"2024-12-10T08:46:02.64531Z","iopub.status.idle":"2024-12-10T08:46:03.081177Z","shell.execute_reply.started":"2024-12-10T08:46:02.645277Z","shell.execute_reply":"2024-12-10T08:46:03.079597Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"num_cols= train.select_dtypes(include='number').columns\nnum_cols = [val for val in num_cols]\ncat_cols = train.select_dtypes(exclude='number').columns\ndatetime_cols = ['Policy Start Date']\ncat_cols = [col for col in cat_cols if col not in datetime_cols]\n\nprint(\"Numerical columns:\",)\nprint(num_cols)\nprint(\"\")\nprint(\"Categorical columns excluding datetime columns:\")\nprint(cat_cols)\nprint(\"\")\nprint(\"Datetime column:\")\ndatetime_cols","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:46:03.08296Z","iopub.execute_input":"2024-12-10T08:46:03.083593Z","iopub.status.idle":"2024-12-10T08:46:03.332219Z","shell.execute_reply.started":"2024-12-10T08:46:03.083551Z","shell.execute_reply":"2024-12-10T08:46:03.331081Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"num_cols= test.select_dtypes(include='number').columns\nnum_cols = [val for val in num_cols]\ncat_cols = test.select_dtypes(exclude='number').columns\ndatetime_cols = ['Policy Start Date']\ncat_cols = [col for col in cat_cols if col not in datetime_cols]\n\nprint(\"Numerical columns:\",)\nprint(num_cols)\nprint(\"\")\nprint(\"Categorical columns excluding datetime columns:\")\nprint(cat_cols)\nprint(\"\")\nprint(\"Datetime column:\")\ndatetime_cols","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:46:03.333636Z","iopub.execute_input":"2024-12-10T08:46:03.334039Z","iopub.status.idle":"2024-12-10T08:46:03.474352Z","shell.execute_reply.started":"2024-12-10T08:46:03.334002Z","shell.execute_reply":"2024-12-10T08:46:03.473222Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[num_cols].hist(bins=30, figsize=(12, 15))\nplt.suptitle('Histograms of Numerical Columns')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:46:03.475698Z","iopub.execute_input":"2024-12-10T08:46:03.476075Z","iopub.status.idle":"2024-12-10T08:46:05.750453Z","shell.execute_reply.started":"2024-12-10T08:46:03.476043Z","shell.execute_reply":"2024-12-10T08:46:05.749284Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\ntest[num_cols].hist(bins=30, figsize=(12, 15))\nplt.suptitle('Histograms of Numerical Columns')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:46:05.752235Z","iopub.execute_input":"2024-12-10T08:46:05.752996Z","iopub.status.idle":"2024-12-10T08:46:07.883042Z","shell.execute_reply.started":"2024-12-10T08:46:05.752944Z","shell.execute_reply":"2024-12-10T08:46:07.881911Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"**We can see clearly that train and test dataset are looking same from visualisation**","metadata":{}},{"cell_type":"code","source":"for col in cat_cols:\n    plt.figure(figsize=(4, 3))\n    sns.countplot(x=col, data=train)\n    plt.title(f'Count Plot of {col}')\n    plt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:46:07.884356Z","iopub.execute_input":"2024-12-10T08:46:07.884681Z","iopub.status.idle":"2024-12-10T08:46:16.201351Z","shell.execute_reply.started":"2024-12-10T08:46:07.88465Z","shell.execute_reply":"2024-12-10T08:46:16.199995Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"corr_matrix = train[num_cols].corr()\nplt.figure(figsize=(10, 8))\nsns.heatmap(corr_matrix, cmap = 'Greens')\nplt.title('Correlation Heatmap of Numerical Columns')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:46:16.203054Z","iopub.execute_input":"2024-12-10T08:46:16.203445Z","iopub.status.idle":"2024-12-10T08:46:16.982195Z","shell.execute_reply.started":"2024-12-10T08:46:16.203405Z","shell.execute_reply":"2024-12-10T08:46:16.980939Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import seaborn as sns\nsns.boxplot(x=train['Premium Amount'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:46:16.983927Z","iopub.execute_input":"2024-12-10T08:46:16.984285Z","iopub.status.idle":"2024-12-10T08:46:17.575924Z","shell.execute_reply.started":"2024-12-10T08:46:16.984252Z","shell.execute_reply":"2024-12-10T08:46:17.574615Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"corr = train[num_cols].corr()['Premium Amount'].sort_values(ascending = False)\npd.DataFrame(corr).style.background_gradient(cmap='Greens')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:46:17.577125Z","iopub.execute_input":"2024-12-10T08:46:17.577472Z","iopub.status.idle":"2024-12-10T08:46:19.205364Z","shell.execute_reply.started":"2024-12-10T08:46:17.577439Z","shell.execute_reply":"2024-12-10T08:46:19.197785Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Gender\"]=train[\"Gender\"].map({\"Female\":1,\"Male\":0}).astype(int)\ntest[\"Gender\"]=test[\"Gender\"].map({\"Female\":1,\"Male\":0}).astype(int)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:48:58.117881Z","iopub.execute_input":"2024-12-10T08:48:58.118335Z","iopub.status.idle":"2024-12-10T08:48:58.253069Z","shell.execute_reply.started":"2024-12-10T08:48:58.118297Z","shell.execute_reply":"2024-12-10T08:48:58.251825Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:00.098655Z","iopub.execute_input":"2024-12-10T08:49:00.099113Z","iopub.status.idle":"2024-12-10T08:49:00.127478Z","shell.execute_reply.started":"2024-12-10T08:49:00.099078Z","shell.execute_reply":"2024-12-10T08:49:00.125948Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"mean_df=round(train[\"Age\"].mean(),1)\nmean_df\nmean_df1=round(test[\"Age\"].mean(),1)\nmean_df1","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:00.532774Z","iopub.execute_input":"2024-12-10T08:49:00.53317Z","iopub.status.idle":"2024-12-10T08:49:00.553074Z","shell.execute_reply.started":"2024-12-10T08:49:00.533137Z","shell.execute_reply":"2024-12-10T08:49:00.551697Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Age\"]=train[\"Age\"].fillna(mean_df)\ntest[\"Age\"]=test[\"Age\"].fillna(mean_df1)\ntrain.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:01.068155Z","iopub.execute_input":"2024-12-10T08:49:01.068574Z","iopub.status.idle":"2024-12-10T08:49:01.676213Z","shell.execute_reply.started":"2024-12-10T08:49:01.068526Z","shell.execute_reply":"2024-12-10T08:49:01.674985Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Age\"]=train[\"Age\"].astype(int)\ntest[\"Age\"]=test[\"Age\"].astype(int)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:04.835576Z","iopub.execute_input":"2024-12-10T08:49:04.837005Z","iopub.status.idle":"2024-12-10T08:49:04.852565Z","shell.execute_reply.started":"2024-12-10T08:49:04.836958Z","shell.execute_reply":"2024-12-10T08:49:04.851299Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"median_income = train['Annual Income'].median()\n\n# Fill missing values with the median\ntrain['Annual Income'] = train['Annual Income'].fillna(median_income)\nmedian_income1 = test['Annual Income'].median()\n\n# Fill missing values with the median\ntest['Annual Income'] = test['Annual Income'].fillna(median_income1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:05.52695Z","iopub.execute_input":"2024-12-10T08:49:05.527394Z","iopub.status.idle":"2024-12-10T08:49:05.591875Z","shell.execute_reply.started":"2024-12-10T08:49:05.527357Z","shell.execute_reply":"2024-12-10T08:49:05.590822Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:06.435178Z","iopub.execute_input":"2024-12-10T08:49:06.435599Z","iopub.status.idle":"2024-12-10T08:49:06.837872Z","shell.execute_reply.started":"2024-12-10T08:49:06.435562Z","shell.execute_reply":"2024-12-10T08:49:06.83658Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Marital Status\"].unique()\ntest[\"Marital Status\"].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:08.082688Z","iopub.execute_input":"2024-12-10T08:49:08.083089Z","iopub.status.idle":"2024-12-10T08:49:08.18431Z","shell.execute_reply.started":"2024-12-10T08:49:08.083058Z","shell.execute_reply":"2024-12-10T08:49:08.182955Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Marital Status\"] = train[\"Marital Status\"].fillna(\"marital_not_specified\")\ntest[\"Marital Status\"] = test[\"Marital Status\"].fillna(\"marital_not_specified\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:08.664843Z","iopub.execute_input":"2024-12-10T08:49:08.665269Z","iopub.status.idle":"2024-12-10T08:49:08.804351Z","shell.execute_reply.started":"2024-12-10T08:49:08.665234Z","shell.execute_reply":"2024-12-10T08:49:08.80326Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test[\"Marital Status\"].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:09.600969Z","iopub.execute_input":"2024-12-10T08:49:09.60138Z","iopub.status.idle":"2024-12-10T08:49:09.659222Z","shell.execute_reply.started":"2024-12-10T08:49:09.601345Z","shell.execute_reply":"2024-12-10T08:49:09.657986Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"matr_encoded= pd.get_dummies(train[\"Marital Status\"]).astype(int)\ntrain.head\nmatr_encoded1= pd.get_dummies(test[\"Marital Status\"]).astype(int)\ntest.head","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:10.179116Z","iopub.execute_input":"2024-12-10T08:49:10.179513Z","iopub.status.idle":"2024-12-10T08:49:10.376588Z","shell.execute_reply.started":"2024-12-10T08:49:10.179478Z","shell.execute_reply":"2024-12-10T08:49:10.375422Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Education Level\"].unique()\ntest[\"Education Level\"].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:11.333164Z","iopub.execute_input":"2024-12-10T08:49:11.333577Z","iopub.status.idle":"2024-12-10T08:49:11.473611Z","shell.execute_reply.started":"2024-12-10T08:49:11.333541Z","shell.execute_reply":"2024-12-10T08:49:11.472425Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\nlabel_encoder = LabelEncoder()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:12.627626Z","iopub.execute_input":"2024-12-10T08:49:12.628426Z","iopub.status.idle":"2024-12-10T08:49:12.684576Z","shell.execute_reply.started":"2024-12-10T08:49:12.628387Z","shell.execute_reply":"2024-12-10T08:49:12.683485Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Education Level Encoded\"] = label_encoder.fit_transform(train[\"Education Level\"])\n\ntest[\"Education Level Encoded\"] = label_encoder.fit_transform(test[\"Education Level\"])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:13.181698Z","iopub.execute_input":"2024-12-10T08:49:13.182121Z","iopub.status.idle":"2024-12-10T08:49:13.604859Z","shell.execute_reply.started":"2024-12-10T08:49:13.182088Z","shell.execute_reply":"2024-12-10T08:49:13.60367Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Education Level Encoded\"].head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:13.773597Z","iopub.execute_input":"2024-12-10T08:49:13.774996Z","iopub.status.idle":"2024-12-10T08:49:13.785163Z","shell.execute_reply.started":"2024-12-10T08:49:13.774953Z","shell.execute_reply":"2024-12-10T08:49:13.783836Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:13.999839Z","iopub.execute_input":"2024-12-10T08:49:14.000282Z","iopub.status.idle":"2024-12-10T08:49:14.029245Z","shell.execute_reply.started":"2024-12-10T08:49:14.000247Z","shell.execute_reply":"2024-12-10T08:49:14.027956Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:14.673537Z","iopub.execute_input":"2024-12-10T08:49:14.674643Z","iopub.status.idle":"2024-12-10T08:49:14.704116Z","shell.execute_reply.started":"2024-12-10T08:49:14.674601Z","shell.execute_reply":"2024-12-10T08:49:14.702697Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Occupation\"].unique()\ntest[\"Occupation\"].unique()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:16.04386Z","iopub.execute_input":"2024-12-10T08:49:16.044287Z","iopub.status.idle":"2024-12-10T08:49:16.14139Z","shell.execute_reply.started":"2024-12-10T08:49:16.04425Z","shell.execute_reply":"2024-12-10T08:49:16.140299Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Occupation\"]=train[\"Occupation\"].fillna(\"occ_not_specified\")\ntest[\"Occupation\"]=test[\"Occupation\"].fillna(\"occ_not_specified\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:16.729062Z","iopub.execute_input":"2024-12-10T08:49:16.729456Z","iopub.status.idle":"2024-12-10T08:49:16.881752Z","shell.execute_reply.started":"2024-12-10T08:49:16.729424Z","shell.execute_reply":"2024-12-10T08:49:16.880162Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"encoded=pd.get_dummies(train[\"Occupation\"]).astype(int)\nencoded\nencoded1=pd.get_dummies(test[\"Occupation\"]).astype(int)\nencoded1","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:17.672073Z","iopub.execute_input":"2024-12-10T08:49:17.672449Z","iopub.status.idle":"2024-12-10T08:49:17.874788Z","shell.execute_reply.started":"2024-12-10T08:49:17.672418Z","shell.execute_reply":"2024-12-10T08:49:17.873693Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:18.325136Z","iopub.execute_input":"2024-12-10T08:49:18.325595Z","iopub.status.idle":"2024-12-10T08:49:18.353285Z","shell.execute_reply.started":"2024-12-10T08:49:18.325557Z","shell.execute_reply":"2024-12-10T08:49:18.352248Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:19.245268Z","iopub.execute_input":"2024-12-10T08:49:19.245676Z","iopub.status.idle":"2024-12-10T08:49:19.657975Z","shell.execute_reply.started":"2024-12-10T08:49:19.24564Z","shell.execute_reply":"2024-12-10T08:49:19.656788Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"health_median=round(train[\"Health Score\"].median(),6)\nhealth_median\nhealth_median1=round(test[\"Health Score\"].median(),6)\nhealth_median1","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:20.010837Z","iopub.execute_input":"2024-12-10T08:49:20.011672Z","iopub.status.idle":"2024-12-10T08:49:20.067263Z","shell.execute_reply.started":"2024-12-10T08:49:20.011625Z","shell.execute_reply":"2024-12-10T08:49:20.066085Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Health Score\"]=train[\"Health Score\"].fillna(health_median)\ntest[\"Health Score\"]=test[\"Health Score\"].fillna(health_median1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:21.052178Z","iopub.execute_input":"2024-12-10T08:49:21.05262Z","iopub.status.idle":"2024-12-10T08:49:21.070598Z","shell.execute_reply.started":"2024-12-10T08:49:21.052583Z","shell.execute_reply":"2024-12-10T08:49:21.06931Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:21.876626Z","iopub.execute_input":"2024-12-10T08:49:21.877071Z","iopub.status.idle":"2024-12-10T08:49:21.904763Z","shell.execute_reply.started":"2024-12-10T08:49:21.877036Z","shell.execute_reply":"2024-12-10T08:49:21.903621Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:22.972068Z","iopub.execute_input":"2024-12-10T08:49:22.97245Z","iopub.status.idle":"2024-12-10T08:49:23.584184Z","shell.execute_reply.started":"2024-12-10T08:49:22.972417Z","shell.execute_reply":"2024-12-10T08:49:23.583108Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train=train.drop(columns=[\"Marital Status\",\"Education Level\",\"Occupation\"],axis=1)\ntest=test.drop(columns=[\"Marital Status\",\"Education Level\",\"Occupation\"],axis=1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:23.586147Z","iopub.execute_input":"2024-12-10T08:49:23.58661Z","iopub.status.idle":"2024-12-10T08:49:23.849831Z","shell.execute_reply.started":"2024-12-10T08:49:23.58656Z","shell.execute_reply":"2024-12-10T08:49:23.848851Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:24.315947Z","iopub.execute_input":"2024-12-10T08:49:24.316364Z","iopub.status.idle":"2024-12-10T08:49:24.338491Z","shell.execute_reply.started":"2024-12-10T08:49:24.316328Z","shell.execute_reply":"2024-12-10T08:49:24.337293Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Location\"].isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:25.621425Z","iopub.execute_input":"2024-12-10T08:49:25.621854Z","iopub.status.idle":"2024-12-10T08:49:25.685883Z","shell.execute_reply.started":"2024-12-10T08:49:25.621817Z","shell.execute_reply":"2024-12-10T08:49:25.68464Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Location\"]=label_encoder.fit_transform(train[\"Location\"])\ntest[\"Location\"]=label_encoder.fit_transform(test[\"Location\"])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:26.32289Z","iopub.execute_input":"2024-12-10T08:49:26.323305Z","iopub.status.idle":"2024-12-10T08:49:26.7457Z","shell.execute_reply.started":"2024-12-10T08:49:26.323274Z","shell.execute_reply":"2024-12-10T08:49:26.744768Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:27.657907Z","iopub.execute_input":"2024-12-10T08:49:27.658338Z","iopub.status.idle":"2024-12-10T08:49:27.685647Z","shell.execute_reply.started":"2024-12-10T08:49:27.658303Z","shell.execute_reply":"2024-12-10T08:49:27.684508Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"****","metadata":{}},{"cell_type":"code","source":"train[\"Policy Type\"].unique()\ntest[\"Policy Type\"].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:28.738989Z","iopub.execute_input":"2024-12-10T08:49:28.73938Z","iopub.status.idle":"2024-12-10T08:49:28.877188Z","shell.execute_reply.started":"2024-12-10T08:49:28.739349Z","shell.execute_reply":"2024-12-10T08:49:28.875961Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Policy Type\"]=label_encoder.fit_transform(train[\"Policy Type\"])\ntrain.head()\ntest[\"Policy Type\"]=label_encoder.fit_transform(test[\"Policy Type\"])\ntest.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:29.026084Z","iopub.execute_input":"2024-12-10T08:49:29.026524Z","iopub.status.idle":"2024-12-10T08:49:29.445945Z","shell.execute_reply.started":"2024-12-10T08:49:29.026487Z","shell.execute_reply":"2024-12-10T08:49:29.444791Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:30.311694Z","iopub.execute_input":"2024-12-10T08:49:30.312149Z","iopub.status.idle":"2024-12-10T08:49:30.645002Z","shell.execute_reply.started":"2024-12-10T08:49:30.31211Z","shell.execute_reply":"2024-12-10T08:49:30.643956Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"median_in=train[\"Insurance Duration\"].median()\ntrain[\"Insurance Duration\"]=train[\"Insurance Duration\"].fillna(median_in)\nmedian_in1=test[\"Insurance Duration\"].median()\ntest[\"Insurance Duration\"]=test[\"Insurance Duration\"].fillna(median_in1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:31.544332Z","iopub.execute_input":"2024-12-10T08:49:31.544768Z","iopub.status.idle":"2024-12-10T08:49:31.608265Z","shell.execute_reply.started":"2024-12-10T08:49:31.544733Z","shell.execute_reply":"2024-12-10T08:49:31.607179Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:32.544089Z","iopub.execute_input":"2024-12-10T08:49:32.544512Z","iopub.status.idle":"2024-12-10T08:49:32.767433Z","shell.execute_reply.started":"2024-12-10T08:49:32.544467Z","shell.execute_reply":"2024-12-10T08:49:32.766011Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"depends=train[\"Number of Dependents\"].mode()\ndepends=test[\"Number of Dependents\"].mode()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:33.361587Z","iopub.execute_input":"2024-12-10T08:49:33.362837Z","iopub.status.idle":"2024-12-10T08:49:33.396352Z","shell.execute_reply.started":"2024-12-10T08:49:33.362793Z","shell.execute_reply":"2024-12-10T08:49:33.395178Z"}},"outputs":[],"execution_count":null},{"cell_type":"raw","source":"","metadata":{}},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:49:35.222628Z","iopub.execute_input":"2024-12-10T08:49:35.223093Z","iopub.status.idle":"2024-12-10T08:49:35.556682Z","shell.execute_reply.started":"2024-12-10T08:49:35.223053Z","shell.execute_reply":"2024-12-10T08:49:35.555557Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"depends=train[\"Number of Dependents\"].mode()[0]\ndepends\ndepends1=test[\"Number of Dependents\"].mode()[0]\ndepends1","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T09:03:23.349247Z","iopub.execute_input":"2024-12-10T09:03:23.349697Z","iopub.status.idle":"2024-12-10T09:03:23.377146Z","shell.execute_reply.started":"2024-12-10T09:03:23.349653Z","shell.execute_reply":"2024-12-10T09:03:23.375889Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Number of Dependents\"]=train[\"Number of Dependents\"].fillna(depends)\ntest[\"Number of Dependents\"]=test[\"Number of Dependents\"].fillna(depends1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T09:03:25.146616Z","iopub.execute_input":"2024-12-10T09:03:25.147081Z","iopub.status.idle":"2024-12-10T09:03:25.164749Z","shell.execute_reply.started":"2024-12-10T09:03:25.147044Z","shell.execute_reply":"2024-12-10T09:03:25.163414Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test[\"Number of Dependents\"].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T09:03:30.624973Z","iopub.execute_input":"2024-12-10T09:03:30.625387Z","iopub.status.idle":"2024-12-10T09:03:30.640272Z","shell.execute_reply.started":"2024-12-10T09:03:30.625352Z","shell.execute_reply":"2024-12-10T09:03:30.63865Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test[\"Number of Dependents\"].astype(int)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T09:03:32.976351Z","iopub.execute_input":"2024-12-10T09:03:32.977176Z","iopub.status.idle":"2024-12-10T09:03:32.986094Z","shell.execute_reply.started":"2024-12-10T09:03:32.977137Z","shell.execute_reply":"2024-12-10T09:03:32.985035Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:19.155516Z","iopub.execute_input":"2024-12-10T08:50:19.155957Z","iopub.status.idle":"2024-12-10T08:50:19.496761Z","shell.execute_reply.started":"2024-12-10T08:50:19.155921Z","shell.execute_reply":"2024-12-10T08:50:19.495428Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"veh=train[\"Vehicle Age\"].mode()[0]\nveh1=test[\"Vehicle Age\"].mode()[0]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:20.482046Z","iopub.execute_input":"2024-12-10T08:50:20.482477Z","iopub.status.idle":"2024-12-10T08:50:20.513764Z","shell.execute_reply.started":"2024-12-10T08:50:20.482442Z","shell.execute_reply":"2024-12-10T08:50:20.512589Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Vehicle Age\"]=train[\"Vehicle Age\"].fillna(veh)\ntest[\"Vehicle Age\"]=test[\"Vehicle Age\"].fillna(veh1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:21.430749Z","iopub.execute_input":"2024-12-10T08:50:21.431154Z","iopub.status.idle":"2024-12-10T08:50:21.450036Z","shell.execute_reply.started":"2024-12-10T08:50:21.431124Z","shell.execute_reply":"2024-12-10T08:50:21.448802Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:24.195376Z","iopub.execute_input":"2024-12-10T08:50:24.196014Z","iopub.status.idle":"2024-12-10T08:50:24.528488Z","shell.execute_reply.started":"2024-12-10T08:50:24.195975Z","shell.execute_reply":"2024-12-10T08:50:24.52723Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_credit=train[\"Credit Score\"].median()\ntrain[\"Credit Score\"]=train[\"Credit Score\"].fillna(train_credit)\ntest_credit=test[\"Credit Score\"].median()\ntest[\"Credit Score\"]=test[\"Credit Score\"].fillna(test_credit)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:25.919912Z","iopub.execute_input":"2024-12-10T08:50:25.920327Z","iopub.status.idle":"2024-12-10T08:50:25.981234Z","shell.execute_reply.started":"2024-12-10T08:50:25.920291Z","shell.execute_reply":"2024-12-10T08:50:25.980062Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\ntrain.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:27.471817Z","iopub.execute_input":"2024-12-10T08:50:27.472241Z","iopub.status.idle":"2024-12-10T08:50:27.814626Z","shell.execute_reply.started":"2024-12-10T08:50:27.472195Z","shell.execute_reply":"2024-12-10T08:50:27.81335Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Customer Feedback\"]=train[\"Customer Feedback\"].fillna(\"No_CustomerFeedback\")\ntest[\"Customer Feedback\"]=test[\"Customer Feedback\"].fillna(\"No_CustomerFeedback\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:30.381069Z","iopub.execute_input":"2024-12-10T08:50:30.381464Z","iopub.status.idle":"2024-12-10T08:50:30.523915Z","shell.execute_reply.started":"2024-12-10T08:50:30.381425Z","shell.execute_reply":"2024-12-10T08:50:30.522367Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Customer Feedback\"]=label_encoder.fit_transform(train[\"Customer Feedback\"])\ntest[\"Customer Feedback\"]=label_encoder.fit_transform(test[\"Customer Feedback\"])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:32.098108Z","iopub.execute_input":"2024-12-10T08:50:32.098547Z","iopub.status.idle":"2024-12-10T08:50:32.476371Z","shell.execute_reply.started":"2024-12-10T08:50:32.09851Z","shell.execute_reply":"2024-12-10T08:50:32.475096Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:33.868343Z","iopub.execute_input":"2024-12-10T08:50:33.868794Z","iopub.status.idle":"2024-12-10T08:50:33.891471Z","shell.execute_reply.started":"2024-12-10T08:50:33.868753Z","shell.execute_reply":"2024-12-10T08:50:33.890283Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:38.19683Z","iopub.execute_input":"2024-12-10T08:50:38.197277Z","iopub.status.idle":"2024-12-10T08:50:38.220124Z","shell.execute_reply.started":"2024-12-10T08:50:38.197237Z","shell.execute_reply":"2024-12-10T08:50:38.21862Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Exercise Frequency\"].unique()\ntest[\"Exercise Frequency\"].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:39.059966Z","iopub.execute_input":"2024-12-10T08:50:39.060356Z","iopub.status.idle":"2024-12-10T08:50:39.190274Z","shell.execute_reply.started":"2024-12-10T08:50:39.060324Z","shell.execute_reply":"2024-12-10T08:50:39.189055Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"exercise_mapping = {'Daily': 4, 'Weekly': 3, 'Monthly': 2, 'Rarely': 1}\n\n# Apply the mapping to the 'Exercise Frequency' column\ntrain['Exercise Frequency'] = train['Exercise Frequency'].map(exercise_mapping)\nexercise_mapping1 = {'Daily': 4, 'Weekly': 3, 'Monthly': 2, 'Rarely': 1}\n\n# Apply the mapping to the 'Exercise Frequency' column\ntest['Exercise Frequency'] = test['Exercise Frequency'].map(exercise_mapping1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:39.192087Z","iopub.execute_input":"2024-12-10T08:50:39.192461Z","iopub.status.idle":"2024-12-10T08:50:39.383958Z","shell.execute_reply.started":"2024-12-10T08:50:39.192425Z","shell.execute_reply":"2024-12-10T08:50:39.382811Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:39.38567Z","iopub.execute_input":"2024-12-10T08:50:39.386291Z","iopub.status.idle":"2024-12-10T08:50:39.407252Z","shell.execute_reply.started":"2024-12-10T08:50:39.386248Z","shell.execute_reply":"2024-12-10T08:50:39.405848Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"exercise_mapping = {'Yes': 1, 'No': 0}\n\n# Apply the mapping to the 'Exercise Frequency' column\ntrain['Smoking Status'] = train['Smoking Status'].map(exercise_mapping)\nexercise_mapping1 = {'Yes': 1, 'No': 0}\n\n# Apply the mapping to the 'Exercise Frequency' column\ntest['Smoking Status'] = test['Smoking Status'].map(exercise_mapping1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:39.408953Z","iopub.execute_input":"2024-12-10T08:50:39.409442Z","iopub.status.idle":"2024-12-10T08:50:39.569475Z","shell.execute_reply.started":"2024-12-10T08:50:39.409384Z","shell.execute_reply":"2024-12-10T08:50:39.568555Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:39.571745Z","iopub.execute_input":"2024-12-10T08:50:39.572199Z","iopub.status.idle":"2024-12-10T08:50:39.591871Z","shell.execute_reply.started":"2024-12-10T08:50:39.572152Z","shell.execute_reply":"2024-12-10T08:50:39.590732Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:42.614201Z","iopub.execute_input":"2024-12-10T08:50:42.614608Z","iopub.status.idle":"2024-12-10T08:50:42.635438Z","shell.execute_reply.started":"2024-12-10T08:50:42.614566Z","shell.execute_reply":"2024-12-10T08:50:42.634213Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Property Type\"].unique()\ntest[\"Property Type\"].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:42.864019Z","iopub.execute_input":"2024-12-10T08:50:42.865328Z","iopub.status.idle":"2024-12-10T08:50:42.989223Z","shell.execute_reply.started":"2024-12-10T08:50:42.865281Z","shell.execute_reply":"2024-12-10T08:50:42.988086Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"property_encoded= pd.get_dummies(train[\"Property Type\"]).astype(int)\nproperty_encoded1= pd.get_dummies(test[\"Property Type\"]).astype(int)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:57:19.523162Z","iopub.execute_input":"2024-12-10T08:57:19.523547Z","iopub.status.idle":"2024-12-10T08:57:19.670199Z","shell.execute_reply.started":"2024-12-10T08:57:19.523515Z","shell.execute_reply":"2024-12-10T08:57:19.669172Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train=pd.concat([train,property_encoded],axis=1)\ntest=pd.concat([test,property_encoded1],axis=1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:57:21.887356Z","iopub.execute_input":"2024-12-10T08:57:21.887856Z","iopub.status.idle":"2024-12-10T08:57:22.494878Z","shell.execute_reply.started":"2024-12-10T08:57:21.887816Z","shell.execute_reply":"2024-12-10T08:57:22.493298Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:47.520914Z","iopub.execute_input":"2024-12-10T08:50:47.521357Z","iopub.status.idle":"2024-12-10T08:50:47.547366Z","shell.execute_reply.started":"2024-12-10T08:50:47.521319Z","shell.execute_reply":"2024-12-10T08:50:47.546001Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:48.59455Z","iopub.execute_input":"2024-12-10T08:50:48.595304Z","iopub.status.idle":"2024-12-10T08:50:48.760613Z","shell.execute_reply.started":"2024-12-10T08:50:48.595264Z","shell.execute_reply":"2024-12-10T08:50:48.759461Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train=pd.concat([train,encoded],axis=1)\ntest=pd.concat([test,encoded1],axis=1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:49.420214Z","iopub.execute_input":"2024-12-10T08:50:49.421481Z","iopub.status.idle":"2024-12-10T08:50:49.712933Z","shell.execute_reply.started":"2024-12-10T08:50:49.42141Z","shell.execute_reply":"2024-12-10T08:50:49.711779Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T09:08:20.25476Z","iopub.execute_input":"2024-12-10T09:08:20.255208Z","iopub.status.idle":"2024-12-10T09:08:20.375082Z","shell.execute_reply.started":"2024-12-10T09:08:20.255171Z","shell.execute_reply":"2024-12-10T09:08:20.374001Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train=pd.concat([train,matr_encoded],axis=1)\ntest=pd.concat([test,matr_encoded1],axis=1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:51.412589Z","iopub.execute_input":"2024-12-10T08:50:51.413028Z","iopub.status.idle":"2024-12-10T08:50:51.794762Z","shell.execute_reply.started":"2024-12-10T08:50:51.412991Z","shell.execute_reply":"2024-12-10T08:50:51.79363Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:52.244389Z","iopub.execute_input":"2024-12-10T08:50:52.244855Z","iopub.status.idle":"2024-12-10T08:50:52.421997Z","shell.execute_reply.started":"2024-12-10T08:50:52.244814Z","shell.execute_reply":"2024-12-10T08:50:52.420782Z"}},"outputs":[],"execution_count":null},{"cell_type":"raw","source":"import datetime as dt","metadata":{}},{"cell_type":"code","source":"import datetime as dt","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:53.984181Z","iopub.execute_input":"2024-12-10T08:50:53.984686Z","iopub.status.idle":"2024-12-10T08:50:53.990038Z","shell.execute_reply.started":"2024-12-10T08:50:53.984637Z","shell.execute_reply":"2024-12-10T08:50:53.988698Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Policy Start Date\"]=pd.to_datetime(train[\"Policy Start Date\"])\ntest[\"Policy Start Date\"]=pd.to_datetime(test[\"Policy Start Date\"])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:54.788479Z","iopub.execute_input":"2024-12-10T08:50:54.788927Z","iopub.status.idle":"2024-12-10T08:50:55.483283Z","shell.execute_reply.started":"2024-12-10T08:50:54.788888Z","shell.execute_reply":"2024-12-10T08:50:55.482088Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:55.485194Z","iopub.execute_input":"2024-12-10T08:50:55.485661Z","iopub.status.idle":"2024-12-10T08:50:55.564042Z","shell.execute_reply.started":"2024-12-10T08:50:55.485613Z","shell.execute_reply":"2024-12-10T08:50:55.562821Z"}},"outputs":[],"execution_count":null},{"cell_type":"raw","source":"","metadata":{}},{"cell_type":"code","source":"train[\"day\"]=train[\"Policy Start Date\"].dt.day\ntest[\"day\"]=test[\"Policy Start Date\"].dt.day","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:57.215081Z","iopub.execute_input":"2024-12-10T08:50:57.216206Z","iopub.status.idle":"2024-12-10T08:50:57.320982Z","shell.execute_reply.started":"2024-12-10T08:50:57.216159Z","shell.execute_reply":"2024-12-10T08:50:57.319663Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.sample(20)\ntest.sample(20)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:58.123462Z","iopub.execute_input":"2024-12-10T08:50:58.123914Z","iopub.status.idle":"2024-12-10T08:50:58.230555Z","shell.execute_reply.started":"2024-12-10T08:50:58.123876Z","shell.execute_reply":"2024-12-10T08:50:58.229178Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"month\"]=train[\"Policy Start Date\"].dt.month\ntest[\"month\"]=test[\"Policy Start Date\"].dt.month","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:58.940805Z","iopub.execute_input":"2024-12-10T08:50:58.941218Z","iopub.status.idle":"2024-12-10T08:50:59.045149Z","shell.execute_reply.started":"2024-12-10T08:50:58.941182Z","shell.execute_reply":"2024-12-10T08:50:59.043677Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Year\"]=train[\"Policy Start Date\"].dt.year\ntest[\"Year\"]=test[\"Policy Start Date\"].dt.year","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:50:59.859763Z","iopub.execute_input":"2024-12-10T08:50:59.860177Z","iopub.status.idle":"2024-12-10T08:50:59.965952Z","shell.execute_reply.started":"2024-12-10T08:50:59.860143Z","shell.execute_reply":"2024-12-10T08:50:59.964805Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"time\"]=train[\"Policy Start Date\"].dt.strftime('%H:%M')\ntest[\"time\"]=test[\"Policy Start Date\"].dt.strftime('%H:%M')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:51:02.87499Z","iopub.execute_input":"2024-12-10T08:51:02.875408Z","iopub.status.idle":"2024-12-10T08:51:12.067682Z","shell.execute_reply.started":"2024-12-10T08:51:02.875373Z","shell.execute_reply":"2024-12-10T08:51:12.066495Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"train[\"Previous Claims\"].unique()\ntest[\"Previous Claims\"].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:55:37.607045Z","iopub.execute_input":"2024-12-10T08:55:37.607509Z","iopub.status.idle":"2024-12-10T08:55:37.646407Z","shell.execute_reply.started":"2024-12-10T08:55:37.607465Z","shell.execute_reply":"2024-12-10T08:55:37.645248Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"claim=train[\"Previous Claims\"].mode()[0]\nclaim\ntrain[\"Previous Claims\"]=train[\"Previous Claims\"].fillna(claim)\nclaim1=test[\"Previous Claims\"].mode()[0]\nclaim1\ntest[\"Previous Claims\"]=test[\"Previous Claims\"].fillna(claim1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:55:55.839385Z","iopub.execute_input":"2024-12-10T08:55:55.83999Z","iopub.status.idle":"2024-12-10T08:55:55.886109Z","shell.execute_reply.started":"2024-12-10T08:55:55.839946Z","shell.execute_reply":"2024-12-10T08:55:55.884803Z"}},"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},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T09:17:37.901901Z","iopub.execute_input":"2024-12-10T09:17:37.90232Z","iopub.status.idle":"2024-12-10T09:17:38.325733Z","shell.execute_reply.started":"2024-12-10T09:17:37.902286Z","shell.execute_reply":"2024-12-10T09:17:38.324409Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Previous Claims\"]=train[\"Previous Claims\"].astype(int)\ntest[\"Previous Claims\"]=test[\"Previous Claims\"].astype(int)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:56:01.491486Z","iopub.execute_input":"2024-12-10T08:56:01.491932Z","iopub.status.idle":"2024-12-10T08:56:01.507262Z","shell.execute_reply.started":"2024-12-10T08:56:01.491895Z","shell.execute_reply":"2024-12-10T08:56:01.505963Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Vehicle Age\"]=train[\"Vehicle Age\"].astype(int)\ntest[\"Vehicle Age\"]=test[\"Vehicle Age\"].astype(int)\ntest[\"Number of Dependents\"]=test[\"Number of Dependents\"].astype(int)\ntrain[\"Number of Dependents\"]=train[\"Number of Dependents\"].astype(int)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T09:04:00.711117Z","iopub.execute_input":"2024-12-10T09:04:00.711523Z","iopub.status.idle":"2024-12-10T09:04:00.737131Z","shell.execute_reply.started":"2024-12-10T09:04:00.711492Z","shell.execute_reply":"2024-12-10T09:04:00.73591Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:51:30.632267Z","iopub.execute_input":"2024-12-10T08:51:30.632686Z","iopub.status.idle":"2024-12-10T08:51:30.657295Z","shell.execute_reply.started":"2024-12-10T08:51:30.632647Z","shell.execute_reply":"2024-12-10T08:51:30.656086Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.drop(columns=[\"time\"],axis=1,inplace=True)\ntest.drop(columns=[\"time\"],axis=1,inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T08:51:32.639975Z","iopub.execute_input":"2024-12-10T08:51:32.640364Z","iopub.status.idle":"2024-12-10T08:51:32.907993Z","shell.execute_reply.started":"2024-12-10T08:51:32.640333Z","shell.execute_reply":"2024-12-10T08:51:32.906776Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.drop(columns=[\"House\",\"Condo\"],axis=1,inplace=True)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\ntest.drop(columns=[\"House\",\"Condo\",\"Apartment\"],axis=1,inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T09:13:25.567539Z","iopub.execute_input":"2024-12-10T09:13:25.56795Z","iopub.status.idle":"2024-12-10T09:13:25.642343Z","shell.execute_reply.started":"2024-12-10T09:13:25.567916Z","shell.execute_reply":"2024-12-10T09:13:25.641109Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T09:13:30.666615Z","iopub.execute_input":"2024-12-10T09:13:30.667078Z","iopub.status.idle":"2024-12-10T09:13:30.776397Z","shell.execute_reply.started":"2024-12-10T09:13:30.667043Z","shell.execute_reply":"2024-12-10T09:13:30.775217Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T09:13:34.882166Z","iopub.execute_input":"2024-12-10T09:13:34.882651Z","iopub.status.idle":"2024-12-10T09:13:34.958029Z","shell.execute_reply.started":"2024-12-10T09:13:34.882617Z","shell.execute_reply":"2024-12-10T09:13:34.956776Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T09:13:52.548495Z","iopub.execute_input":"2024-12-10T09:13:52.548966Z","iopub.status.idle":"2024-12-10T09:13:52.65639Z","shell.execute_reply.started":"2024-12-10T09:13:52.54893Z","shell.execute_reply":"2024-12-10T09:13:52.655166Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.drop(columns=[\"Policy Start Date\"],axis=1,inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T09:14:43.575753Z","iopub.execute_input":"2024-12-10T09:14:43.576185Z","iopub.status.idle":"2024-12-10T09:14:43.684264Z","shell.execute_reply.started":"2024-12-10T09:14:43.57615Z","shell.execute_reply":"2024-12-10T09:14:43.683223Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T09:15:35.998446Z","iopub.execute_input":"2024-12-10T09:15:35.998917Z","iopub.status.idle":"2024-12-10T09:15:36.087496Z","shell.execute_reply.started":"2024-12-10T09:15:35.998864Z","shell.execute_reply":"2024-12-10T09:15:36.086061Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Property Type\"].unique()\nproperty_encode=pd.get_dummies(train[\"Property Type\"]).astype(int)\nproperty_encode","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T09:38:39.007816Z","iopub.execute_input":"2024-12-10T09:38:39.008766Z","iopub.status.idle":"2024-12-10T09:38:39.198769Z","shell.execute_reply.started":"2024-12-10T09:38:39.008685Z","shell.execute_reply":"2024-12-10T09:38:39.19762Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train=pd.concat([train,property_encode],axis=1)\ntrain.drop(columns=[\"House\",\"Condo\",\"Apartment\",\"Property Type\"],axis=1,inplace=True)\ntrain.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T09:41:13.942444Z","iopub.execute_input":"2024-12-10T09:41:13.942884Z","iopub.status.idle":"2024-12-10T09:41:14.417881Z","shell.execute_reply.started":"2024-12-10T09:41:13.942847Z","shell.execute_reply":"2024-12-10T09:41:14.416523Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.drop(columns=[\"Property Type\"],axis=1,inplace=True)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T09:42:18.128653Z","iopub.execute_input":"2024-12-10T09:42:18.129143Z","iopub.status.idle":"2024-12-10T09:42:18.191632Z","shell.execute_reply.started":"2024-12-10T09:42:18.129107Z","shell.execute_reply":"2024-12-10T09:42:18.190192Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T09:43:00.957143Z","iopub.execute_input":"2024-12-10T09:43:00.957566Z","iopub.status.idle":"2024-12-10T09:43:01.010321Z","shell.execute_reply.started":"2024-12-10T09:43:00.957522Z","shell.execute_reply":"2024-12-10T09:43:01.008847Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Preparing model","metadata":{}},{"cell_type":"code","source":"# Define target variable and features\nX_train = train.drop(columns=['Premium Amount', 'id'])\ny_train = train['Premium Amount']\n\n# For the test dataset (assuming no target variable in test data)\nX_test = test.drop(columns=['id'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T09:43:05.460304Z","iopub.execute_input":"2024-12-10T09:43:05.46075Z","iopub.status.idle":"2024-12-10T09:43:05.59696Z","shell.execute_reply.started":"2024-12-10T09:43:05.460686Z","shell.execute_reply":"2024-12-10T09:43:05.595296Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.preprocessing import StandardScaler\n\nscaler = StandardScaler()\n\n# Identify numerical columns\nnumerical_columns = X_train.select_dtypes(include=['int64', 'float64','int32']).columns\n\nX_train[numerical_columns] = scaler.fit_transform(X_train[numerical_columns])\nX_test[numerical_columns] = scaler.transform(X_test[numerical_columns])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T10:00:10.921571Z","iopub.execute_input":"2024-12-10T10:00:10.922056Z","iopub.status.idle":"2024-12-10T10:00:12.408778Z","shell.execute_reply.started":"2024-12-10T10:00:10.922017Z","shell.execute_reply":"2024-12-10T10:00:12.407608Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestRegressor\n\n# Initialize Random Forest\nmodel = RandomForestRegressor(random_state=42, n_estimators=100, max_depth=10)\n\n# Train the model\nmodel.fit(X_train, y_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T10:00:35.211598Z","iopub.execute_input":"2024-12-10T10:00:35.212086Z","iopub.status.idle":"2024-12-10T10:15:38.386291Z","shell.execute_reply.started":"2024-12-10T10:00:35.212048Z","shell.execute_reply":"2024-12-10T10:15:38.385123Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.model_selection import cross_val_score\nfrom sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score\n\n# Cross-validation scores\ncv_scores = cross_val_score(model, X_train, y_train, cv=5, scoring='neg_mean_absolute_error')\nprint(\"Cross-Validated Mean Absolute Error (CV MAE):\", -cv_scores.mean())\n","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_train_pred = model.predict(X_train)\n\n# Metrics\ntrain_mae = mean_absolute_error(y_train, y_train_pred)\ntrain_mse = mean_squared_error(y_train, y_train_pred)\ntrain_r2 = r2_score(y_train, y_train_pred)\n\nprint(\"Train MAE:\", train_mae)\nprint(\"Train MSE:\", train_mse)\nprint(\"Train R² Score:\", train_r2)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T10:46:57.244809Z","iopub.execute_input":"2024-12-10T10:46:57.245995Z","iopub.status.idle":"2024-12-10T10:47:07.840436Z","shell.execute_reply.started":"2024-12-10T10:46:57.245951Z","shell.execute_reply":"2024-12-10T10:47:07.839148Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}