{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"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":30839,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false},"colab":{"provenance":[],"name":"Regression - Insurance Dataset"},"widgets":{"application/vnd.jupyter.widget-state+json":{"98965d7b02e64c66b598955efd914624":{"model_module":"@jupyter-widgets/controls","model_name":"VBoxModel","model_module_version":"1.5.0","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"VBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"VBoxView","box_style":"","children":["IPY_MODEL_7f05cb19500a476ca62b8a86ffff7058"],"layout":"IPY_MODEL_7ce2019da3984b3e9545b4425e253e31"}},"eacea166970a40208d454642ef6b1e97":{"model_module":"@jupyter-widgets/controls","model_name":"HTMLModel","model_module_version":"1.5.0","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HTMLView","description":"","description_tooltip":null,"layout":"IPY_MODEL_f694e70f282941a6ae87780f9d5c1836","placeholder":"​","style":"IPY_MODEL_0cd54ddd511240af9b1f9316f20d79ba","value":"<center> <img\nsrc=https://www.kaggle.com/static/images/site-logo.png\nalt='Kaggle'> <br> Create an API token from <a\nhref=\"https://www.kaggle.com/settings/account\" target=\"_blank\">your Kaggle\nsettings page</a> and paste it below along with your Kaggle username. <br> </center>"}},"87ff16cc679745b3aace0de79b4c5f9b":{"model_module":"@jupyter-widgets/controls","model_name":"TextModel","model_module_version":"1.5.0","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"TextModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"TextView","continuous_update":true,"description":"Username:","description_tooltip":null,"disabled":false,"layout":"IPY_MODEL_67630f452ed145e39262d43a8dc8ed1a","placeholder":"​","style":"IPY_MODEL_e82977927c85459ca5a059e500f5da7c","value":"eslam200"}},"4595a1d6e4b6417d9a4d99451d253e56":{"model_module":"@jupyter-widgets/controls","model_name":"PasswordModel","model_module_version":"1.5.0","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"PasswordModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"PasswordView","continuous_update":true,"description":"Token:","description_tooltip":null,"disabled":false,"layout":"IPY_MODEL_c760f3eca36e4841adeedbe47faf6479","placeholder":"​","style":"IPY_MODEL_5baaf2b5712449e0a9c8a42edf7420bf","value":""}},"355bd93e6f6049a9a5bffd925da76a39":{"model_module":"@jupyter-widgets/controls","model_name":"ButtonModel","model_module_version":"1.5.0","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"ButtonModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"ButtonView","button_style":"","description":"Login","disabled":false,"icon":"","layout":"IPY_MODEL_5a2d9c41de6c447193243ab1ba9bdfd8","style":"IPY_MODEL_c4de81c16065457ea8df5cb3363f8b7d","tooltip":""}},"71454ff509614b929eca9d622251d6ce":{"model_module":"@jupyter-widgets/controls","model_name":"HTMLModel","model_module_version":"1.5.0","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HTMLView","description":"","description_tooltip":null,"layout":"IPY_MODEL_710d6795f1f74b6cafe235c2f7376541","placeholder":"​","style":"IPY_MODEL_13197bf809e24c058fc6393fc2d706a9","value":"\n<b>Thank You</b></center>"}},"7ce2019da3984b3e9545b4425e253e31":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":"center","align_self":null,"border":null,"bottom":null,"display":"flex","flex":null,"flex_flow":"column","grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":"50%"}},"f694e70f282941a6ae87780f9d5c1836":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"0cd54ddd511240af9b1f9316f20d79ba":{"model_module":"@jupyter-widgets/controls","model_name":"DescriptionStyleModel","model_module_version":"1.5.0","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"67630f452ed145e39262d43a8dc8ed1a":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"e82977927c85459ca5a059e500f5da7c":{"model_module":"@jupyter-widgets/controls","model_name":"DescriptionStyleModel","model_module_version":"1.5.0","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"c760f3eca36e4841adeedbe47faf6479":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"5baaf2b5712449e0a9c8a42edf7420bf":{"model_module":"@jupyter-widgets/controls","model_name":"DescriptionStyleModel","model_module_version":"1.5.0","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"5a2d9c41de6c447193243ab1ba9bdfd8":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"c4de81c16065457ea8df5cb3363f8b7d":{"model_module":"@jupyter-widgets/controls","model_name":"ButtonStyleModel","model_module_version":"1.5.0","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"ButtonStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","button_color":null,"font_weight":""}},"710d6795f1f74b6cafe235c2f7376541":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"13197bf809e24c058fc6393fc2d706a9":{"model_module":"@jupyter-widgets/controls","model_name":"DescriptionStyleModel","model_module_version":"1.5.0","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"c584e5caf8af440ea0543c4e347b73b6":{"model_module":"@jupyter-widgets/controls","model_name":"LabelModel","model_module_version":"1.5.0","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"LabelModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"LabelView","description":"","description_tooltip":null,"layout":"IPY_MODEL_58eb836bede644debb4685051761be9e","placeholder":"​","style":"IPY_MODEL_c01368fc2d024688afd72e20bd4c26c9","value":"Connecting..."}},"58eb836bede644debb4685051761be9e":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"c01368fc2d024688afd72e20bd4c26c9":{"model_module":"@jupyter-widgets/controls","model_name":"DescriptionStyleModel","model_module_version":"1.5.0","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"7f05cb19500a476ca62b8a86ffff7058":{"model_module":"@jupyter-widgets/controls","model_name":"LabelModel","model_module_version":"1.5.0","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"LabelModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"LabelView","description":"","description_tooltip":null,"layout":"IPY_MODEL_8920ec6ac4a649b286cda72725d16a15","placeholder":"​","style":"IPY_MODEL_4b5f5d200c35436c82f2e56d61ddc1ab","value":"Kaggle credentials successfully validated."}},"8920ec6ac4a649b286cda72725d16a15":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"4b5f5d200c35436c82f2e56d61ddc1ab":{"model_module":"@jupyter-widgets/controls","model_name":"DescriptionStyleModel","model_module_version":"1.5.0","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}}}}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# train_path = playground_series_s4e12_path + '/train.csv'\n# test_path = playground_series_s4e12_path + '/test.csv'\n# submission_path = playground_series_s4e12_path + '/sample_submission.csv'\n\ntrain_path = \"/kaggle/input/playground-series-s4e12/train.csv\"\ntest_path = \"/kaggle/input/playground-series-s4e12/test.csv\"\nsubmission_path = \"/kaggle/input/playground-series-s4e12/sample_submission.csv\"","metadata":{"id":"SEPCc8AymKp7","trusted":true,"execution":{"iopub.status.busy":"2025-01-28T02:41:14.547027Z","iopub.execute_input":"2025-01-28T02:41:14.547331Z","iopub.status.idle":"2025-01-28T02:41:14.55156Z","shell.execute_reply.started":"2025-01-28T02:41:14.547308Z","shell.execute_reply":"2025-01-28T02:41:14.550659Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# %%capture\n# !pip install category_encoders","metadata":{"id":"YvumrGInm3Wu","trusted":true,"execution":{"iopub.status.busy":"2025-01-28T02:41:14.807047Z","iopub.execute_input":"2025-01-28T02:41:14.807357Z","iopub.status.idle":"2025-01-28T02:41:14.811Z","shell.execute_reply.started":"2025-01-28T02:41:14.807333Z","shell.execute_reply":"2025-01-28T02:41:14.80998Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\n\n# Visualization\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nimport plotly.express as px\n\n# Models\nfrom sklearn.linear_model import LinearRegression, Ridge\nfrom category_encoders import OneHotEncoder\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.pipeline import make_pipeline\nfrom sklearn.impute import SimpleImputer","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-28T02:41:15.064816Z","iopub.execute_input":"2025-01-28T02:41:15.065107Z","iopub.status.idle":"2025-01-28T02:41:17.688352Z","shell.execute_reply.started":"2025-01-28T02:41:15.065084Z","shell.execute_reply":"2025-01-28T02:41:17.68758Z"},"id":"5xkKbHXZlp1o"},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Imports","metadata":{"id":"VYqSd6Qz3YTj"}},{"cell_type":"code","source":"df = pd.read_csv(train_path, index_col=\"id\")\ndf.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-28T02:41:17.689502Z","iopub.execute_input":"2025-01-28T02:41:17.690018Z","iopub.status.idle":"2025-01-28T02:41:23.094805Z","shell.execute_reply.started":"2025-01-28T02:41:17.689987Z","shell.execute_reply":"2025-01-28T02:41:23.093866Z"},"id":"qMZIQNyKlp1o","outputId":"ef027071-8c7d-4b99-e9ba-096d24811f0a"},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.info()","metadata":{"trusted":true,"id":"l4Wo-5Tqlp1p","outputId":"31b03552-2b99-452e-83b0-cd70d96a1447","execution":{"iopub.status.busy":"2025-01-28T02:41:23.096436Z","iopub.execute_input":"2025-01-28T02:41:23.09665Z","iopub.status.idle":"2025-01-28T02:41:23.728463Z","shell.execute_reply.started":"2025-01-28T02:41:23.096632Z","shell.execute_reply":"2025-01-28T02:41:23.727603Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.describe()","metadata":{"trusted":true,"id":"nx3hMLFalp1p","outputId":"adde10bf-ca2e-4d46-e0eb-37f473c3fef7","execution":{"iopub.status.busy":"2025-01-28T02:41:23.729871Z","iopub.execute_input":"2025-01-28T02:41:23.730111Z","iopub.status.idle":"2025-01-28T02:41:24.265284Z","shell.execute_reply.started":"2025-01-28T02:41:23.73009Z","shell.execute_reply":"2025-01-28T02:41:24.264448Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"(df.isna().sum() / len(df)).sort_values(ascending=False) * 100","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-28T02:41:24.26623Z","iopub.execute_input":"2025-01-28T02:41:24.266532Z","iopub.status.idle":"2025-01-28T02:41:24.889733Z","shell.execute_reply.started":"2025-01-28T02:41:24.266501Z","shell.execute_reply":"2025-01-28T02:41:24.88867Z"},"id":"C6s1ECBRlp1q","outputId":"49ec3b3b-f5e8-4352-85a7-79962f7eab19"},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Exploratory Data Analysis","metadata":{"id":"RHCYb9xmlp1q"}},{"cell_type":"code","source":"fig = px.histogram(\n    df,\n    x=\"Age\",\n    marginal=\"box\",\n    nbins=50,\n    title=\"Distribution of Age\")\nfig.update_layout(bargap=0.1)\nfig.show()","metadata":{"trusted":true,"execution":{"execution_failed":"2025-01-28T02:35:41.945Z"},"id":"If40J8ePlp1s"},"outputs":[],"execution_count":null},{"cell_type":"code","source":"fig = px.histogram(\n    df,\n    x=\"Annual Income\",\n    marginal=\"box\",\n    color=\"Gender\",\n    nbins=50,\n    title=\"Distribution of Annual Income\"\n)\nfig.update_layout(bargap=0.1)\nfig.show()","metadata":{"trusted":true,"execution":{"execution_failed":"2025-01-28T02:35:41.945Z"},"id":"pF4tLo5Hlp1s"},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df[\"Credit Score\"].plot(kind=\"box\", vert=False)","metadata":{"trusted":true,"execution":{"execution_failed":"2025-01-28T02:35:41.945Z"},"id":"y8eJ9iOslp1t"},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df[\"Smoking Status\"].value_counts()","metadata":{"trusted":true,"execution":{"execution_failed":"2025-01-28T02:35:41.945Z"},"id":"KE2EbfZslp1t"},"outputs":[],"execution_count":null},{"cell_type":"code","source":"px.histogram(\n    df.sample(10000),\n    x=\"Annual Income\",\n    color=\"Smoking Status\",\n    title=\"\"\n)","metadata":{"trusted":true,"execution":{"execution_failed":"2025-01-28T02:35:41.945Z"},"id":"Aw_TJJRHlp1t"},"outputs":[],"execution_count":null},{"cell_type":"code","source":"fig = px.scatter(\n    df.sample(2000),\n    x=\"Health Score\",\n    y=\"Annual Income\"\n)\nfig.show()","metadata":{"trusted":true,"execution":{"execution_failed":"2025-01-28T02:35:41.945Z"},"id":"1CUdj5q4lp1u"},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sns.heatmap(df.select_dtypes(\"number\").corr())\nplt.title(\"Correlation Matrix\")","metadata":{"trusted":true,"execution":{"execution_failed":"2025-01-28T02:35:41.945Z"},"id":"PZe5fg60lp1u"},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Preparing Data","metadata":{"id":"EOEEa-yflp1u"}},{"cell_type":"code","source":"df.head(1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-28T02:41:24.890826Z","iopub.execute_input":"2025-01-28T02:41:24.89115Z","iopub.status.idle":"2025-01-28T02:41:24.907629Z","shell.execute_reply.started":"2025-01-28T02:41:24.891127Z","shell.execute_reply":"2025-01-28T02:41:24.906955Z"},"id":"VU1S9VPAlp1u","outputId":"43d39aea-5202-43a9-f41d-0a5e7655d2a4"},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def wrangle(filepath):\n  df = pd.read_csv(filepath, index_col=\"id\")\n  df.drop(columns=[\"Policy Start Date\", \"Previous Claims\", \"Occupation\"], inplace=True)\n  return df\n\ndf = wrangle(train_path)","metadata":{"id":"JGNz_4CHl_xA","trusted":true,"execution":{"iopub.status.busy":"2025-01-28T02:41:24.908659Z","iopub.execute_input":"2025-01-28T02:41:24.909022Z","iopub.status.idle":"2025-01-28T02:41:29.361661Z","shell.execute_reply.started":"2025-01-28T02:41:24.908987Z","shell.execute_reply":"2025-01-28T02:41:29.360868Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"target = \"Premium Amount\"\nX = df.drop(columns=target)\ny = df[target]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-28T02:41:29.364512Z","iopub.execute_input":"2025-01-28T02:41:29.364784Z","iopub.status.idle":"2025-01-28T02:41:29.409843Z","shell.execute_reply.started":"2025-01-28T02:41:29.364757Z","shell.execute_reply":"2025-01-28T02:41:29.408905Z"},"id":"x46B8278lp1v"},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Creating the model","metadata":{"id":"IErRIpONlp1v"}},{"cell_type":"markdown","source":"$$RMSE = \\sqrt{\\dfrac{\\sum^N_{i=1}({Pred_i - Actual_i})^2}{N}}$$","metadata":{"id":"fHD0cjnolp1v"}},{"cell_type":"code","source":"def rmse(targets, predictions):\n    return np.sqrt(np.mean((targets - predictions) ** 2))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-28T02:41:29.410897Z","iopub.execute_input":"2025-01-28T02:41:29.411135Z","iopub.status.idle":"2025-01-28T02:41:29.415542Z","shell.execute_reply.started":"2025-01-28T02:41:29.411114Z","shell.execute_reply":"2025-01-28T02:41:29.414432Z"},"id":"rSHDGPVClp1v"},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model = make_pipeline(\n    OneHotEncoder(use_cat_names=True),\n    SimpleImputer(),\n    LinearRegression()\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-28T02:41:29.4165Z","iopub.execute_input":"2025-01-28T02:41:29.416842Z","iopub.status.idle":"2025-01-28T02:41:29.426759Z","shell.execute_reply.started":"2025-01-28T02:41:29.416812Z","shell.execute_reply":"2025-01-28T02:41:29.425806Z"},"id":"T9BloqARlp1v"},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.fit(X, y)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-28T02:41:29.427648Z","iopub.execute_input":"2025-01-28T02:41:29.427916Z","iopub.status.idle":"2025-01-28T02:41:37.971584Z","shell.execute_reply.started":"2025-01-28T02:41:29.427895Z","shell.execute_reply":"2025-01-28T02:41:37.970802Z"},"id":"Xv0MCno6lp1v","outputId":"34838105-471a-4f47-a7a2-2e6c1747afba"},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.score(X, y)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-28T02:41:37.972367Z","iopub.execute_input":"2025-01-28T02:41:37.972634Z","iopub.status.idle":"2025-01-28T02:41:40.756733Z","shell.execute_reply.started":"2025-01-28T02:41:37.9726Z","shell.execute_reply":"2025-01-28T02:41:40.755818Z"},"id":"80LDo79plp1v","outputId":"929ec90b-686a-4bdb-c9fa-1c0acc4ac6c1"},"outputs":[],"execution_count":null},{"cell_type":"code","source":"rmse(y, model.predict(X))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-28T02:41:40.757658Z","iopub.execute_input":"2025-01-28T02:41:40.75793Z","iopub.status.idle":"2025-01-28T02:41:43.545821Z","shell.execute_reply.started":"2025-01-28T02:41:40.757909Z","shell.execute_reply":"2025-01-28T02:41:43.544778Z"},"id":"FNztHihjlp1v","outputId":"6e468880-f007-47a2-e45b-0eaf58425450"},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Testing and Evaluating","metadata":{"id":"OEhoh9CQlp1w"}},{"cell_type":"code","source":"test_df = wrangle(test_path)\ntest_df.info()","metadata":{"trusted":true,"id":"iRs5kr40lp1w","outputId":"1ea252c9-04d8-40ea-efe3-054fd41d5ff7","execution":{"iopub.status.busy":"2025-01-28T02:57:45.335069Z","iopub.execute_input":"2025-01-28T02:57:45.335347Z","iopub.status.idle":"2025-01-28T02:57:48.01162Z","shell.execute_reply.started":"2025-01-28T02:57:45.335325Z","shell.execute_reply":"2025-01-28T02:57:48.010651Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_pred = pd.DataFrame(model.predict(test_df), index=test_df.index, columns=[\"Premium Amount\"])\ntest_pred.info()","metadata":{"id":"y4he4UFTpDuO","trusted":true,"execution":{"iopub.status.busy":"2025-01-28T02:58:25.564883Z","iopub.execute_input":"2025-01-28T02:58:25.565319Z","iopub.status.idle":"2025-01-28T02:58:25.677061Z","shell.execute_reply.started":"2025-01-28T02:58:25.565283Z","shell.execute_reply":"2025-01-28T02:58:25.675795Z"},"outputId":"3c602c9f-91c8-4de2-f0e5-afc69b4e0355"},"outputs":[],"execution_count":null},{"cell_type":"code","source":"subm = pd.read_csv(submission_path, index_col=\"id\")\nsubm.info()","metadata":{"id":"ff5mETZroKKh","outputId":"109703f2-e9b3-4779-db9d-1232782beafa","trusted":true,"execution":{"iopub.status.busy":"2025-01-28T02:56:34.769299Z","iopub.execute_input":"2025-01-28T02:56:34.769601Z","iopub.status.idle":"2025-01-28T02:56:34.934959Z","shell.execute_reply.started":"2025-01-28T02:56:34.769578Z","shell.execute_reply":"2025-01-28T02:56:34.934188Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"rmse(subm[\"Premium Amount\"], test_pred[\"Premium Amount\"])","metadata":{"id":"7dlH7KG3oWbo","outputId":"ccadb3e4-0e74-40fd-e93e-39b92545c55f","trusted":true,"execution":{"iopub.status.busy":"2025-01-28T02:55:42.658784Z","iopub.execute_input":"2025-01-28T02:55:42.659112Z","iopub.status.idle":"2025-01-28T02:55:42.69792Z","shell.execute_reply.started":"2025-01-28T02:55:42.659088Z","shell.execute_reply":"2025-01-28T02:55:42.697135Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_pred.rename({\"Premium Amount Pred\": \"Premium Amount\"})[[\"Premium Amount\"]].to_csv(\"submission.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-28T02:53:16.774382Z","iopub.execute_input":"2025-01-28T02:53:16.774758Z","iopub.status.idle":"2025-01-28T02:53:17.65421Z","shell.execute_reply.started":"2025-01-28T02:53:16.774692Z","shell.execute_reply":"2025-01-28T02:53:17.653196Z"},"id":"IEdDKp4z29AQ"},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!kaggle competitions submit -c playground-series-s4e12 -f submission.csv -m \"Message\"","metadata":{"id":"lDixw-fb4WHb"},"outputs":[],"execution_count":null}]}