{"metadata":{"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"language_info":{"name":"python","version":"3.10.12","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":30822,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:33.553935Z","iopub.execute_input":"2025-01-14T14:29:33.554204Z","iopub.status.idle":"2025-01-14T14:29:33.989218Z","shell.execute_reply.started":"2025-01-14T14:29:33.554179Z","shell.execute_reply":"2025-01-14T14:29:33.988027Z"}},"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":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport datetime\nfrom sklearn.impute import SimpleImputer\nimport seaborn as sns\nimport statistics as st\nfrom sklearn.model_selection import train_test_split, KFold, StratifiedKFold, GridSearchCV\nimport lightgbm as lgb\nimport xgboost as xgb\nfrom sklearn.ensemble import RandomForestRegressor\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.metrics import accuracy_score,mean_squared_log_error","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:33.990723Z","iopub.execute_input":"2025-01-14T14:29:33.991308Z","iopub.status.idle":"2025-01-14T14:29:38.62771Z","shell.execute_reply.started":"2025-01-14T14:29:33.991265Z","shell.execute_reply":"2025-01-14T14:29:38.626555Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train=pd.read_csv('/kaggle/input/playground-series-s4e12/train.csv')\ntest=pd.read_csv('/kaggle/input/playground-series-s4e12/test.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:38.628923Z","iopub.execute_input":"2025-01-14T14:29:38.629685Z","iopub.status.idle":"2025-01-14T14:29:50.53898Z","shell.execute_reply.started":"2025-01-14T14:29:38.629652Z","shell.execute_reply":"2025-01-14T14:29:50.537717Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Data Preparation and Cleaning","metadata":{}},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:50.540062Z","iopub.execute_input":"2025-01-14T14:29:50.540677Z","iopub.status.idle":"2025-01-14T14:29:50.584135Z","shell.execute_reply.started":"2025-01-14T14:29:50.540636Z","shell.execute_reply":"2025-01-14T14:29:50.582934Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:50.585042Z","iopub.execute_input":"2025-01-14T14:29:50.585307Z","iopub.status.idle":"2025-01-14T14:29:50.591979Z","shell.execute_reply.started":"2025-01-14T14:29:50.585285Z","shell.execute_reply":"2025-01-14T14:29:50.590587Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:50.594953Z","iopub.execute_input":"2025-01-14T14:29:50.595272Z","iopub.status.idle":"2025-01-14T14:29:51.250279Z","shell.execute_reply.started":"2025-01-14T14:29:50.595241Z","shell.execute_reply":"2025-01-14T14:29:51.249043Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:51.252147Z","iopub.execute_input":"2025-01-14T14:29:51.252494Z","iopub.status.idle":"2025-01-14T14:29:51.275421Z","shell.execute_reply.started":"2025-01-14T14:29:51.252445Z","shell.execute_reply":"2025-01-14T14:29:51.274081Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:51.276727Z","iopub.execute_input":"2025-01-14T14:29:51.277102Z","iopub.status.idle":"2025-01-14T14:29:51.29922Z","shell.execute_reply.started":"2025-01-14T14:29:51.277074Z","shell.execute_reply":"2025-01-14T14:29:51.297698Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:51.300416Z","iopub.execute_input":"2025-01-14T14:29:51.300826Z","iopub.status.idle":"2025-01-14T14:29:51.735668Z","shell.execute_reply.started":"2025-01-14T14:29:51.300795Z","shell.execute_reply":"2025-01-14T14:29:51.734362Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:51.736746Z","iopub.execute_input":"2025-01-14T14:29:51.737136Z","iopub.status.idle":"2025-01-14T14:29:52.360648Z","shell.execute_reply.started":"2025-01-14T14:29:51.737096Z","shell.execute_reply":"2025-01-14T14:29:52.359568Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.describe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:52.361626Z","iopub.execute_input":"2025-01-14T14:29:52.361945Z","iopub.status.idle":"2025-01-14T14:29:53.108689Z","shell.execute_reply.started":"2025-01-14T14:29:52.361915Z","shell.execute_reply":"2025-01-14T14:29:53.107551Z"}},"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'])\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:53.109702Z","iopub.execute_input":"2025-01-14T14:29:53.110119Z","iopub.status.idle":"2025-01-14T14:29:53.987739Z","shell.execute_reply.started":"2025-01-14T14:29:53.110076Z","shell.execute_reply":"2025-01-14T14:29:53.986594Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:53.988674Z","iopub.execute_input":"2025-01-14T14:29:53.989304Z","iopub.status.idle":"2025-01-14T14:29:54.561932Z","shell.execute_reply.started":"2025-01-14T14:29:53.98927Z","shell.execute_reply":"2025-01-14T14:29:54.560569Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['Policy Start_Date']=train['Policy Start Date'].dt.date\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:54.563169Z","iopub.execute_input":"2025-01-14T14:29:54.563494Z","iopub.status.idle":"2025-01-14T14:29:54.882001Z","shell.execute_reply.started":"2025-01-14T14:29:54.563447Z","shell.execute_reply":"2025-01-14T14:29:54.880855Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test['Policy Start_Date']=test['Policy Start Date'].dt.date","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:54.883378Z","iopub.execute_input":"2025-01-14T14:29:54.884131Z","iopub.status.idle":"2025-01-14T14:29:55.101086Z","shell.execute_reply.started":"2025-01-14T14:29:54.884083Z","shell.execute_reply":"2025-01-14T14:29:55.100147Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:55.102178Z","iopub.execute_input":"2025-01-14T14:29:55.102492Z","iopub.status.idle":"2025-01-14T14:29:55.12796Z","shell.execute_reply.started":"2025-01-14T14:29:55.102446Z","shell.execute_reply":"2025-01-14T14:29:55.126685Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:55.129062Z","iopub.execute_input":"2025-01-14T14:29:55.129437Z","iopub.status.idle":"2025-01-14T14:29:55.168805Z","shell.execute_reply.started":"2025-01-14T14:29:55.129399Z","shell.execute_reply":"2025-01-14T14:29:55.167532Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:55.169872Z","iopub.execute_input":"2025-01-14T14:29:55.170259Z","iopub.status.idle":"2025-01-14T14:29:55.805946Z","shell.execute_reply.started":"2025-01-14T14:29:55.170219Z","shell.execute_reply":"2025-01-14T14:29:55.804859Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:55.806957Z","iopub.execute_input":"2025-01-14T14:29:55.807244Z","iopub.status.idle":"2025-01-14T14:29:55.832935Z","shell.execute_reply.started":"2025-01-14T14:29:55.807218Z","shell.execute_reply":"2025-01-14T14:29:55.831373Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\ntrain.drop(columns=['Policy Start Date'],inplace=True)\ntest.drop(columns=['Policy Start Date'],inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:55.838785Z","iopub.execute_input":"2025-01-14T14:29:55.839114Z","iopub.status.idle":"2025-01-14T14:29:56.10288Z","shell.execute_reply.started":"2025-01-14T14:29:55.839089Z","shell.execute_reply":"2025-01-14T14:29:56.10174Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:56.105311Z","iopub.execute_input":"2025-01-14T14:29:56.105615Z","iopub.status.idle":"2025-01-14T14:29:56.736035Z","shell.execute_reply.started":"2025-01-14T14:29:56.10559Z","shell.execute_reply":"2025-01-14T14:29:56.734947Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:56.737251Z","iopub.execute_input":"2025-01-14T14:29:56.737642Z","iopub.status.idle":"2025-01-14T14:29:56.763531Z","shell.execute_reply.started":"2025-01-14T14:29:56.737606Z","shell.execute_reply":"2025-01-14T14:29:56.762296Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:56.764788Z","iopub.execute_input":"2025-01-14T14:29:56.765185Z","iopub.status.idle":"2025-01-14T14:29:56.799175Z","shell.execute_reply.started":"2025-01-14T14:29:56.765145Z","shell.execute_reply":"2025-01-14T14:29:56.797878Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['Health Score']=round(train['Health Score'],3)\ntest['Health Score']=round(test['Health Score'],3)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:56.800562Z","iopub.execute_input":"2025-01-14T14:29:56.800854Z","iopub.status.idle":"2025-01-14T14:29:56.827947Z","shell.execute_reply.started":"2025-01-14T14:29:56.800828Z","shell.execute_reply":"2025-01-14T14:29:56.826856Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:56.828876Z","iopub.execute_input":"2025-01-14T14:29:56.829152Z","iopub.status.idle":"2025-01-14T14:29:56.855767Z","shell.execute_reply.started":"2025-01-14T14:29:56.829126Z","shell.execute_reply":"2025-01-14T14:29:56.854384Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:56.856916Z","iopub.execute_input":"2025-01-14T14:29:56.857313Z","iopub.status.idle":"2025-01-14T14:29:57.4705Z","shell.execute_reply.started":"2025-01-14T14:29:56.857283Z","shell.execute_reply":"2025-01-14T14:29:57.469551Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head(50)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:57.471401Z","iopub.execute_input":"2025-01-14T14:29:57.471788Z","iopub.status.idle":"2025-01-14T14:29:57.529312Z","shell.execute_reply.started":"2025-01-14T14:29:57.471741Z","shell.execute_reply":"2025-01-14T14:29:57.528087Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.describe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:57.530857Z","iopub.execute_input":"2025-01-14T14:29:57.531344Z","iopub.status.idle":"2025-01-14T14:29:58.330411Z","shell.execute_reply.started":"2025-01-14T14:29:57.531309Z","shell.execute_reply":"2025-01-14T14:29:58.328837Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:58.331787Z","iopub.execute_input":"2025-01-14T14:29:58.332197Z","iopub.status.idle":"2025-01-14T14:29:58.339617Z","shell.execute_reply.started":"2025-01-14T14:29:58.332144Z","shell.execute_reply":"2025-01-14T14:29:58.338132Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:58.340939Z","iopub.execute_input":"2025-01-14T14:29:58.341351Z","iopub.status.idle":"2025-01-14T14:29:58.77003Z","shell.execute_reply.started":"2025-01-14T14:29:58.341316Z","shell.execute_reply":"2025-01-14T14:29:58.76883Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:58.771148Z","iopub.execute_input":"2025-01-14T14:29:58.771536Z","iopub.status.idle":"2025-01-14T14:29:58.778223Z","shell.execute_reply.started":"2025-01-14T14:29:58.771498Z","shell.execute_reply":"2025-01-14T14:29:58.777238Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"imputer=SimpleImputer(missing_values=np.nan,strategy='mean')\nimputer.fit(train.iloc[:,[1,5,8,11]].values)\ntrain.iloc[:,[1,5,8,11]]=imputer.transform(train.iloc[:,[1,5,8,11]].values)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:58.779219Z","iopub.execute_input":"2025-01-14T14:29:58.779651Z","iopub.status.idle":"2025-01-14T14:29:58.970621Z","shell.execute_reply.started":"2025-01-14T14:29:58.779622Z","shell.execute_reply":"2025-01-14T14:29:58.969728Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"imputertest=SimpleImputer(missing_values=np.nan,strategy='mean')\nimputertest.fit(test.iloc[:,[1,5,8,11]].values)\ntest.iloc[:,[1,5,8,11]]=imputertest.transform(test.iloc[:,[1,5,8,11]].values)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:58.971755Z","iopub.execute_input":"2025-01-14T14:29:58.972133Z","iopub.status.idle":"2025-01-14T14:29:59.107422Z","shell.execute_reply.started":"2025-01-14T14:29:58.972095Z","shell.execute_reply":"2025-01-14T14:29:59.106302Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['Number of Dependents']=round(train['Number of Dependents'],0)\ntest['Number of Dependents']=round(test['Number of Dependents'],0)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:59.108688Z","iopub.execute_input":"2025-01-14T14:29:59.10916Z","iopub.status.idle":"2025-01-14T14:29:59.12717Z","shell.execute_reply.started":"2025-01-14T14:29:59.109075Z","shell.execute_reply":"2025-01-14T14:29:59.126154Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head(50)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:59.128282Z","iopub.execute_input":"2025-01-14T14:29:59.128688Z","iopub.status.idle":"2025-01-14T14:29:59.182968Z","shell.execute_reply.started":"2025-01-14T14:29:59.128657Z","shell.execute_reply":"2025-01-14T14:29:59.181705Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['Previous Claims']=round(train['Previous Claims'],0)\ntest['Previous Claims']=round(test['Previous Claims'],0)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:59.184453Z","iopub.execute_input":"2025-01-14T14:29:59.184928Z","iopub.status.idle":"2025-01-14T14:29:59.210858Z","shell.execute_reply.started":"2025-01-14T14:29:59.184883Z","shell.execute_reply":"2025-01-14T14:29:59.209768Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head(50)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:59.211856Z","iopub.execute_input":"2025-01-14T14:29:59.212217Z","iopub.status.idle":"2025-01-14T14:29:59.270984Z","shell.execute_reply.started":"2025-01-14T14:29:59.212176Z","shell.execute_reply":"2025-01-14T14:29:59.269906Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.isna().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:59.272168Z","iopub.execute_input":"2025-01-14T14:29:59.272609Z","iopub.status.idle":"2025-01-14T14:29:59.89304Z","shell.execute_reply.started":"2025-01-14T14:29:59.272564Z","shell.execute_reply":"2025-01-14T14:29:59.891798Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"impute=SimpleImputer(missing_values=np.nan,strategy='most_frequent')\nimpute.fit(train.iloc[:,[4]].values)\ntrain.iloc[:,[4]]=impute.transform(train.iloc[:,[4]].values)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:29:59.894134Z","iopub.execute_input":"2025-01-14T14:29:59.894556Z","iopub.status.idle":"2025-01-14T14:30:00.128606Z","shell.execute_reply.started":"2025-01-14T14:29:59.894504Z","shell.execute_reply":"2025-01-14T14:30:00.127158Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"imputetest=SimpleImputer(missing_values=np.nan,strategy='most_frequent')\nimputetest.fit(test.iloc[:,[4]].values)\ntest.iloc[:,[4]]=impute.transform(test.iloc[:,[4]].values)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:00.129635Z","iopub.execute_input":"2025-01-14T14:30:00.130017Z","iopub.status.idle":"2025-01-14T14:30:00.292226Z","shell.execute_reply.started":"2025-01-14T14:30:00.129976Z","shell.execute_reply":"2025-01-14T14:30:00.29086Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:00.293404Z","iopub.execute_input":"2025-01-14T14:30:00.293913Z","iopub.status.idle":"2025-01-14T14:30:00.725721Z","shell.execute_reply.started":"2025-01-14T14:30:00.293793Z","shell.execute_reply":"2025-01-14T14:30:00.7247Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['Occupation']=train['Occupation'].fillna('Self-Employed')\ntest['Occupation']=test['Occupation'].fillna('Self-Employed')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:00.726808Z","iopub.execute_input":"2025-01-14T14:30:00.727145Z","iopub.status.idle":"2025-01-14T14:30:00.877772Z","shell.execute_reply.started":"2025-01-14T14:30:00.727116Z","shell.execute_reply":"2025-01-14T14:30:00.876055Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head(10)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:00.879026Z","iopub.execute_input":"2025-01-14T14:30:00.879313Z","iopub.status.idle":"2025-01-14T14:30:00.914688Z","shell.execute_reply.started":"2025-01-14T14:30:00.879288Z","shell.execute_reply":"2025-01-14T14:30:00.913332Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.head(10)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:00.916515Z","iopub.execute_input":"2025-01-14T14:30:00.917819Z","iopub.status.idle":"2025-01-14T14:30:00.947252Z","shell.execute_reply.started":"2025-01-14T14:30:00.917735Z","shell.execute_reply":"2025-01-14T14:30:00.94543Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.isna().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:00.948519Z","iopub.execute_input":"2025-01-14T14:30:00.94894Z","iopub.status.idle":"2025-01-14T14:30:01.57663Z","shell.execute_reply.started":"2025-01-14T14:30:00.948893Z","shell.execute_reply":"2025-01-14T14:30:01.575521Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.isna().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:01.577723Z","iopub.execute_input":"2025-01-14T14:30:01.578016Z","iopub.status.idle":"2025-01-14T14:30:01.987381Z","shell.execute_reply.started":"2025-01-14T14:30:01.57799Z","shell.execute_reply":"2025-01-14T14:30:01.985955Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head(50)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:01.988777Z","iopub.execute_input":"2025-01-14T14:30:01.989188Z","iopub.status.idle":"2025-01-14T14:30:02.052226Z","shell.execute_reply.started":"2025-01-14T14:30:01.989147Z","shell.execute_reply":"2025-01-14T14:30:02.050934Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"imputer_Income=SimpleImputer(missing_values=np.nan,strategy='mean')\nimputer_Income.fit(train.iloc[:,[3,13]].values)\ntrain.iloc[:,[3,13]]=imputer_Income.transform(train.iloc[:,[3,13]].values)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:02.053302Z","iopub.execute_input":"2025-01-14T14:30:02.053742Z","iopub.status.idle":"2025-01-14T14:30:02.13895Z","shell.execute_reply.started":"2025-01-14T14:30:02.053699Z","shell.execute_reply":"2025-01-14T14:30:02.137724Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.isna().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:02.140018Z","iopub.execute_input":"2025-01-14T14:30:02.140286Z","iopub.status.idle":"2025-01-14T14:30:02.782587Z","shell.execute_reply.started":"2025-01-14T14:30:02.140264Z","shell.execute_reply":"2025-01-14T14:30:02.781097Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"imputer_Income_test=SimpleImputer(missing_values=np.nan,strategy='mean')\nimputer_Income_test.fit(test.iloc[:,[3,13]].values)\ntest.iloc[:,[3,13]]=imputer_Income_test.transform(test.iloc[:,[3,13]].values)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:02.783658Z","iopub.execute_input":"2025-01-14T14:30:02.784062Z","iopub.status.idle":"2025-01-14T14:30:02.842053Z","shell.execute_reply.started":"2025-01-14T14:30:02.784022Z","shell.execute_reply":"2025-01-14T14:30:02.841003Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"imputer_PC=SimpleImputer(missing_values=np.nan,strategy='mean')\nimputer_PC.fit(train.iloc[:,[12,14]].values)\ntrain.iloc[:,[12,14]]=imputer_PC.transform(train.iloc[:,[12,14]].values)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:02.843104Z","iopub.execute_input":"2025-01-14T14:30:02.843428Z","iopub.status.idle":"2025-01-14T14:30:02.903046Z","shell.execute_reply.started":"2025-01-14T14:30:02.84339Z","shell.execute_reply":"2025-01-14T14:30:02.90182Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"imputer_PCtest=SimpleImputer(missing_values=np.nan,strategy='mean')\nimputer_PCtest.fit(test.iloc[:,[12,14]].values)\ntest.iloc[:,[12,14]]=imputer_PC.transform(test.iloc[:,[12,14]].values)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:02.904399Z","iopub.execute_input":"2025-01-14T14:30:02.904854Z","iopub.status.idle":"2025-01-14T14:30:02.949346Z","shell.execute_reply.started":"2025-01-14T14:30:02.904812Z","shell.execute_reply":"2025-01-14T14:30:02.948212Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.isna().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:02.951035Z","iopub.execute_input":"2025-01-14T14:30:02.951417Z","iopub.status.idle":"2025-01-14T14:30:03.555515Z","shell.execute_reply.started":"2025-01-14T14:30:02.951383Z","shell.execute_reply":"2025-01-14T14:30:03.55446Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.isna().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:03.556417Z","iopub.execute_input":"2025-01-14T14:30:03.556752Z","iopub.status.idle":"2025-01-14T14:30:03.962898Z","shell.execute_reply.started":"2025-01-14T14:30:03.556727Z","shell.execute_reply":"2025-01-14T14:30:03.961532Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"imputer_Feedback=SimpleImputer(missing_values=np.nan,strategy='most_frequent')\nimputer_Feedback.fit(train.iloc[:,[15]].values)\ntrain.iloc[:,[15]]=imputer_Feedback.transform(train.iloc[:,[15]].values)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:03.963954Z","iopub.execute_input":"2025-01-14T14:30:03.964226Z","iopub.status.idle":"2025-01-14T14:30:04.183125Z","shell.execute_reply.started":"2025-01-14T14:30:03.964202Z","shell.execute_reply":"2025-01-14T14:30:04.182079Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"imputer_Feedbacktest=SimpleImputer(missing_values=np.nan,strategy='most_frequent')\nimputer_Feedbacktest.fit(test.iloc[:,[15]].values)\ntest.iloc[:,[15]]=imputer_Feedbacktest.transform(test.iloc[:,[15]].values)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:04.18417Z","iopub.execute_input":"2025-01-14T14:30:04.184496Z","iopub.status.idle":"2025-01-14T14:30:04.337765Z","shell.execute_reply.started":"2025-01-14T14:30:04.184447Z","shell.execute_reply":"2025-01-14T14:30:04.336684Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.isna().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:04.338949Z","iopub.execute_input":"2025-01-14T14:30:04.339342Z","iopub.status.idle":"2025-01-14T14:30:04.950967Z","shell.execute_reply.started":"2025-01-14T14:30:04.339303Z","shell.execute_reply":"2025-01-14T14:30:04.949783Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.isna().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:04.952278Z","iopub.execute_input":"2025-01-14T14:30:04.952726Z","iopub.status.idle":"2025-01-14T14:30:05.360348Z","shell.execute_reply.started":"2025-01-14T14:30:04.952684Z","shell.execute_reply":"2025-01-14T14:30:05.359502Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['Health Score']=round(train['Health Score'],3)\ntest['Health Score']=round(test['Health Score'],3)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:05.361064Z","iopub.execute_input":"2025-01-14T14:30:05.361318Z","iopub.status.idle":"2025-01-14T14:30:05.37701Z","shell.execute_reply.started":"2025-01-14T14:30:05.361298Z","shell.execute_reply":"2025-01-14T14:30:05.375966Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head(50)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:05.378143Z","iopub.execute_input":"2025-01-14T14:30:05.378517Z","iopub.status.idle":"2025-01-14T14:30:05.436096Z","shell.execute_reply.started":"2025-01-14T14:30:05.378451Z","shell.execute_reply":"2025-01-14T14:30:05.435015Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:05.437411Z","iopub.execute_input":"2025-01-14T14:30:05.437825Z","iopub.status.idle":"2025-01-14T14:30:05.857421Z","shell.execute_reply.started":"2025-01-14T14:30:05.437778Z","shell.execute_reply":"2025-01-14T14:30:05.856293Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Data Visualisation","metadata":{}},{"cell_type":"code","source":"sns.boxplot(test['Age'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:05.865555Z","iopub.execute_input":"2025-01-14T14:30:05.865914Z","iopub.status.idle":"2025-01-14T14:30:06.113816Z","shell.execute_reply.started":"2025-01-14T14:30:05.865883Z","shell.execute_reply":"2025-01-14T14:30:06.112699Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sns.boxplot(test['Annual Income'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:06.11641Z","iopub.execute_input":"2025-01-14T14:30:06.11676Z","iopub.status.idle":"2025-01-14T14:30:06.527577Z","shell.execute_reply.started":"2025-01-14T14:30:06.11673Z","shell.execute_reply":"2025-01-14T14:30:06.526645Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sns.boxplot(test['Number of Dependents'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:06.528428Z","iopub.execute_input":"2025-01-14T14:30:06.528736Z","iopub.status.idle":"2025-01-14T14:30:06.750652Z","shell.execute_reply.started":"2025-01-14T14:30:06.52871Z","shell.execute_reply":"2025-01-14T14:30:06.749458Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sns.boxplot(test['Health Score'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:06.751881Z","iopub.execute_input":"2025-01-14T14:30:06.752209Z","iopub.status.idle":"2025-01-14T14:30:06.963629Z","shell.execute_reply.started":"2025-01-14T14:30:06.75218Z","shell.execute_reply":"2025-01-14T14:30:06.962576Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sns.boxplot(test['Previous Claims'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:06.964741Z","iopub.execute_input":"2025-01-14T14:30:06.965102Z","iopub.status.idle":"2025-01-14T14:30:07.324105Z","shell.execute_reply.started":"2025-01-14T14:30:06.965073Z","shell.execute_reply":"2025-01-14T14:30:07.322803Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sns.boxplot(test['Vehicle Age'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:07.32543Z","iopub.execute_input":"2025-01-14T14:30:07.325885Z","iopub.status.idle":"2025-01-14T14:30:07.664894Z","shell.execute_reply.started":"2025-01-14T14:30:07.325833Z","shell.execute_reply":"2025-01-14T14:30:07.663864Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### Feature Engineering","metadata":{}},{"cell_type":"code","source":"train['Exercise Frequency'].unique()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:07.665859Z","iopub.execute_input":"2025-01-14T14:30:07.666146Z","iopub.status.idle":"2025-01-14T14:30:07.744128Z","shell.execute_reply.started":"2025-01-14T14:30:07.666121Z","shell.execute_reply":"2025-01-14T14:30:07.743114Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"Dict={}\nlst=['Weekly','Monthly','Daily','Rarely']\nfor key,val in enumerate(lst):\n    Dict[val]=key\nprint(Dict)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:07.745152Z","iopub.execute_input":"2025-01-14T14:30:07.745558Z","iopub.status.idle":"2025-01-14T14:30:07.752056Z","shell.execute_reply.started":"2025-01-14T14:30:07.745507Z","shell.execute_reply":"2025-01-14T14:30:07.750926Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:07.753061Z","iopub.execute_input":"2025-01-14T14:30:07.75339Z","iopub.status.idle":"2025-01-14T14:30:07.794402Z","shell.execute_reply.started":"2025-01-14T14:30:07.753362Z","shell.execute_reply":"2025-01-14T14:30:07.793034Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['Exercise_Frequency']=train['Exercise Frequency'].map(Dict)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:07.795704Z","iopub.execute_input":"2025-01-14T14:30:07.796048Z","iopub.status.idle":"2025-01-14T14:30:07.879981Z","shell.execute_reply.started":"2025-01-14T14:30:07.796016Z","shell.execute_reply":"2025-01-14T14:30:07.878424Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head(50)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:07.881154Z","iopub.execute_input":"2025-01-14T14:30:07.881586Z","iopub.status.idle":"2025-01-14T14:30:07.938822Z","shell.execute_reply.started":"2025-01-14T14:30:07.881545Z","shell.execute_reply":"2025-01-14T14:30:07.937119Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test['Exercise_Frequency']=test['Exercise Frequency'].map(Dict)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:07.940743Z","iopub.execute_input":"2025-01-14T14:30:07.941194Z","iopub.status.idle":"2025-01-14T14:30:08.006125Z","shell.execute_reply.started":"2025-01-14T14:30:07.941151Z","shell.execute_reply":"2025-01-14T14:30:08.004739Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.head(50)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:08.00728Z","iopub.execute_input":"2025-01-14T14:30:08.0076Z","iopub.status.idle":"2025-01-14T14:30:08.071888Z","shell.execute_reply.started":"2025-01-14T14:30:08.007572Z","shell.execute_reply":"2025-01-14T14:30:08.070673Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"gender={'Female':0,'Male':1}\n\ntrain['Gender_type']=train['Gender'].map(gender)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:08.072811Z","iopub.execute_input":"2025-01-14T14:30:08.073091Z","iopub.status.idle":"2025-01-14T14:30:08.150787Z","shell.execute_reply.started":"2025-01-14T14:30:08.073065Z","shell.execute_reply":"2025-01-14T14:30:08.149663Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head(10)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:08.152001Z","iopub.execute_input":"2025-01-14T14:30:08.152381Z","iopub.status.idle":"2025-01-14T14:30:08.179522Z","shell.execute_reply.started":"2025-01-14T14:30:08.15234Z","shell.execute_reply":"2025-01-14T14:30:08.178352Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:08.180763Z","iopub.execute_input":"2025-01-14T14:30:08.181153Z","iopub.status.idle":"2025-01-14T14:30:08.221428Z","shell.execute_reply.started":"2025-01-14T14:30:08.181104Z","shell.execute_reply":"2025-01-14T14:30:08.220158Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test['Gender_type']=test['Gender'].map(gender)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:08.22256Z","iopub.execute_input":"2025-01-14T14:30:08.222941Z","iopub.status.idle":"2025-01-14T14:30:08.281169Z","shell.execute_reply.started":"2025-01-14T14:30:08.22289Z","shell.execute_reply":"2025-01-14T14:30:08.280107Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"marital_status={'Married':0,'Divorced':1,'Single':2}\ntrain['Marital Status']=train['Marital Status'].map(marital_status)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:08.282326Z","iopub.execute_input":"2025-01-14T14:30:08.28271Z","iopub.status.idle":"2025-01-14T14:30:08.372705Z","shell.execute_reply.started":"2025-01-14T14:30:08.282671Z","shell.execute_reply":"2025-01-14T14:30:08.371622Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test['Marital Status']=test['Marital Status'].map(marital_status)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:08.37372Z","iopub.execute_input":"2025-01-14T14:30:08.374094Z","iopub.status.idle":"2025-01-14T14:30:08.435939Z","shell.execute_reply.started":"2025-01-14T14:30:08.374054Z","shell.execute_reply":"2025-01-14T14:30:08.434814Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['Education Level'].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:08.436929Z","iopub.execute_input":"2025-01-14T14:30:08.437526Z","iopub.status.idle":"2025-01-14T14:30:08.522155Z","shell.execute_reply.started":"2025-01-14T14:30:08.43745Z","shell.execute_reply":"2025-01-14T14:30:08.520945Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"edu_level={\"Bachelor's\":0,\"Master's\":1,'High School':2,'PhD':3}\ntrain['Education Level']=train['Education Level'].map(edu_level)\ntest['Education Level']=test['Education Level'].map(edu_level)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:08.52307Z","iopub.execute_input":"2025-01-14T14:30:08.523348Z","iopub.status.idle":"2025-01-14T14:30:08.646262Z","shell.execute_reply.started":"2025-01-14T14:30:08.52332Z","shell.execute_reply":"2025-01-14T14:30:08.645175Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['Occupation'].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:08.647351Z","iopub.execute_input":"2025-01-14T14:30:08.647744Z","iopub.status.idle":"2025-01-14T14:30:08.727336Z","shell.execute_reply.started":"2025-01-14T14:30:08.647714Z","shell.execute_reply":"2025-01-14T14:30:08.726247Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"occ={'Self-Employed':0,'Employed':1,'Unemployed':2}\ntrain['Occupation']=train['Occupation'].map(occ)\ntest['Occupation']=test['Occupation'].map(occ)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:08.728398Z","iopub.execute_input":"2025-01-14T14:30:08.728886Z","iopub.status.idle":"2025-01-14T14:30:08.865017Z","shell.execute_reply.started":"2025-01-14T14:30:08.728841Z","shell.execute_reply":"2025-01-14T14:30:08.863655Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['Location'].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:08.866157Z","iopub.execute_input":"2025-01-14T14:30:08.866577Z","iopub.status.idle":"2025-01-14T14:30:08.941034Z","shell.execute_reply.started":"2025-01-14T14:30:08.866542Z","shell.execute_reply":"2025-01-14T14:30:08.940054Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"location={'Urban':0,'Rural':1,'Suburban':2}\ntrain['Location']=train['Location'].map(location)\ntest['Location']=test['Location'].map(location)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:08.942061Z","iopub.execute_input":"2025-01-14T14:30:08.942387Z","iopub.status.idle":"2025-01-14T14:30:09.066623Z","shell.execute_reply.started":"2025-01-14T14:30:08.942359Z","shell.execute_reply":"2025-01-14T14:30:09.065433Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['Policy Type'].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:09.06789Z","iopub.execute_input":"2025-01-14T14:30:09.068199Z","iopub.status.idle":"2025-01-14T14:30:09.149128Z","shell.execute_reply.started":"2025-01-14T14:30:09.068172Z","shell.execute_reply":"2025-01-14T14:30:09.148024Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"poltype={'Premium':0,'Comprehensive':1,'Basic':2}\ntrain['Policy Type']=train['Policy Type'].map(poltype)\ntest['Policy Type']=test['Policy Type'].map(poltype)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:09.150152Z","iopub.execute_input":"2025-01-14T14:30:09.150638Z","iopub.status.idle":"2025-01-14T14:30:09.292365Z","shell.execute_reply.started":"2025-01-14T14:30:09.150412Z","shell.execute_reply":"2025-01-14T14:30:09.291223Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['Customer Feedback'].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:09.293352Z","iopub.execute_input":"2025-01-14T14:30:09.293677Z","iopub.status.idle":"2025-01-14T14:30:09.367385Z","shell.execute_reply.started":"2025-01-14T14:30:09.29364Z","shell.execute_reply":"2025-01-14T14:30:09.366246Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"feedback={'Poor':0,'Average':1,'Good':2}\ntrain['Customer Feedback']=train['Customer Feedback'].map(feedback)\ntest['Customer Feedback']=test['Customer Feedback'].map(feedback)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:09.368297Z","iopub.execute_input":"2025-01-14T14:30:09.368605Z","iopub.status.idle":"2025-01-14T14:30:09.514582Z","shell.execute_reply.started":"2025-01-14T14:30:09.368571Z","shell.execute_reply":"2025-01-14T14:30:09.513462Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['Smoking Status'].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:09.515736Z","iopub.execute_input":"2025-01-14T14:30:09.516062Z","iopub.status.idle":"2025-01-14T14:30:09.587005Z","shell.execute_reply.started":"2025-01-14T14:30:09.516034Z","shell.execute_reply":"2025-01-14T14:30:09.585837Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"smoke_status={'Yes':0,'No':1}\ntrain['Smoking Status']=train['Smoking Status'].map(smoke_status)\ntest['Smoking Status']=test['Smoking Status'].map(smoke_status)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:09.587956Z","iopub.execute_input":"2025-01-14T14:30:09.588362Z","iopub.status.idle":"2025-01-14T14:30:09.710501Z","shell.execute_reply.started":"2025-01-14T14:30:09.588261Z","shell.execute_reply":"2025-01-14T14:30:09.709435Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['Property Type'].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:09.711385Z","iopub.execute_input":"2025-01-14T14:30:09.711679Z","iopub.status.idle":"2025-01-14T14:30:09.787347Z","shell.execute_reply.started":"2025-01-14T14:30:09.711653Z","shell.execute_reply":"2025-01-14T14:30:09.786112Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"prop_type={'House':0,'Apartment':1,'Condo':2}\ntrain['Property Type']=train['Property Type'].map(prop_type)\ntest['Property Type']=test['Property Type'].map(prop_type)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:09.78844Z","iopub.execute_input":"2025-01-14T14:30:09.78902Z","iopub.status.idle":"2025-01-14T14:30:09.912944Z","shell.execute_reply.started":"2025-01-14T14:30:09.788933Z","shell.execute_reply":"2025-01-14T14:30:09.911811Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train=train.drop(columns=['Gender','Exercise Frequency'])\ntest=test.drop(columns=['Gender','Exercise Frequency'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:09.914272Z","iopub.execute_input":"2025-01-14T14:30:09.914721Z","iopub.status.idle":"2025-01-14T14:30:10.153747Z","shell.execute_reply.started":"2025-01-14T14:30:09.914681Z","shell.execute_reply":"2025-01-14T14:30:10.152586Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['Credit Score']=round(train['Credit Score'],0)\ntest['Credit Score']=round(test['Credit Score'],0)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:10.154708Z","iopub.execute_input":"2025-01-14T14:30:10.155017Z","iopub.status.idle":"2025-01-14T14:30:10.169091Z","shell.execute_reply.started":"2025-01-14T14:30:10.15499Z","shell.execute_reply":"2025-01-14T14:30:10.167737Z"}},"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'])\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:10.170783Z","iopub.execute_input":"2025-01-14T14:30:10.171189Z","iopub.status.idle":"2025-01-14T14:30:10.413588Z","shell.execute_reply.started":"2025-01-14T14:30:10.171156Z","shell.execute_reply":"2025-01-14T14:30:10.412435Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"today=datetime.datetime.today()\ntoday","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:10.414422Z","iopub.execute_input":"2025-01-14T14:30:10.414975Z","iopub.status.idle":"2025-01-14T14:30:10.42242Z","shell.execute_reply.started":"2025-01-14T14:30:10.414933Z","shell.execute_reply":"2025-01-14T14:30:10.421008Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['Time_Elapsed_between_Days']=(today-train['Policy Start_Date']).dt.days\ntest['Time_Elapsed_between_Days']=(today-train['Policy Start_Date']).dt.days","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:10.424223Z","iopub.execute_input":"2025-01-14T14:30:10.424758Z","iopub.status.idle":"2025-01-14T14:30:10.57445Z","shell.execute_reply.started":"2025-01-14T14:30:10.424587Z","shell.execute_reply":"2025-01-14T14:30:10.573523Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train=train.drop(columns=['Policy Start_Date'])\ntest=test.drop(columns=['Policy Start_Date'])\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:10.575711Z","iopub.execute_input":"2025-01-14T14:30:10.576106Z","iopub.status.idle":"2025-01-14T14:30:10.771759Z","shell.execute_reply.started":"2025-01-14T14:30:10.576067Z","shell.execute_reply":"2025-01-14T14:30:10.770764Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:10.772872Z","iopub.execute_input":"2025-01-14T14:30:10.773256Z","iopub.status.idle":"2025-01-14T14:30:10.793522Z","shell.execute_reply.started":"2025-01-14T14:30:10.773217Z","shell.execute_reply":"2025-01-14T14:30:10.792038Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:10.79483Z","iopub.execute_input":"2025-01-14T14:30:10.795138Z","iopub.status.idle":"2025-01-14T14:30:10.835507Z","shell.execute_reply.started":"2025-01-14T14:30:10.795114Z","shell.execute_reply":"2025-01-14T14:30:10.834417Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:10.836591Z","iopub.execute_input":"2025-01-14T14:30:10.837058Z","iopub.status.idle":"2025-01-14T14:30:10.871308Z","shell.execute_reply.started":"2025-01-14T14:30:10.837014Z","shell.execute_reply":"2025-01-14T14:30:10.869954Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:10.872247Z","iopub.execute_input":"2025-01-14T14:30:10.872583Z","iopub.status.idle":"2025-01-14T14:30:10.92256Z","shell.execute_reply.started":"2025-01-14T14:30:10.872551Z","shell.execute_reply":"2025-01-14T14:30:10.920429Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(train.shape)\nprint(test.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:10.924258Z","iopub.execute_input":"2025-01-14T14:30:10.924814Z","iopub.status.idle":"2025-01-14T14:30:10.931517Z","shell.execute_reply.started":"2025-01-14T14:30:10.924776Z","shell.execute_reply":"2025-01-14T14:30:10.929432Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Splitting the data and training with lgbm regressor","metadata":{}},{"cell_type":"code","source":"X=train.drop(columns=['Premium Amount'])\ny=train['Premium Amount']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:10.932774Z","iopub.execute_input":"2025-01-14T14:30:10.933407Z","iopub.status.idle":"2025-01-14T14:30:11.02473Z","shell.execute_reply.started":"2025-01-14T14:30:10.933333Z","shell.execute_reply":"2025-01-14T14:30:11.023219Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"n_splits=5\nlgb_params={\n    'objective':'regression',\n    'metric':'rmse',\n    'boosting_type':'gbdt',\n    'learning_rate':0.01,\n    'n_estimators':1000,\n    'early_stopping_rounds':50,\n    'random_state':42\n}","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:11.026166Z","iopub.execute_input":"2025-01-14T14:30:11.026663Z","iopub.status.idle":"2025-01-14T14:30:11.031839Z","shell.execute_reply.started":"2025-01-14T14:30:11.026618Z","shell.execute_reply":"2025-01-14T14:30:11.030852Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"xgb_params={\n    'objective':'reg:squarederror',\n    'eval_metric':'rmse',\n    'learning_rate':0.01,\n    'n_estimators':1000,\n    'early_stopping_rounds':50,\n    'random_state':42\n}","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:11.032801Z","iopub.execute_input":"2025-01-14T14:30:11.033132Z","iopub.status.idle":"2025-01-14T14:30:11.055714Z","shell.execute_reply.started":"2025-01-14T14:30:11.033107Z","shell.execute_reply":"2025-01-14T14:30:11.054329Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#Initialise Predictions\nlgb_predictions=np.zeros(len(test))\nxgb_predictions=np.zeros(len(test))\nkf=KFold(n_splits=n_splits,shuffle=True,random_state=42)\n#RMSLE function\ndef acc_score(y_true,y_pred):\n    return np.sqrt(mean_squared_log_error(y_true,np.maximum(y_pred,0)))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:11.056827Z","iopub.execute_input":"2025-01-14T14:30:11.057134Z","iopub.status.idle":"2025-01-14T14:30:11.07998Z","shell.execute_reply.started":"2025-01-14T14:30:11.057108Z","shell.execute_reply":"2025-01-14T14:30:11.07867Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for fold,(train_idx,val_idx) in enumerate(kf.split(X)):\n    X_train,X_val=X.iloc[train_idx],X.iloc[val_idx]\n    y_train,y_val=y.iloc[train_idx],y.iloc[val_idx]\n    #lightgbm\n    lgb_model=lgb.LGBMRegressor(**lgb_params)\n    lgb_model.fit(X_train,y_train,eval_set=[(X_val,y_val)])\n    lgb_val_pred=lgb_model.predict(X_val)\n    print(acc_score(y_val,lgb_val_pred))\n    lgb_predictions+=lgb_model.predict(test)/n_splits\n    \n    ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:30:11.080954Z","iopub.execute_input":"2025-01-14T14:30:11.081243Z","iopub.status.idle":"2025-01-14T14:37:40.121298Z","shell.execute_reply.started":"2025-01-14T14:30:11.081217Z","shell.execute_reply":"2025-01-14T14:37:40.120045Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"lgb_predictions","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:37:40.122331Z","iopub.execute_input":"2025-01-14T14:37:40.122669Z","iopub.status.idle":"2025-01-14T14:37:40.128968Z","shell.execute_reply.started":"2025-01-14T14:37:40.122634Z","shell.execute_reply":"2025-01-14T14:37:40.127787Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Submission","metadata":{}},{"cell_type":"code","source":"pred_Targ1=pd.DataFrame()\npred_Targ1['id']=test['id']\npred_Targ1","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:37:40.129862Z","iopub.execute_input":"2025-01-14T14:37:40.130179Z","iopub.status.idle":"2025-01-14T14:37:40.172924Z","shell.execute_reply.started":"2025-01-14T14:37:40.130145Z","shell.execute_reply":"2025-01-14T14:37:40.171844Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pred_Targ1['Premium Amount']=lgb_predictions","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:37:40.17382Z","iopub.execute_input":"2025-01-14T14:37:40.174161Z","iopub.status.idle":"2025-01-14T14:37:40.180319Z","shell.execute_reply.started":"2025-01-14T14:37:40.174133Z","shell.execute_reply":"2025-01-14T14:37:40.178918Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pred_Targ1.to_csv('//kaggle/working/Submission.csv',header=True,index=False,mode='w')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-14T14:37:40.181727Z","iopub.execute_input":"2025-01-14T14:37:40.182057Z","iopub.status.idle":"2025-01-14T14:37:41.776461Z","shell.execute_reply.started":"2025-01-14T14:37:40.182016Z","shell.execute_reply":"2025-01-14T14:37:41.775537Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}