{"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":"# import libraries\nimport numpy as np # for linaer algebra\nimport pandas as pd # for data processing, to CSV file I/O","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:40:48.279232Z","iopub.execute_input":"2024-12-09T12:40:48.279677Z","iopub.status.idle":"2024-12-09T12:40:49.307719Z","shell.execute_reply.started":"2024-12-09T12:40:48.279619Z","shell.execute_reply":"2024-12-09T12:40:49.306586Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# read the data\ntrain_data = pd.read_csv('/kaggle/input/playground-series-s4e12/train.csv')\ntest_data = pd.read_csv('/kaggle/input/playground-series-s4e12/test.csv')\nsample_data = pd.read_csv('/kaggle/input/playground-series-s4e12/sample_submission.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:41:35.054222Z","iopub.execute_input":"2024-12-09T12:41:35.054566Z","iopub.status.idle":"2024-12-09T12:41:46.018212Z","shell.execute_reply.started":"2024-12-09T12:41:35.054536Z","shell.execute_reply":"2024-12-09T12:41:46.017076Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:41:53.789957Z","iopub.execute_input":"2024-12-09T12:41:53.790668Z","iopub.status.idle":"2024-12-09T12:41:54.605599Z","shell.execute_reply.started":"2024-12-09T12:41:53.79063Z","shell.execute_reply":"2024-12-09T12:41:54.604526Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:41:56.34374Z","iopub.execute_input":"2024-12-09T12:41:56.344131Z","iopub.status.idle":"2024-12-09T12:41:56.369722Z","shell.execute_reply.started":"2024-12-09T12:41:56.344097Z","shell.execute_reply":"2024-12-09T12:41:56.368738Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:42:13.714356Z","iopub.execute_input":"2024-12-09T12:42:13.714758Z","iopub.status.idle":"2024-12-09T12:42:13.721931Z","shell.execute_reply.started":"2024-12-09T12:42:13.714724Z","shell.execute_reply":"2024-12-09T12:42:13.720798Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data.columns","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:42:24.374254Z","iopub.execute_input":"2024-12-09T12:42:24.375064Z","iopub.status.idle":"2024-12-09T12:42:24.382878Z","shell.execute_reply.started":"2024-12-09T12:42:24.375022Z","shell.execute_reply":"2024-12-09T12:42:24.381674Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_data.columns","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:42:56.161268Z","iopub.execute_input":"2024-12-09T12:42:56.16165Z","iopub.status.idle":"2024-12-09T12:42:56.169008Z","shell.execute_reply.started":"2024-12-09T12:42:56.161616Z","shell.execute_reply":"2024-12-09T12:42:56.167864Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data = train_data.drop(columns = ['id','Marital Status','Number of Dependents', 'Education Level', 'Occupation','Vehicle Age','Insurance Duration','Policy Start Date',\n       'Customer Feedback','Property Type'])\ntest_data = test_data.drop(columns = ['id','Marital Status','Number of Dependents', 'Education Level', 'Occupation','Vehicle Age','Insurance Duration','Policy Start Date',\n       'Customer Feedback','Property Type'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:43:05.633945Z","iopub.execute_input":"2024-12-09T12:43:05.634365Z","iopub.status.idle":"2024-12-09T12:43:05.816001Z","shell.execute_reply.started":"2024-12-09T12:43:05.634331Z","shell.execute_reply":"2024-12-09T12:43:05.814497Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data.columns","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:43:20.521509Z","iopub.execute_input":"2024-12-09T12:43:20.521887Z","iopub.status.idle":"2024-12-09T12:43:20.529267Z","shell.execute_reply.started":"2024-12-09T12:43:20.521854Z","shell.execute_reply":"2024-12-09T12:43:20.52805Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_data.columns","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:43:31.19402Z","iopub.execute_input":"2024-12-09T12:43:31.194394Z","iopub.status.idle":"2024-12-09T12:43:31.201995Z","shell.execute_reply.started":"2024-12-09T12:43:31.194361Z","shell.execute_reply":"2024-12-09T12:43:31.200708Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data.dtypes","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:43:40.7244Z","iopub.execute_input":"2024-12-09T12:43:40.725401Z","iopub.status.idle":"2024-12-09T12:43:40.73492Z","shell.execute_reply.started":"2024-12-09T12:43:40.725345Z","shell.execute_reply":"2024-12-09T12:43:40.733789Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:43:49.513701Z","iopub.execute_input":"2024-12-09T12:43:49.514203Z","iopub.status.idle":"2024-12-09T12:43:49.83223Z","shell.execute_reply.started":"2024-12-09T12:43:49.514165Z","shell.execute_reply":"2024-12-09T12:43:49.83077Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data.describe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:43:58.494655Z","iopub.execute_input":"2024-12-09T12:43:58.49533Z","iopub.status.idle":"2024-12-09T12:43:58.955056Z","shell.execute_reply.started":"2024-12-09T12:43:58.495292Z","shell.execute_reply":"2024-12-09T12:43:58.953998Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data.isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:44:12.799689Z","iopub.execute_input":"2024-12-09T12:44:12.800127Z","iopub.status.idle":"2024-12-09T12:44:13.097304Z","shell.execute_reply.started":"2024-12-09T12:44:12.800089Z","shell.execute_reply":"2024-12-09T12:44:13.09611Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_data.isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:44:21.958355Z","iopub.execute_input":"2024-12-09T12:44:21.958699Z","iopub.status.idle":"2024-12-09T12:44:22.158137Z","shell.execute_reply.started":"2024-12-09T12:44:21.95867Z","shell.execute_reply":"2024-12-09T12:44:22.15714Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# fill the missing values\nnum_cols = ['Age', 'Annual Income', 'Health Score', \n                  'Previous Claims','Credit Score']\ntrain_data[num_cols]=train_data[num_cols].fillna(train_data[num_cols].mean())\ntest_data[num_cols]=test_data[num_cols].fillna(test_data[num_cols].mean())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:44:32.469311Z","iopub.execute_input":"2024-12-09T12:44:32.469716Z","iopub.status.idle":"2024-12-09T12:44:32.761127Z","shell.execute_reply.started":"2024-12-09T12:44:32.469682Z","shell.execute_reply":"2024-12-09T12:44:32.759612Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# FE - convert categorical to numerical\ntrain_data = pd.get_dummies(train_data,drop_first=True)\ntest_data = pd.get_dummies(test_data,drop_first=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:44:40.833935Z","iopub.execute_input":"2024-12-09T12:44:40.834311Z","iopub.status.idle":"2024-12-09T12:44:41.727053Z","shell.execute_reply.started":"2024-12-09T12:44:40.834278Z","shell.execute_reply":"2024-12-09T12:44:41.726081Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data.isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:44:53.824321Z","iopub.execute_input":"2024-12-09T12:44:53.824712Z","iopub.status.idle":"2024-12-09T12:44:53.852772Z","shell.execute_reply.started":"2024-12-09T12:44:53.824677Z","shell.execute_reply":"2024-12-09T12:44:53.851746Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_data.isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:45:16.249716Z","iopub.execute_input":"2024-12-09T12:45:16.25007Z","iopub.status.idle":"2024-12-09T12:45:16.270267Z","shell.execute_reply.started":"2024-12-09T12:45:16.25004Z","shell.execute_reply":"2024-12-09T12:45:16.269223Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# seperate features and target\nX_train = train_data.drop(columns = ['Premium Amount'])\ny_train = train_data['Premium Amount']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:45:29.298796Z","iopub.execute_input":"2024-12-09T12:45:29.299607Z","iopub.status.idle":"2024-12-09T12:45:29.327786Z","shell.execute_reply.started":"2024-12-09T12:45:29.299569Z","shell.execute_reply":"2024-12-09T12:45:29.326764Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.linear_model import LinearRegression\nmodel = LinearRegression()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:45:37.91585Z","iopub.execute_input":"2024-12-09T12:45:37.916229Z","iopub.status.idle":"2024-12-09T12:45:38.672387Z","shell.execute_reply.started":"2024-12-09T12:45:37.916196Z","shell.execute_reply":"2024-12-09T12:45:38.671268Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.fit(X_train,y_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:45:44.793755Z","iopub.execute_input":"2024-12-09T12:45:44.794941Z","iopub.status.idle":"2024-12-09T12:45:46.014568Z","shell.execute_reply.started":"2024-12-09T12:45:44.794901Z","shell.execute_reply":"2024-12-09T12:45:46.012698Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"predictions = model.predict(test_data)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:46:08.240107Z","iopub.execute_input":"2024-12-09T12:46:08.24051Z","iopub.status.idle":"2024-12-09T12:46:08.311503Z","shell.execute_reply.started":"2024-12-09T12:46:08.240478Z","shell.execute_reply":"2024-12-09T12:46:08.309377Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"predictions","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:46:22.694521Z","iopub.execute_input":"2024-12-09T12:46:22.695489Z","iopub.status.idle":"2024-12-09T12:46:22.702553Z","shell.execute_reply.started":"2024-12-09T12:46:22.69544Z","shell.execute_reply":"2024-12-09T12:46:22.701232Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# submission file\nsample_data['Premium Amount'] = predictions","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:46:32.574149Z","iopub.execute_input":"2024-12-09T12:46:32.574542Z","iopub.status.idle":"2024-12-09T12:46:32.580039Z","shell.execute_reply.started":"2024-12-09T12:46:32.574509Z","shell.execute_reply":"2024-12-09T12:46:32.578926Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# save file\nsample_data.to_csv('Submission.csv',index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-09T12:46:45.684197Z","iopub.execute_input":"2024-12-09T12:46:45.684548Z","iopub.status.idle":"2024-12-09T12:46:47.38959Z","shell.execute_reply.started":"2024-12-09T12:46:45.684518Z","shell.execute_reply":"2024-12-09T12:46:47.388738Z"}},"outputs":[],"execution_count":null}]}