{"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# from sklearn.model_selection import RandomizedSearchCV\nfrom skopt import BayesSearchCV\nimport sklearn\n\nfrom xgboost import XGBRegressor","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2024-12-07T04:59:03.156622Z","iopub.execute_input":"2024-12-07T04:59:03.157157Z","iopub.status.idle":"2024-12-07T04:59:03.162222Z","shell.execute_reply.started":"2024-12-07T04:59:03.157121Z","shell.execute_reply":"2024-12-07T04:59:03.160983Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"raw_data=pd.read_csv('/kaggle/input/playground-series-s4e12/train.csv')\nraw_data.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-07T04:56:41.61186Z","iopub.execute_input":"2024-12-07T04:56:41.612691Z","iopub.status.idle":"2024-12-07T04:56:47.920174Z","shell.execute_reply.started":"2024-12-07T04:56:41.612647Z","shell.execute_reply":"2024-12-07T04:56:47.919126Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"raw_data['Premium Amount']=np.log(raw_data['Premium Amount'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-07T04:56:47.921721Z","iopub.execute_input":"2024-12-07T04:56:47.922095Z","iopub.status.idle":"2024-12-07T04:56:47.944217Z","shell.execute_reply.started":"2024-12-07T04:56:47.922063Z","shell.execute_reply":"2024-12-07T04:56:47.943113Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"raw_data.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-03T13:28:48.284333Z","iopub.execute_input":"2024-12-03T13:28:48.28479Z","iopub.status.idle":"2024-12-03T13:28:48.310836Z","shell.execute_reply.started":"2024-12-03T13:28:48.28472Z","shell.execute_reply":"2024-12-03T13:28:48.309099Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def clean(cleaned):\n    for col in cleaned.select_dtypes(include='object').columns:\n        cleaned[col]=cleaned[col].fillna('-')\n        cleaned[col]=cleaned[col].astype('category')\n        \nclean(raw_data)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-07T04:56:47.945385Z","iopub.execute_input":"2024-12-07T04:56:47.945704Z","iopub.status.idle":"2024-12-07T04:56:50.686334Z","shell.execute_reply.started":"2024-12-07T04:56:47.945673Z","shell.execute_reply":"2024-12-07T04:56:50.685295Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def new_features(df):\n    df['Income_Deps']=df['Annual Income']/(df['Number of Dependents']+1)\n\nnew_features(raw_data)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-07T04:56:50.688606Z","iopub.execute_input":"2024-12-07T04:56:50.689565Z","iopub.status.idle":"2024-12-07T04:56:50.701591Z","shell.execute_reply.started":"2024-12-07T04:56:50.689513Z","shell.execute_reply":"2024-12-07T04:56:50.700624Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"param_grid={\n    # 'num_leaves':[31,62],\n    'max_depth':[3,5,7],\n    'min_child_weight':[0.5,1,1.5],\n    'subsample':[0.5,1],\n    'gamma':[0,0.5,1]\n}","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-07T04:56:50.703002Z","iopub.execute_input":"2024-12-07T04:56:50.703432Z","iopub.status.idle":"2024-12-07T04:56:50.711073Z","shell.execute_reply.started":"2024-12-07T04:56:50.703382Z","shell.execute_reply":"2024-12-07T04:56:50.71005Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X=raw_data.drop(['id','Premium Amount'],axis=1)\ny=raw_data['Premium Amount']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-07T04:56:52.164291Z","iopub.execute_input":"2024-12-07T04:56:52.164669Z","iopub.status.idle":"2024-12-07T04:56:52.205193Z","shell.execute_reply.started":"2024-12-07T04:56:52.164635Z","shell.execute_reply":"2024-12-07T04:56:52.20412Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"search=BayesSearchCV(\n    estimator=XGBRegressor(n_estimators=200,random_state=25,enable_categorical=True),\n    search_spaces=param_grid,\n    n_jobs=-1,\n    cv=3,\n    n_iter=20,\n    verbose=5,\n    scoring='neg_root_mean_squared_error'\n)\nsearch.fit(X,y)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-07T04:59:44.82633Z","iopub.execute_input":"2024-12-07T04:59:44.826703Z","iopub.status.idle":"2024-12-07T04:59:48.02897Z","shell.execute_reply.started":"2024-12-07T04:59:44.826667Z","shell.execute_reply":"2024-12-07T04:59:48.027357Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"search.best_params_","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"search.best_score_","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}