{"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\n\nfrom lightgbm import LGBMRegressor","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2024-12-03T13:11:59.759447Z","iopub.execute_input":"2024-12-03T13:11:59.759866Z","iopub.status.idle":"2024-12-03T13:12:00.032161Z","shell.execute_reply.started":"2024-12-03T13:11:59.759829Z","shell.execute_reply":"2024-12-03T13:12:00.031104Z"}},"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-03T13:02:02.477461Z","iopub.execute_input":"2024-12-03T13:02:02.478003Z","iopub.status.idle":"2024-12-03T13:02:08.814844Z","shell.execute_reply.started":"2024-12-03T13:02:02.477964Z","shell.execute_reply":"2024-12-03T13:02:08.813607Z"}},"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-03T13:09:34.089899Z","iopub.execute_input":"2024-12-03T13:09:34.090909Z","iopub.status.idle":"2024-12-03T13:09:34.111708Z","shell.execute_reply.started":"2024-12-03T13:09:34.09087Z","shell.execute_reply":"2024-12-03T13:09:34.110855Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"raw_data.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-03T13:09:40.779504Z","iopub.execute_input":"2024-12-03T13:09:40.779873Z","iopub.status.idle":"2024-12-03T13:09:40.81511Z","shell.execute_reply.started":"2024-12-03T13:09:40.779839Z","shell.execute_reply":"2024-12-03T13:09:40.813941Z"}},"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-03T13:09:55.532154Z","iopub.execute_input":"2024-12-03T13:09:55.532556Z","iopub.status.idle":"2024-12-03T13:09:57.875887Z","shell.execute_reply.started":"2024-12-03T13:09:55.532519Z","shell.execute_reply":"2024-12-03T13:09:57.87503Z"}},"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-03T13:10:12.629248Z","iopub.execute_input":"2024-12-03T13:10:12.629638Z","iopub.status.idle":"2024-12-03T13:10:12.640069Z","shell.execute_reply.started":"2024-12-03T13:10:12.629602Z","shell.execute_reply":"2024-12-03T13:10:12.639169Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"param_grid={\n    # 'num_leaves':[31,62],\n    'max_depth':[3,5,7],\n    'min_data_in_leaf':[10,20,40],\n    'feature_fraction':[0.5,1]\n}","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-03T13:16:30.428643Z","iopub.execute_input":"2024-12-03T13:16:30.429032Z","iopub.status.idle":"2024-12-03T13:16:30.434482Z","shell.execute_reply.started":"2024-12-03T13:16:30.428995Z","shell.execute_reply":"2024-12-03T13:16:30.43327Z"}},"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-03T13:15:40.676118Z","iopub.execute_input":"2024-12-03T13:15:40.677056Z","iopub.status.idle":"2024-12-03T13:15:40.729065Z","shell.execute_reply.started":"2024-12-03T13:15:40.677002Z","shell.execute_reply":"2024-12-03T13:15:40.727963Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"search=BayesSearchCV(\n    estimator=LGBMRegressor(n_estimators=200,random_state=25),\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-03T13:18:21.906215Z","iopub.execute_input":"2024-12-03T13:18:21.906635Z","iopub.status.idle":"2024-12-03T13:18:49.910696Z","shell.execute_reply.started":"2024-12-03T13:18:21.906594Z","shell.execute_reply":"2024-12-03T13:18:49.909091Z"}},"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}]}