{"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.12.4"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":84896,"databundleVersionId":10305135,"sourceType":"competition"}],"dockerImageVersionId":30822,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"id":"0e778ab1-5eed-446e-ac62-c620e983472e","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,cross_val_score\nfrom sklearn.ensemble import RandomForestRegressor\nfrom sklearn.neural_network import MLPRegressor\nfrom sklearn.svm import SVR\nfrom sklearn.tree import DecisionTreeRegressor\nfrom sklearn.preprocessing import StandardScaler,OneHotEncoder,OrdinalEncoder\nfrom sklearn.compose import ColumnTransformer\nfrom sklearn.pipeline import make_pipeline\nimport pickle \nfrom sklearn.impute import SimpleImputer,KNNImputer","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-07T08:03:06.613618Z","iopub.execute_input":"2025-01-07T08:03:06.613992Z","iopub.status.idle":"2025-01-07T08:03:08.076412Z","shell.execute_reply.started":"2025-01-07T08:03:06.613959Z","shell.execute_reply":"2025-01-07T08:03:08.075291Z"}},"outputs":[],"execution_count":null},{"id":"3f9fa38e-2f29-4764-9bca-8b7f9ab9540a","cell_type":"markdown","source":"- /kaggle/input/playground-series-s4e12/sample_submission.csv\n- /kaggle/input/playground-series-s4e12/train.csv\n- /kaggle/input/playground-series-s4e12/test.csv","metadata":{}},{"id":"21a04d94-6045-4cd5-ad1e-17552e3b6036","cell_type":"code","source":"df = pd.read_csv('/kaggle/input/playground-series-s4e12/train.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-07T08:03:08.077562Z","iopub.execute_input":"2025-01-07T08:03:08.078109Z","iopub.status.idle":"2025-01-07T08:03:15.186139Z","shell.execute_reply.started":"2025-01-07T08:03:08.078073Z","shell.execute_reply":"2025-01-07T08:03:15.184914Z"}},"outputs":[],"execution_count":null},{"id":"81613856-335e-4aad-aef6-045754dd442d","cell_type":"code","source":"test=pd.read_csv('/kaggle/input/playground-series-s4e12/test.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-07T08:03:15.188069Z","iopub.execute_input":"2025-01-07T08:03:15.188385Z","iopub.status.idle":"2025-01-07T08:03:19.474458Z","shell.execute_reply.started":"2025-01-07T08:03:15.188357Z","shell.execute_reply":"2025-01-07T08:03:19.473278Z"}},"outputs":[],"execution_count":null},{"id":"a40f36f7-8b2e-498a-8b48-3cb482f62c29","cell_type":"code","source":"df.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-07T08:03:19.476249Z","iopub.execute_input":"2025-01-07T08:03:19.476637Z","iopub.status.idle":"2025-01-07T08:03:20.125175Z","shell.execute_reply.started":"2025-01-07T08:03:19.476597Z","shell.execute_reply":"2025-01-07T08:03:20.123915Z"}},"outputs":[],"execution_count":null},{"id":"f54319fe-b99b-4cb4-9b37-bf6fc50d1913","cell_type":"code","source":"df.drop(['id','Policy Start Date'],axis='columns',inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-07T08:03:20.12598Z","iopub.execute_input":"2025-01-07T08:03:20.126262Z","iopub.status.idle":"2025-01-07T08:03:20.309142Z","shell.execute_reply.started":"2025-01-07T08:03:20.12624Z","shell.execute_reply":"2025-01-07T08:03:20.30792Z"}},"outputs":[],"execution_count":null},{"id":"e0f5f28f-2c2d-4cfe-9dfd-9c4e5224bcd2","cell_type":"code","source":"df.sample(5)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-07T08:03:20.310038Z","iopub.execute_input":"2025-01-07T08:03:20.31032Z","iopub.status.idle":"2025-01-07T08:03:20.390624Z","shell.execute_reply.started":"2025-01-07T08:03:20.310297Z","shell.execute_reply":"2025-01-07T08:03:20.389567Z"}},"outputs":[],"execution_count":null},{"id":"02c84f42-3eaa-407f-9195-740915bd379a","cell_type":"code","source":"X= df.iloc[:10000,:-1]\ny=df.iloc[:10000,-1]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-07T08:03:20.391559Z","iopub.execute_input":"2025-01-07T08:03:20.391857Z","iopub.status.idle":"2025-01-07T08:03:20.533785Z","shell.execute_reply.started":"2025-01-07T08:03:20.39183Z","shell.execute_reply":"2025-01-07T08:03:20.532722Z"}},"outputs":[],"execution_count":null},{"id":"22febc90-7db0-4352-9f0d-11f0948b5d0c","cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.2,random_state=42)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-07T08:07:19.843904Z","iopub.execute_input":"2025-01-07T08:07:19.844265Z","iopub.status.idle":"2025-01-07T08:07:19.85522Z","shell.execute_reply.started":"2025-01-07T08:07:19.844237Z","shell.execute_reply":"2025-01-07T08:07:19.853909Z"}},"outputs":[],"execution_count":null},{"id":"59236aa0-94a0-49a1-9318-b9b809f33fe0","cell_type":"code","source":"trf1 = ColumnTransformer(transformers=[('mean1',SimpleImputer(strategy='mean'),[0,2,7,11,12,13])],\n                         remainder='passthrough')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-07T08:07:16.454556Z","iopub.execute_input":"2025-01-07T08:07:16.454939Z","iopub.status.idle":"2025-01-07T08:07:16.460536Z","shell.execute_reply.started":"2025-01-07T08:07:16.454904Z","shell.execute_reply":"2025-01-07T08:07:16.459166Z"}},"outputs":[],"execution_count":null},{"id":"c953aeb2-091f-4265-9d36-172300b8cdda","cell_type":"code","source":"trf2 = ColumnTransformer(transformers=[('medium1',SimpleImputer(strategy='most_frequent'),[3,4,6,10,15])],remainder='passthrough')#10","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-07T08:07:16.86334Z","iopub.execute_input":"2025-01-07T08:07:16.863736Z","iopub.status.idle":"2025-01-07T08:07:16.868608Z","shell.execute_reply.started":"2025-01-07T08:07:16.863693Z","shell.execute_reply":"2025-01-07T08:07:16.86738Z"}},"outputs":[],"execution_count":null},{"id":"b6974686-cc1d-4db1-8526-980372d93652","cell_type":"code","source":"X_train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-07T08:03:20.57858Z","iopub.execute_input":"2025-01-07T08:03:20.579068Z","iopub.status.idle":"2025-01-07T08:03:20.607845Z","shell.execute_reply.started":"2025-01-07T08:03:20.579026Z","shell.execute_reply":"2025-01-07T08:03:20.606611Z"}},"outputs":[],"execution_count":null},{"id":"cd874d8b-90fa-4a3d-bd0f-faf2c38dd414","cell_type":"markdown","source":"- Education Level : [\"High School\",\"Bachelor's\",\"Master's\",\"PhD\"]\n- Exercise Frequency : [\"Rarely\",\"Daily\",\"Weekly\",\"Monthly\"]\n- Customer Feedback : [\"Poor\",\"Average\",\"Good\"]\n- Policy Type : [\"Basic\",\"Comprehensive\",\"Premium\"]","metadata":{}},{"id":"b40b8aee-7079-4f32-8304-9a9739e10ae7","cell_type":"code","source":"trf3 = ColumnTransformer(transformers=[\n    ('edu',OrdinalEncoder(categories=[[\"Female\",\"Male\"],\n                                      [\"High School\",\"Bachelor's\",\"Master's\",\"PhD\"],\n                                      [\"Basic\",\"Comprehensive\",\"Premium\"],\n                                      [\"Poor\",\"Average\",\"Good\"],\n                                      [\"Rarely\",\"Daily\",\"Weekly\",\"Monthly\"],\n                                      ],handle_unknown=\"use_encoded_value\", unknown_value=-1),[1,5,9,14,16])\n],remainder='passthrough')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-07T08:03:20.609412Z","iopub.execute_input":"2025-01-07T08:03:20.609721Z","iopub.status.idle":"2025-01-07T08:03:20.615011Z","shell.execute_reply.started":"2025-01-07T08:03:20.60969Z","shell.execute_reply":"2025-01-07T08:03:20.61377Z"}},"outputs":[],"execution_count":null},{"id":"bd3429ad-4e21-49c1-a8f5-eaf8eeddda70","cell_type":"code","source":"trf4 = ColumnTransformer(\n    ('ohe',OneHotEncoder(sparse_output=False,handle_unknown='ignore',drop='first'),[3,6,8,15,17]),remainder='passthrough')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-07T08:03:20.615911Z","iopub.execute_input":"2025-01-07T08:03:20.616291Z","iopub.status.idle":"2025-01-07T08:03:20.63735Z","shell.execute_reply.started":"2025-01-07T08:03:20.616252Z","shell.execute_reply":"2025-01-07T08:03:20.636183Z"}},"outputs":[],"execution_count":null},{"id":"80462165-97ea-497a-896e-ced8c4c7a185","cell_type":"code","source":"X_train = trf1.fit_transform(X_train)\nX_train = trf2.fit_transform(X_train)\nX_train = trf3.fit_transform(X_train)\n# X_train = trf4.fit_transform(X_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-07T08:07:25.685116Z","iopub.execute_input":"2025-01-07T08:07:25.685474Z","iopub.status.idle":"2025-01-07T08:07:25.739232Z","shell.execute_reply.started":"2025-01-07T08:07:25.685441Z","shell.execute_reply":"2025-01-07T08:07:25.738144Z"}},"outputs":[],"execution_count":null},{"id":"9a3b9ccf-f2f5-450b-adf0-2821c9e5e8b3","cell_type":"code","source":"df_train = pd.DataFrame(X_train)\ndf_train \n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-07T08:08:42.331102Z","iopub.execute_input":"2025-01-07T08:08:42.33147Z","iopub.status.idle":"2025-01-07T08:08:42.352123Z","shell.execute_reply.started":"2025-01-07T08:08:42.331436Z","shell.execute_reply":"2025-01-07T08:08:42.350976Z"}},"outputs":[],"execution_count":null},{"id":"186c0783-9100-4fe3-9376-03607bc79171","cell_type":"code","source":"# dtr = DecisionTreeRegressor()\n# svm = SVR()\n# rf = RandomForestRegressor()\n# pipe1 = make_pipeline(trf1,trf2,trf3,trf4,dtr)\n# pipe2 = make_pipeline(trf1,trf2,trf3,trf4,svm)\n# pipe3 = make_pipeline(trf1,trf2,trf3,trf4,rf)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-07T08:03:20.742575Z","iopub.execute_input":"2025-01-07T08:03:20.742928Z","iopub.status.idle":"2025-01-07T08:03:20.760659Z","shell.execute_reply.started":"2025-01-07T08:03:20.742897Z","shell.execute_reply":"2025-01-07T08:03:20.759435Z"}},"outputs":[],"execution_count":null},{"id":"2b643bf7-b6fe-4a5a-9688-7aeddcad7649","cell_type":"code","source":"# pipe1.fit(X_train,y_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-07T08:03:20.761969Z","iopub.execute_input":"2025-01-07T08:03:20.762301Z","iopub.status.idle":"2025-01-07T08:03:20.782345Z","shell.execute_reply.started":"2025-01-07T08:03:20.762262Z","shell.execute_reply":"2025-01-07T08:03:20.78119Z"}},"outputs":[],"execution_count":null},{"id":"d0d4a056-bb8c-43fe-8bc6-65b1225b59a1","cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}