{"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":"# 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":"2024-12-21T09:21:53.017131Z","iopub.execute_input":"2024-12-21T09:21:53.017592Z","iopub.status.idle":"2024-12-21T09:21:53.408484Z","shell.execute_reply.started":"2024-12-21T09:21:53.017554Z","shell.execute_reply":"2024-12-21T09:21:53.407361Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# 1-Import Necessary Libraries","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import mean_squared_log_error\nfrom sklearn.impute import SimpleImputer\nfrom sklearn.preprocessing import LabelEncoder,StandardScaler,MinMaxScaler,OrdinalEncoder,OneHotEncoder\nfrom sklearn.pipeline import Pipeline\nfrom sklearn.compose import ColumnTransformer\n\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:21:53.41086Z","iopub.execute_input":"2024-12-21T09:21:53.411492Z","iopub.status.idle":"2024-12-21T09:21:54.686379Z","shell.execute_reply.started":"2024-12-21T09:21:53.411443Z","shell.execute_reply":"2024-12-21T09:21:54.685484Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df=pd.read_csv('/kaggle/input/playground-series-s4e12/train.csv')\ntest=pd.read_csv('/kaggle/input/playground-series-s4e12/test.csv')\ndf.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:21:54.687648Z","iopub.execute_input":"2024-12-21T09:21:54.688088Z","iopub.status.idle":"2024-12-21T09:22:05.126135Z","shell.execute_reply.started":"2024-12-21T09:21:54.688057Z","shell.execute_reply":"2024-12-21T09:22:05.125076Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:05.127888Z","iopub.execute_input":"2024-12-21T09:22:05.128246Z","iopub.status.idle":"2024-12-21T09:22:05.13424Z","shell.execute_reply.started":"2024-12-21T09:22:05.128175Z","shell.execute_reply":"2024-12-21T09:22:05.133249Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# 2-Data Cleaning","metadata":{}},{"cell_type":"code","source":"df.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:05.13679Z","iopub.execute_input":"2024-12-21T09:22:05.137104Z","iopub.status.idle":"2024-12-21T09:22:05.83508Z","shell.execute_reply.started":"2024-12-21T09:22:05.137073Z","shell.execute_reply":"2024-12-21T09:22:05.833876Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:05.836328Z","iopub.execute_input":"2024-12-21T09:22:05.836661Z","iopub.status.idle":"2024-12-21T09:22:06.489384Z","shell.execute_reply.started":"2024-12-21T09:22:05.836629Z","shell.execute_reply":"2024-12-21T09:22:06.488263Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.duplicated().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:06.49066Z","iopub.execute_input":"2024-12-21T09:22:06.490997Z","iopub.status.idle":"2024-12-21T09:22:08.443809Z","shell.execute_reply.started":"2024-12-21T09:22:06.490967Z","shell.execute_reply":"2024-12-21T09:22:08.44244Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df['Parsed_Date']=pd.to_datetime(df['Policy Start Date'],format='ISO8601')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:08.445018Z","iopub.execute_input":"2024-12-21T09:22:08.445392Z","iopub.status.idle":"2024-12-21T09:22:08.76148Z","shell.execute_reply.started":"2024-12-21T09:22:08.445343Z","shell.execute_reply":"2024-12-21T09:22:08.760434Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df['Parsed_Date']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:08.762873Z","iopub.execute_input":"2024-12-21T09:22:08.763219Z","iopub.status.idle":"2024-12-21T09:22:08.77437Z","shell.execute_reply.started":"2024-12-21T09:22:08.763161Z","shell.execute_reply":"2024-12-21T09:22:08.773335Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Extract meaningful date components\ndf['Year'] = df['Parsed_Date'].dt.year\ndf['Month'] = df['Parsed_Date'].dt.month\ndf['Day'] = df['Parsed_Date'].dt.day\n#df['Day of Week'] = df['Parsed_Date'].dt.dayofweek  # 0=Monday, 6=Sunday\n#df['Is Weekend'] = df['Day of Week'].apply(lambda x: 1 if x >= 5 else 0)\ndf['Quarter'] = df['Parsed_Date'].dt.quarter","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:08.775904Z","iopub.execute_input":"2024-12-21T09:22:08.776367Z","iopub.status.idle":"2024-12-21T09:22:09.023776Z","shell.execute_reply.started":"2024-12-21T09:22:08.776321Z","shell.execute_reply":"2024-12-21T09:22:09.022801Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:09.02515Z","iopub.execute_input":"2024-12-21T09:22:09.025608Z","iopub.status.idle":"2024-12-21T09:22:09.053348Z","shell.execute_reply.started":"2024-12-21T09:22:09.025565Z","shell.execute_reply":"2024-12-21T09:22:09.05197Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:09.054848Z","iopub.execute_input":"2024-12-21T09:22:09.055177Z","iopub.status.idle":"2024-12-21T09:22:09.735253Z","shell.execute_reply.started":"2024-12-21T09:22:09.055146Z","shell.execute_reply":"2024-12-21T09:22:09.734142Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# 2_EDA","metadata":{}},{"cell_type":"code","source":"df1=df.drop(['Policy Start Date','Parsed_Date'],axis=1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:09.736564Z","iopub.execute_input":"2024-12-21T09:22:09.736895Z","iopub.status.idle":"2024-12-21T09:22:09.909731Z","shell.execute_reply.started":"2024-12-21T09:22:09.736862Z","shell.execute_reply":"2024-12-21T09:22:09.908761Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"numerical=[i for i in df1.columns if df1[i].dtype in ['int64','float64','int32'] ]\ncategorical=[j for j in df1.columns if df1[j].dtype == 'object']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:09.913476Z","iopub.execute_input":"2024-12-21T09:22:09.913824Z","iopub.status.idle":"2024-12-21T09:22:09.923446Z","shell.execute_reply.started":"2024-12-21T09:22:09.913791Z","shell.execute_reply":"2024-12-21T09:22:09.922292Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"correlation=df1[numerical].corr()['Premium Amount']\ncorrelation","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:09.924818Z","iopub.execute_input":"2024-12-21T09:22:09.925269Z","iopub.status.idle":"2024-12-21T09:22:10.772529Z","shell.execute_reply.started":"2024-12-21T09:22:09.925225Z","shell.execute_reply":"2024-12-21T09:22:10.771108Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(15,15))\nsns.heatmap(df1[numerical].corr(),annot=True)\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:10.774102Z","iopub.execute_input":"2024-12-21T09:22:10.774478Z","iopub.status.idle":"2024-12-21T09:22:12.577735Z","shell.execute_reply.started":"2024-12-21T09:22:10.774444Z","shell.execute_reply":"2024-12-21T09:22:12.576506Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#drop features with ~0 correlation\n#df2=df1.drop(['id','Age','Number of Dependents','Vehicle Age','Insurance Duration'],axis=1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:12.579042Z","iopub.execute_input":"2024-12-21T09:22:12.579402Z","iopub.status.idle":"2024-12-21T09:22:12.583971Z","shell.execute_reply.started":"2024-12-21T09:22:12.579368Z","shell.execute_reply":"2024-12-21T09:22:12.582814Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#df2.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:12.585296Z","iopub.execute_input":"2024-12-21T09:22:12.585613Z","iopub.status.idle":"2024-12-21T09:22:12.596651Z","shell.execute_reply.started":"2024-12-21T09:22:12.585583Z","shell.execute_reply":"2024-12-21T09:22:12.595589Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X=df1.drop(['id','Premium Amount'],axis=1)\ny=df['Premium Amount']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:12.597813Z","iopub.execute_input":"2024-12-21T09:22:12.5981Z","iopub.status.idle":"2024-12-21T09:22:12.770964Z","shell.execute_reply.started":"2024-12-21T09:22:12.598072Z","shell.execute_reply":"2024-12-21T09:22:12.770023Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# 3-Data Preprocessing","metadata":{}},{"cell_type":"code","source":"X.columns","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:12.772306Z","iopub.execute_input":"2024-12-21T09:22:12.772718Z","iopub.status.idle":"2024-12-21T09:22:12.779627Z","shell.execute_reply.started":"2024-12-21T09:22:12.772676Z","shell.execute_reply":"2024-12-21T09:22:12.778505Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"numerical=[i for i in X.columns if X[i].dtype in ['int64','float64','int32'] ]\ncategorical=[j for j in X.columns if X[j].dtype == 'object']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:12.780742Z","iopub.execute_input":"2024-12-21T09:22:12.78102Z","iopub.status.idle":"2024-12-21T09:22:12.79341Z","shell.execute_reply.started":"2024-12-21T09:22:12.780994Z","shell.execute_reply":"2024-12-21T09:22:12.792321Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"numerical_transformer=SimpleImputer(strategy='mean')\ncategorical_transformer=Pipeline(steps=[('imputer',SimpleImputer(strategy='most_frequent')),('OneHotencoder',OneHotEncoder(handle_unknown='ignore'))])\npreprocessor=ColumnTransformer(transformers=[('cat',categorical_transformer,categorical),('num',numerical_transformer,numerical)])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:12.794863Z","iopub.execute_input":"2024-12-21T09:22:12.79517Z","iopub.status.idle":"2024-12-21T09:22:12.807828Z","shell.execute_reply.started":"2024-12-21T09:22:12.79514Z","shell.execute_reply":"2024-12-21T09:22:12.806723Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y1=np.log1p(y)\ny2=y/2","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:12.809139Z","iopub.execute_input":"2024-12-21T09:22:12.809591Z","iopub.status.idle":"2024-12-21T09:22:12.85239Z","shell.execute_reply.started":"2024-12-21T09:22:12.809495Z","shell.execute_reply":"2024-12-21T09:22:12.851398Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X1=preprocessor.fit_transform(X)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:12.853723Z","iopub.execute_input":"2024-12-21T09:22:12.854098Z","iopub.status.idle":"2024-12-21T09:22:18.916572Z","shell.execute_reply.started":"2024-12-21T09:22:12.85406Z","shell.execute_reply":"2024-12-21T09:22:18.915359Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sc=StandardScaler()\nst=MinMaxScaler()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:18.91803Z","iopub.execute_input":"2024-12-21T09:22:18.918386Z","iopub.status.idle":"2024-12-21T09:22:18.923073Z","shell.execute_reply.started":"2024-12-21T09:22:18.918354Z","shell.execute_reply":"2024-12-21T09:22:18.922065Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X2=sc.fit_transform(X1)\nX3=st.fit_transform(X1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:18.924374Z","iopub.execute_input":"2024-12-21T09:22:18.924685Z","iopub.status.idle":"2024-12-21T09:22:20.367622Z","shell.execute_reply.started":"2024-12-21T09:22:18.924654Z","shell.execute_reply":"2024-12-21T09:22:20.366613Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train,X_test,y_train,y_test=train_test_split(X1,y1,test_size=0.01,random_state=22)\nX1_train,X1_test,y1_train,y1_test=train_test_split(X2,y1,test_size=0.01,random_state=22)\nX2_train,X2_test,y2_train,y2_test=train_test_split(X3,y1,test_size=0.01,random_state=23)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:20.368831Z","iopub.execute_input":"2024-12-21T09:22:20.369165Z","iopub.status.idle":"2024-12-21T09:22:21.167236Z","shell.execute_reply.started":"2024-12-21T09:22:20.369133Z","shell.execute_reply":"2024-12-21T09:22:21.166269Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# 4-Model Building","metadata":{}},{"cell_type":"code","source":"from sklearn.ensemble import VotingRegressor,StackingRegressor,HistGradientBoostingRegressor\nfrom sklearn.linear_model import LinearRegression,Ridge,Lasso,SGDRegressor\nimport lightgbm  as lgb\nfrom catboost import CatBoostRegressor\nfrom  xgboost import XGBRegressor \n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:21.168497Z","iopub.execute_input":"2024-12-21T09:22:21.168818Z","iopub.status.idle":"2024-12-21T09:22:22.851444Z","shell.execute_reply.started":"2024-12-21T09:22:21.168787Z","shell.execute_reply":"2024-12-21T09:22:22.850318Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def rmsle(y_pred,y_test):\n    return np.sqrt(mean_squared_log_error(y_pred,y_test))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:22.852706Z","iopub.execute_input":"2024-12-21T09:22:22.853234Z","iopub.status.idle":"2024-12-21T09:22:22.858163Z","shell.execute_reply.started":"2024-12-21T09:22:22.853178Z","shell.execute_reply":"2024-12-21T09:22:22.85712Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"**HistGradientBoostin**","metadata":{}},{"cell_type":"code","source":"hist=HistGradientBoostingRegressor(random_state=3)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:22.859307Z","iopub.execute_input":"2024-12-21T09:22:22.859579Z","iopub.status.idle":"2024-12-21T09:22:22.87336Z","shell.execute_reply.started":"2024-12-21T09:22:22.859551Z","shell.execute_reply":"2024-12-21T09:22:22.872493Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"hist.fit(X2_train,y2_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:22.874545Z","iopub.execute_input":"2024-12-21T09:22:22.874936Z","iopub.status.idle":"2024-12-21T09:22:33.400915Z","shell.execute_reply.started":"2024-12-21T09:22:22.874884Z","shell.execute_reply":"2024-12-21T09:22:33.398712Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_pred4=hist.predict(X2_test)\nrmsle(y_pred4,y2_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:33.401915Z","iopub.execute_input":"2024-12-21T09:22:33.402255Z","iopub.status.idle":"2024-12-21T09:22:33.456726Z","shell.execute_reply.started":"2024-12-21T09:22:33.402221Z","shell.execute_reply":"2024-12-21T09:22:33.455897Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"**CatBoost**","metadata":{}},{"cell_type":"code","source":"catboost=CatBoostRegressor(random_state=11,verbose=0)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:33.457689Z","iopub.execute_input":"2024-12-21T09:22:33.458002Z","iopub.status.idle":"2024-12-21T09:22:33.467077Z","shell.execute_reply.started":"2024-12-21T09:22:33.457971Z","shell.execute_reply":"2024-12-21T09:22:33.466286Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"catboost.fit(X2_train,y2_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:22:33.468669Z","iopub.execute_input":"2024-12-21T09:22:33.468988Z","iopub.status.idle":"2024-12-21T09:24:23.888605Z","shell.execute_reply.started":"2024-12-21T09:22:33.468957Z","shell.execute_reply":"2024-12-21T09:24:23.887426Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_pred6=catboost.predict(X2_test)\nrmsle(y_pred6,y2_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:24:23.890285Z","iopub.execute_input":"2024-12-21T09:24:23.89073Z","iopub.status.idle":"2024-12-21T09:24:24.055392Z","shell.execute_reply.started":"2024-12-21T09:24:23.890684Z","shell.execute_reply":"2024-12-21T09:24:24.05431Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"**LGB**","metadata":{}},{"cell_type":"code","source":"lgbm=lgb.LGBMRegressor(random_state=83)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:24:24.056777Z","iopub.execute_input":"2024-12-21T09:24:24.057701Z","iopub.status.idle":"2024-12-21T09:24:24.062502Z","shell.execute_reply.started":"2024-12-21T09:24:24.057648Z","shell.execute_reply":"2024-12-21T09:24:24.061394Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"lgbm.fit(X2_train,y2_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:24:24.063705Z","iopub.execute_input":"2024-12-21T09:24:24.064Z","iopub.status.idle":"2024-12-21T09:24:31.294346Z","shell.execute_reply.started":"2024-12-21T09:24:24.063971Z","shell.execute_reply":"2024-12-21T09:24:31.293233Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_pred7=lgbm.predict(X2_test)\nrmsle(y_pred7,y2_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:24:31.2956Z","iopub.execute_input":"2024-12-21T09:24:31.295895Z","iopub.status.idle":"2024-12-21T09:24:31.372685Z","shell.execute_reply.started":"2024-12-21T09:24:31.295867Z","shell.execute_reply":"2024-12-21T09:24:31.371624Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"**Voting**","metadata":{}},{"cell_type":"code","source":"voting=VotingRegressor(estimators=[('hist',hist),('cb',catboost),('lgb',lgbm)])\nvoting.fit(X2_train,y2_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:24:31.374598Z","iopub.execute_input":"2024-12-21T09:24:31.374926Z","iopub.status.idle":"2024-12-21T09:27:01.016886Z","shell.execute_reply.started":"2024-12-21T09:24:31.374897Z","shell.execute_reply":"2024-12-21T09:27:01.015693Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_pred8=voting.predict(X2_test)*0.98\nrmsle(y_pred8,y2_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:27:01.018274Z","iopub.execute_input":"2024-12-21T09:27:01.018602Z","iopub.status.idle":"2024-12-21T09:27:01.366413Z","shell.execute_reply.started":"2024-12-21T09:27:01.018572Z","shell.execute_reply":"2024-12-21T09:27:01.365291Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"stacking=StackingRegressor(estimators=[('hist',hist)],final_estimator=lgbm)\nstacking.fit(X2_train,y2_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:27:01.37345Z","iopub.execute_input":"2024-12-21T09:27:01.373833Z","iopub.status.idle":"2024-12-21T09:29:38.347358Z","shell.execute_reply.started":"2024-12-21T09:27:01.373793Z","shell.execute_reply":"2024-12-21T09:29:38.346175Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_pred9=np.expm1(stacking.predict(X2_test))*0.009\nrmsle(y_pred9,y2_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:29:38.349035Z","iopub.execute_input":"2024-12-21T09:29:38.349501Z","iopub.status.idle":"2024-12-21T09:29:38.541443Z","shell.execute_reply.started":"2024-12-21T09:29:38.349452Z","shell.execute_reply":"2024-12-21T09:29:38.540368Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:29:38.542552Z","iopub.execute_input":"2024-12-21T09:29:38.542886Z","iopub.status.idle":"2024-12-21T09:29:38.569155Z","shell.execute_reply.started":"2024-12-21T09:29:38.542857Z","shell.execute_reply":"2024-12-21T09:29:38.567972Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:29:38.570667Z","iopub.execute_input":"2024-12-21T09:29:38.571021Z","iopub.status.idle":"2024-12-21T09:29:39.011279Z","shell.execute_reply.started":"2024-12-21T09:29:38.57099Z","shell.execute_reply":"2024-12-21T09:29:39.010208Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test['Parsed_Date']=pd.to_datetime(test['Policy Start Date'],format='ISO8601')\ntest['Year'] = test['Parsed_Date'].dt.year\ntest['Month'] = test['Parsed_Date'].dt.month\ntest['Day'] = test['Parsed_Date'].dt.day\n#df['Day of Week'] = df['Parsed_Date'].dt.dayofweek  # 0=Monday, 6=Sunday\n#df['Is Weekend'] = df['Day of Week'].apply(lambda x: 1 if x >= 5 else 0)\ntest['Quarter'] = test['Parsed_Date'].dt.quarter","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:29:39.012597Z","iopub.execute_input":"2024-12-21T09:29:39.012986Z","iopub.status.idle":"2024-12-21T09:29:39.383471Z","shell.execute_reply.started":"2024-12-21T09:29:39.012949Z","shell.execute_reply":"2024-12-21T09:29:39.382541Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"testy=test[X.columns]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:29:39.384814Z","iopub.execute_input":"2024-12-21T09:29:39.385148Z","iopub.status.idle":"2024-12-21T09:29:39.498947Z","shell.execute_reply.started":"2024-12-21T09:29:39.385115Z","shell.execute_reply":"2024-12-21T09:29:39.497729Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"testy=preprocessor.fit_transform(testy)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:29:39.500313Z","iopub.execute_input":"2024-12-21T09:29:39.500648Z","iopub.status.idle":"2024-12-21T09:29:44.499941Z","shell.execute_reply.started":"2024-12-21T09:29:39.500617Z","shell.execute_reply":"2024-12-21T09:29:44.499038Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"testy=st.fit_transform(testy)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:29:44.501228Z","iopub.execute_input":"2024-12-21T09:29:44.501584Z","iopub.status.idle":"2024-12-21T09:29:44.871143Z","shell.execute_reply.started":"2024-12-21T09:29:44.501547Z","shell.execute_reply":"2024-12-21T09:29:44.870266Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# 7-Submission","metadata":{}},{"cell_type":"code","source":"predictions=np.expm1(voting.predict(testy))\npredic=np.expm1(stacking.predict(testy))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:29:44.872431Z","iopub.execute_input":"2024-12-21T09:29:44.872808Z","iopub.status.idle":"2024-12-21T09:30:27.208482Z","shell.execute_reply.started":"2024-12-21T09:29:44.872774Z","shell.execute_reply":"2024-12-21T09:30:27.207364Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"predi=predictions*0.7 + predic*0.3","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:45:22.755126Z","iopub.execute_input":"2024-12-21T09:45:22.756102Z","iopub.status.idle":"2024-12-21T09:45:22.764495Z","shell.execute_reply.started":"2024-12-21T09:45:22.756058Z","shell.execute_reply":"2024-12-21T09:45:22.763421Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"predi","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:45:24.588109Z","iopub.execute_input":"2024-12-21T09:45:24.5889Z","iopub.status.idle":"2024-12-21T09:45:24.595771Z","shell.execute_reply.started":"2024-12-21T09:45:24.588858Z","shell.execute_reply":"2024-12-21T09:45:24.594794Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"output=pd.DataFrame({'id':test.id,'Premium Amount':predi})\noutput","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:45:27.567892Z","iopub.execute_input":"2024-12-21T09:45:27.568841Z","iopub.status.idle":"2024-12-21T09:45:27.585654Z","shell.execute_reply.started":"2024-12-21T09:45:27.568785Z","shell.execute_reply":"2024-12-21T09:45:27.584285Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"output.describe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:45:29.347147Z","iopub.execute_input":"2024-12-21T09:45:29.34759Z","iopub.status.idle":"2024-12-21T09:45:29.412297Z","shell.execute_reply.started":"2024-12-21T09:45:29.347555Z","shell.execute_reply":"2024-12-21T09:45:29.411125Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#output['Premium Amount']=output['Premium Amount'].mean()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:45:33.167048Z","iopub.execute_input":"2024-12-21T09:45:33.167496Z","iopub.status.idle":"2024-12-21T09:45:33.172472Z","shell.execute_reply.started":"2024-12-21T09:45:33.167448Z","shell.execute_reply":"2024-12-21T09:45:33.171384Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"output","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:45:34.994826Z","iopub.execute_input":"2024-12-21T09:45:34.995281Z","iopub.status.idle":"2024-12-21T09:45:35.007244Z","shell.execute_reply.started":"2024-12-21T09:45:34.99524Z","shell.execute_reply":"2024-12-21T09:45:35.006081Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission=output.to_csv('submission.csv',index=False)\nprint('The Submission Is Saved Successfully')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:45:40.447664Z","iopub.execute_input":"2024-12-21T09:45:40.448498Z","iopub.status.idle":"2024-12-21T09:45:42.089125Z","shell.execute_reply.started":"2024-12-21T09:45:40.448462Z","shell.execute_reply":"2024-12-21T09:45:42.087923Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}