{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceType":"competition","sourceId":84896,"databundleVersionId":10305135}],"dockerImageVersionId":31287,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Regression with an Insurance","metadata":{}},{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:08.462337Z","iopub.execute_input":"2026-03-08T15:52:08.462601Z","iopub.status.idle":"2026-03-08T15:52:09.545662Z","shell.execute_reply.started":"2026-03-08T15:52:08.462579Z","shell.execute_reply":"2026-03-08T15:52:09.544863Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Business Goal\n\nThe objective of this project is to predict individual medical insurance charges using demographic and lifestyle information such as age, BMI, smoking status, and region. Accurate predictions help insurance companies estimate medical costs and manage risk effectively.","metadata":{}},{"cell_type":"markdown","source":"# Import Libraries","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.ensemble import RandomForestRegressor\nfrom sklearn.metrics import r2_score, mean_squared_error","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:09.54752Z","iopub.execute_input":"2026-03-08T15:52:09.547953Z","iopub.status.idle":"2026-03-08T15:52:11.516524Z","shell.execute_reply.started":"2026-03-08T15:52:09.54793Z","shell.execute_reply":"2026-03-08T15:52:11.515745Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Load Dataset","metadata":{}},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/competitions/playground-series-s4e12/train.csv')\ntest = pd.read_csv('/kaggle/input/competitions/playground-series-s4e12/test.csv')\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:11.517492Z","iopub.execute_input":"2026-03-08T15:52:11.517984Z","iopub.status.idle":"2026-03-08T15:52:18.697966Z","shell.execute_reply.started":"2026-03-08T15:52:11.51795Z","shell.execute_reply":"2026-03-08T15:52:18.69736Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:18.698767Z","iopub.execute_input":"2026-03-08T15:52:18.699016Z","iopub.status.idle":"2026-03-08T15:52:18.704664Z","shell.execute_reply.started":"2026-03-08T15:52:18.698993Z","shell.execute_reply":"2026-03-08T15:52:18.704011Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:18.705612Z","iopub.execute_input":"2026-03-08T15:52:18.706144Z","iopub.status.idle":"2026-03-08T15:52:18.717037Z","shell.execute_reply.started":"2026-03-08T15:52:18.706113Z","shell.execute_reply":"2026-03-08T15:52:18.716326Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# EDA ","metadata":{}},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:18.717985Z","iopub.execute_input":"2026-03-08T15:52:18.718304Z","iopub.status.idle":"2026-03-08T15:52:18.762322Z","shell.execute_reply.started":"2026-03-08T15:52:18.718277Z","shell.execute_reply":"2026-03-08T15:52:18.76163Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:18.764732Z","iopub.execute_input":"2026-03-08T15:52:18.765023Z","iopub.status.idle":"2026-03-08T15:52:18.781468Z","shell.execute_reply.started":"2026-03-08T15:52:18.765003Z","shell.execute_reply":"2026-03-08T15:52:18.780759Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.columns","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:18.783132Z","iopub.execute_input":"2026-03-08T15:52:18.783573Z","iopub.status.idle":"2026-03-08T15:52:18.793301Z","shell.execute_reply.started":"2026-03-08T15:52:18.783552Z","shell.execute_reply":"2026-03-08T15:52:18.792601Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:18.794161Z","iopub.execute_input":"2026-03-08T15:52:18.794476Z","iopub.status.idle":"2026-03-08T15:52:19.41306Z","shell.execute_reply.started":"2026-03-08T15:52:18.794454Z","shell.execute_reply":"2026-03-08T15:52:19.412182Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Missing Values","metadata":{"execution":{"iopub.status.busy":"2026-03-08T14:13:33.121707Z","iopub.execute_input":"2026-03-08T14:13:33.122569Z","iopub.status.idle":"2026-03-08T14:13:33.126588Z","shell.execute_reply.started":"2026-03-08T14:13:33.122535Z","shell.execute_reply":"2026-03-08T14:13:33.12558Z"}}},{"cell_type":"code","source":"train.isnull().sum().sort_values(ascending=False).plot(kind=\"bar\", figsize=(10,4))\nplt.title(\"Missing Values\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:19.414344Z","iopub.execute_input":"2026-03-08T15:52:19.414684Z","iopub.status.idle":"2026-03-08T15:52:20.357873Z","shell.execute_reply.started":"2026-03-08T15:52:19.414634Z","shell.execute_reply":"2026-03-08T15:52:20.357155Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Premium Amount\"].plot(kind=\"hist\", bins=40, figsize=(8,4))\nplt.title(\"Premium Amount Distribution\")\nplt.xlabel(\"Premium Amount\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:20.35874Z","iopub.execute_input":"2026-03-08T15:52:20.359319Z","iopub.status.idle":"2026-03-08T15:52:20.614201Z","shell.execute_reply.started":"2026-03-08T15:52:20.359297Z","shell.execute_reply":"2026-03-08T15:52:20.613548Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Age\"].plot(kind=\"hist\", bins=30, figsize=(8,4))\nplt.title(\"Age Distribution\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:20.615178Z","iopub.execute_input":"2026-03-08T15:52:20.61553Z","iopub.status.idle":"2026-03-08T15:52:20.776245Z","shell.execute_reply.started":"2026-03-08T15:52:20.615506Z","shell.execute_reply":"2026-03-08T15:52:20.77561Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"Annual Income\"].plot(kind=\"hist\", bins=40, figsize=(8,4))\nplt.title(\"Annual Income Distribution\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:20.77717Z","iopub.execute_input":"2026-03-08T15:52:20.777749Z","iopub.status.idle":"2026-03-08T15:52:20.975209Z","shell.execute_reply.started":"2026-03-08T15:52:20.777717Z","shell.execute_reply":"2026-03-08T15:52:20.97452Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.groupby(\"Smoking Status\")[\"Premium Amount\"].mean().plot(kind=\"bar\")\nplt.title(\"Average Premium by Smoking Status\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:20.976258Z","iopub.execute_input":"2026-03-08T15:52:20.976729Z","iopub.status.idle":"2026-03-08T15:52:21.140975Z","shell.execute_reply.started":"2026-03-08T15:52:20.976706Z","shell.execute_reply":"2026-03-08T15:52:21.140152Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.groupby(\"Exercise Frequency\")[\"Premium Amount\"].mean().plot(kind=\"bar\")\nplt.title(\"Premium vs Exercise Frequency\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:21.141973Z","iopub.execute_input":"2026-03-08T15:52:21.142271Z","iopub.status.idle":"2026-03-08T15:52:21.306199Z","shell.execute_reply.started":"2026-03-08T15:52:21.142237Z","shell.execute_reply":"2026-03-08T15:52:21.305507Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.groupby(\"Property Type\")[\"Premium Amount\"].mean().plot(kind=\"bar\")\nplt.title(\"Premium by Property Type\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:21.307111Z","iopub.execute_input":"2026-03-08T15:52:21.307428Z","iopub.status.idle":"2026-03-08T15:52:21.469842Z","shell.execute_reply.started":"2026-03-08T15:52:21.307406Z","shell.execute_reply":"2026-03-08T15:52:21.469043Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Premium Amount varies significantly across different lifestyle factors.\n\nSmoking status appears to increase insurance premiums.\n\nHigher annual income groups tend to have higher premium amounts.\n\nExercise frequency and property type may also influence insurance pricing.","metadata":{}},{"cell_type":"code","source":"import seaborn as sns\nsns.heatmap(train.corr(numeric_only=True),annot=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:21.470857Z","iopub.execute_input":"2026-03-08T15:52:21.471193Z","iopub.status.idle":"2026-03-08T15:52:22.607071Z","shell.execute_reply.started":"2026-03-08T15:52:21.471162Z","shell.execute_reply":"2026-03-08T15:52:22.60623Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Feature Engineering","metadata":{}},{"cell_type":"code","source":"train_len = len(train)\ndf = pd.concat([train, test], axis=0).reset_index(drop=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:22.60806Z","iopub.execute_input":"2026-03-08T15:52:22.608375Z","iopub.status.idle":"2026-03-08T15:52:24.00903Z","shell.execute_reply.started":"2026-03-08T15:52:22.608353Z","shell.execute_reply":"2026-03-08T15:52:24.008186Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:24.010045Z","iopub.execute_input":"2026-03-08T15:52:24.010398Z","iopub.status.idle":"2026-03-08T15:52:24.015585Z","shell.execute_reply.started":"2026-03-08T15:52:24.010376Z","shell.execute_reply":"2026-03-08T15:52:24.014714Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:24.016607Z","iopub.execute_input":"2026-03-08T15:52:24.016923Z","iopub.status.idle":"2026-03-08T15:52:24.041606Z","shell.execute_reply.started":"2026-03-08T15:52:24.016903Z","shell.execute_reply":"2026-03-08T15:52:24.040853Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df[\"Policy Start Date\"] = pd.to_datetime(df[\"Policy Start Date\"])\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:24.042527Z","iopub.execute_input":"2026-03-08T15:52:24.042952Z","iopub.status.idle":"2026-03-08T15:52:24.512156Z","shell.execute_reply.started":"2026-03-08T15:52:24.042931Z","shell.execute_reply":"2026-03-08T15:52:24.511349Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df[\"policy_month\"] = df[\"Policy Start Date\"].dt.month\ndf[\"policy_day\"] = df[\"Policy Start Date\"].dt.day","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:24.515308Z","iopub.execute_input":"2026-03-08T15:52:24.515513Z","iopub.status.idle":"2026-03-08T15:52:24.676779Z","shell.execute_reply.started":"2026-03-08T15:52:24.515495Z","shell.execute_reply":"2026-03-08T15:52:24.676005Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.drop(columns=[\"Policy Start Date\"], inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:24.677652Z","iopub.execute_input":"2026-03-08T15:52:24.678036Z","iopub.status.idle":"2026-03-08T15:52:24.961452Z","shell.execute_reply.started":"2026-03-08T15:52:24.678011Z","shell.execute_reply":"2026-03-08T15:52:24.960852Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df[\"income_per_age\"] = df[\"Annual Income\"] / (df[\"Age\"] + 1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:24.962436Z","iopub.execute_input":"2026-03-08T15:52:24.962741Z","iopub.status.idle":"2026-03-08T15:52:24.975846Z","shell.execute_reply.started":"2026-03-08T15:52:24.962708Z","shell.execute_reply":"2026-03-08T15:52:24.975085Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df[\"claims_per_duration\"] = df[\"Previous Claims\"] / (df[\"Insurance Duration\"] + 1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:24.976818Z","iopub.execute_input":"2026-03-08T15:52:24.977104Z","iopub.status.idle":"2026-03-08T15:52:24.991088Z","shell.execute_reply.started":"2026-03-08T15:52:24.977084Z","shell.execute_reply":"2026-03-08T15:52:24.990316Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df[\"health_risk\"] = df[\"Health Score\"] * df[\"Smoking Status\"].map({\"Yes\":2,\"No\":1})","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:24.992084Z","iopub.execute_input":"2026-03-08T15:52:24.992383Z","iopub.status.idle":"2026-03-08T15:52:25.102473Z","shell.execute_reply.started":"2026-03-08T15:52:24.992363Z","shell.execute_reply":"2026-03-08T15:52:25.101922Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df = df.fillna(0)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:25.103361Z","iopub.execute_input":"2026-03-08T15:52:25.103628Z","iopub.status.idle":"2026-03-08T15:52:26.901069Z","shell.execute_reply.started":"2026-03-08T15:52:25.1036Z","shell.execute_reply":"2026-03-08T15:52:26.900217Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df = pd.get_dummies(df)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:26.902266Z","iopub.execute_input":"2026-03-08T15:52:26.902851Z","iopub.status.idle":"2026-03-08T15:52:29.24599Z","shell.execute_reply.started":"2026-03-08T15:52:26.902813Z","shell.execute_reply":"2026-03-08T15:52:29.245332Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Train/Test Split","metadata":{}},{"cell_type":"code","source":"train_final = df.iloc[:train_len].copy()\ntest_final = df.iloc[train_len:].copy()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:29.246895Z","iopub.execute_input":"2026-03-08T15:52:29.247275Z","iopub.status.idle":"2026-03-08T15:52:29.368735Z","shell.execute_reply.started":"2026-03-08T15:52:29.24724Z","shell.execute_reply":"2026-03-08T15:52:29.36787Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y = train_final[\"Premium Amount\"]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:29.370046Z","iopub.execute_input":"2026-03-08T15:52:29.370347Z","iopub.status.idle":"2026-03-08T15:52:29.374676Z","shell.execute_reply.started":"2026-03-08T15:52:29.370318Z","shell.execute_reply":"2026-03-08T15:52:29.373994Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"x = train_final.drop(columns=[\"Premium Amount\"])\nx_test = test_final.drop(columns=[\"Premium Amount\"], errors=\"ignore\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:29.375524Z","iopub.execute_input":"2026-03-08T15:52:29.375891Z","iopub.status.idle":"2026-03-08T15:52:29.475419Z","shell.execute_reply.started":"2026-03-08T15:52:29.375862Z","shell.execute_reply":"2026-03-08T15:52:29.474769Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\nx_train, x_val, y_train, y_val = train_test_split(x, y,test_size=0.2,random_state=42)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:29.476299Z","iopub.execute_input":"2026-03-08T15:52:29.476654Z","iopub.status.idle":"2026-03-08T15:52:29.784519Z","shell.execute_reply.started":"2026-03-08T15:52:29.47663Z","shell.execute_reply":"2026-03-08T15:52:29.783383Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Model","metadata":{}},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestRegressor","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:29.785658Z","iopub.execute_input":"2026-03-08T15:52:29.786078Z","iopub.status.idle":"2026-03-08T15:52:29.790512Z","shell.execute_reply.started":"2026-03-08T15:52:29.786051Z","shell.execute_reply":"2026-03-08T15:52:29.789699Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model = RandomForestRegressor(n_estimators=300,random_state=42,n_jobs=-1)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:29.79186Z","iopub.execute_input":"2026-03-08T15:52:29.792416Z","iopub.status.idle":"2026-03-08T15:52:29.805762Z","shell.execute_reply.started":"2026-03-08T15:52:29.79239Z","shell.execute_reply":"2026-03-08T15:52:29.804972Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.fit(x_train, y_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T15:52:29.807083Z","iopub.execute_input":"2026-03-08T15:52:29.807542Z","iopub.status.idle":"2026-03-08T16:50:56.870386Z","shell.execute_reply.started":"2026-03-08T15:52:29.80752Z","shell.execute_reply":"2026-03-08T16:50:56.869683Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Validation Prediction","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T16:50:56.871343Z","iopub.execute_input":"2026-03-08T16:50:56.871633Z","iopub.status.idle":"2026-03-08T16:50:56.875004Z","shell.execute_reply.started":"2026-03-08T16:50:56.871611Z","shell.execute_reply":"2026-03-08T16:50:56.8743Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val_pred = model.predict(x_val)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T16:50:56.875879Z","iopub.execute_input":"2026-03-08T16:50:56.87626Z","iopub.status.idle":"2026-03-08T16:51:15.040946Z","shell.execute_reply.started":"2026-03-08T16:50:56.876238Z","shell.execute_reply":"2026-03-08T16:51:15.040041Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.metrics import r2_score, mean_squared_error, mean_absolute_error","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T16:51:15.042845Z","iopub.execute_input":"2026-03-08T16:51:15.043319Z","iopub.status.idle":"2026-03-08T16:51:15.046629Z","shell.execute_reply.started":"2026-03-08T16:51:15.043296Z","shell.execute_reply":"2026-03-08T16:51:15.046045Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"r2 = r2_score(y_val, val_pred)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T16:51:15.047505Z","iopub.execute_input":"2026-03-08T16:51:15.047782Z","iopub.status.idle":"2026-03-08T16:51:15.070728Z","shell.execute_reply.started":"2026-03-08T16:51:15.047762Z","shell.execute_reply":"2026-03-08T16:51:15.070019Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"mean_squared_error(y_val, val_pred)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T17:29:37.030185Z","iopub.execute_input":"2026-03-08T17:29:37.030978Z","iopub.status.idle":"2026-03-08T17:29:37.038542Z","shell.execute_reply.started":"2026-03-08T17:29:37.030935Z","shell.execute_reply":"2026-03-08T17:29:37.038023Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# feature ımportance","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport matplotlib.pyplot as plt\n\nimportance = pd.Series(model.feature_importances_, index=x.columns)\n\nimportance.sort_values(ascending=False).head(15).plot(\n    kind=\"bar\",\n    figsize=(10,4)\n)\n\nplt.title(\"Top Feature Importances\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T17:29:56.308263Z","iopub.execute_input":"2026-03-08T17:29:56.309014Z","iopub.status.idle":"2026-03-08T17:29:57.981332Z","shell.execute_reply.started":"2026-03-08T17:29:56.308986Z","shell.execute_reply":"2026-03-08T17:29:57.980657Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# test prediction","metadata":{}},{"cell_type":"code","source":"test_pred = model.predict(x_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T17:30:05.493318Z","iopub.execute_input":"2026-03-08T17:30:05.494065Z","iopub.status.idle":"2026-03-08T17:30:46.74142Z","shell.execute_reply.started":"2026-03-08T17:30:05.494035Z","shell.execute_reply":"2026-03-08T17:30:46.740483Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission = pd.DataFrame({\n    \"id\": test[\"id\"],\n    \"Premium Amount\": test_pred\n})\n\nsubmission.to_csv(\"submission.csv\", index=False)\n\nsubmission.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T17:30:46.742844Z","iopub.execute_input":"2026-03-08T17:30:46.743162Z","iopub.status.idle":"2026-03-08T17:30:48.069982Z","shell.execute_reply.started":"2026-03-08T17:30:46.74314Z","shell.execute_reply":"2026-03-08T17:30:48.069358Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\n\nprint(os.listdir())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-03-08T17:30:48.070829Z","iopub.execute_input":"2026-03-08T17:30:48.071167Z","iopub.status.idle":"2026-03-08T17:30:48.075322Z","shell.execute_reply.started":"2026-03-08T17:30:48.071143Z","shell.execute_reply":"2026-03-08T17:30:48.074737Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}