{"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 numpy as np\nimport pandas as pd\n\ndata=pd.read_csv(\"/kaggle/input/playground-series-s4e12/train.csv\")","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2024-12-19T08:11:06.323581Z","iopub.execute_input":"2024-12-19T08:11:06.324761Z","iopub.status.idle":"2024-12-19T08:11:12.072275Z","shell.execute_reply.started":"2024-12-19T08:11:06.324697Z","shell.execute_reply":"2024-12-19T08:11:12.069515Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data1=data.copy()\n\ndef genderToBinary(dat):\n    dat[\"Gender\"]=(dat[\"Gender\"]==\"Female\")+0\ndef maritalToNum(dat):\n    dat.replace({\"Marital Status\":{\"Married\":int(1),\"Single\":int(0),\"Divorced\":int(2)}},inplace=True)\ndef educationToNum(dat):\n    dat.replace({'Education Level':{\"Master's\":2,\n                                    \"PhD\":3,\n                                    \"Bachelor's\":1,\n                                    \"High School\":0}},inplace=True)\ndef smokingToBin(dat):\n    dat['Smoking Status']=(dat['Smoking Status']==\"Yes\")+0\ndef customerToNum(dat):\n    dat.replace({\"Customer Feedback\":{\"Poor\":int(0),\"Average\":int(1),\"Good\":int(2)}},inplace=True)\ndef excerciseToNum(dat):\n    dat.replace({\"Exercise Frequency\":{\"Weekly\": 2,\"Monthly\":1,\"Rarely\": 0,\"Daily\": 3}},inplace=True)\ndef occupationToNum(dat):\n    dat.replace({\"Occupation\":{\"Employed\":1,\"Self-Employed\":2,\"Unemployed\":0}},inplace=True)\ndef locationToNum(dat):\n    dat.replace({\"Location\":{\"Suburban\":1,\"Urban\":2,\"Rural\":0}},inplace=True)\ndef propertyToNum(dat):\n    dat.replace({\"Property Type\":{\"Condo\":1,\"Apartment\":2,\"House\":0}},inplace=True)\ndef policyToNum(dat):\n    dat.replace({\"Property Type\":{\"Condo\":1,\"Apartment\":2,\"House\":0}},inplace=True)\ngenderToBinary(data1)\nmaritalToNum(data1)\neducationToNum(data1)\nsmokingToBin(data1)\ncustomerToNum(data1)\nexcerciseToNum(data1)\noccupationToNum(data1)\nlocationToNum(data1)\npropertyToNum(data1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T08:20:57.771519Z","iopub.execute_input":"2024-12-19T08:20:57.771915Z","iopub.status.idle":"2024-12-19T08:21:01.773154Z","shell.execute_reply.started":"2024-12-19T08:20:57.77188Z","shell.execute_reply":"2024-12-19T08:21:01.772059Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data=data1","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T08:21:11.255065Z","iopub.execute_input":"2024-12-19T08:21:11.25556Z","iopub.status.idle":"2024-12-19T08:21:11.305968Z","shell.execute_reply.started":"2024-12-19T08:21:11.255517Z","shell.execute_reply":"2024-12-19T08:21:11.304619Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#data['Annual Income']=np.log(data['Annual Income']+1)\ndata['Annual Income'].hist()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T22:32:55.334103Z","iopub.execute_input":"2024-12-17T22:32:55.335217Z","iopub.status.idle":"2024-12-17T22:32:55.698264Z","shell.execute_reply.started":"2024-12-17T22:32:55.335159Z","shell.execute_reply":"2024-12-17T22:32:55.697118Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ratio=0.8\n# n=int(ratio*len(data))\n# train=data[:n]\n# val=data[n:]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-16T21:37:10.021084Z","iopub.execute_input":"2024-12-16T21:37:10.021539Z","iopub.status.idle":"2024-12-16T21:37:10.030077Z","shell.execute_reply.started":"2024-12-16T21:37:10.021498Z","shell.execute_reply":"2024-12-16T21:37:10.028678Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"columns=data.columns[data.dtypes!='object']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T08:18:12.190901Z","iopub.execute_input":"2024-12-19T08:18:12.191389Z","iopub.status.idle":"2024-12-19T08:18:12.197671Z","shell.execute_reply.started":"2024-12-19T08:18:12.191351Z","shell.execute_reply":"2024-12-19T08:18:12.196323Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X=data[columns].drop([\"id\", \"Premium Amount\"],axis=1)\ny=data[\"Premium Amount\"]\n# X_val=val[columns].drop([\"id\", \"Premium Amount\"],axis=1)\n# y_val=val[\"Premium Amount\"]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-19T08:18:28.657457Z","iopub.execute_input":"2024-12-19T08:18:28.657897Z","iopub.status.idle":"2024-12-19T08:18:28.736283Z","shell.execute_reply.started":"2024-12-19T08:18:28.657856Z","shell.execute_reply":"2024-12-19T08:18:28.735135Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from xgboost import XGBRegressor\n\nbst = XGBRegressor(n_estimators=120, max_depth=3, learning_rate=.5)\nbst.fit(X,np.log(y))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-16T21:38:53.382154Z","iopub.execute_input":"2024-12-16T21:38:53.383244Z","iopub.status.idle":"2024-12-16T21:39:01.421106Z","shell.execute_reply.started":"2024-12-16T21:38:53.383178Z","shell.execute_reply":"2024-12-16T21:39:01.419595Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test=pd.read_csv(\"/kaggle/input/playground-series-s4e12/test.csv\")\ngenderToBinary(test)\nmaritalToNum(test)\neducationToNum(test)\nsmokingToBin(test)\ncustomerToNum(test)\nexcerciseToNum(test)\noccupationToNum(test)\nlocationToNum(test)\npropertyToNum(test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-16T21:39:32.514299Z","iopub.execute_input":"2024-12-16T21:39:32.514848Z","iopub.status.idle":"2024-12-16T21:39:39.452725Z","shell.execute_reply.started":"2024-12-16T21:39:32.514784Z","shell.execute_reply":"2024-12-16T21:39:39.451282Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_test=test[columns.drop(\"Premium Amount\")].drop([\"id\"],axis=1)\nsubs=pd.DataFrame(np.exp(bst.predict(X_test)),index=test['id'], columns=['Premium Amount'])\nsubs.to_csv(\"submission.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-16T21:39:53.608912Z","iopub.execute_input":"2024-12-16T21:39:53.609342Z","iopub.status.idle":"2024-12-16T21:39:55.66003Z","shell.execute_reply.started":"2024-12-16T21:39:53.609304Z","shell.execute_reply":"2024-12-16T21:39:55.657772Z"}},"outputs":[],"execution_count":null}]}