{"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":30786,"isInternetEnabled":false,"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\n# import os\n# for dirname, _, filenames in os.walk('/kaggle/input'):\n#     for filename in filenames:\n#         print(os.path.join(dirname, filename))\n\ntrain_data_path = \"/kaggle/input/playground-series-s4e12/train.csv\"\ntest_data_path = \"/kaggle/input/playground-series-s4e12/test.csv\"\nsample_data_path = \"/kaggle/input/playground-series-s4e12/sample_submission.csv\"\n\ntrain_data = pd.read_csv(train_data_path)\ntest_data = pd.read_csv(test_data_path)\nsample_data = pd.read_csv(sample_data_path)\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-05T00:35:16.312657Z","iopub.execute_input":"2024-12-05T00:35:16.313226Z","iopub.status.idle":"2024-12-05T00:35:31.008957Z","shell.execute_reply.started":"2024-12-05T00:35:16.313133Z","shell.execute_reply":"2024-12-05T00:35:31.007561Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y = train_data['Premium Amount']\n\nfeatures = ['Age', 'Gender', \"Marital Status\", \n            \"Annual Income\", \"Credit Score\", \n            \"Health Score\", \"Smoking Status\", \n            \"Exercise Frequency\", \"Policy Type\", \n            \"Previous Claims\", \"Insurance Duration\", \"Location\"]\n\nX_orig  = train_data[features]\n\ndef preprocess(df) :\n    df.loc[df['Smoking Status'] == 'Yes', 'Smoking Status'] = 1\n    df.loc[df['Smoking Status'] == 'No', 'Smoking Status'] = 0\n    \n    mul_features = [\"Gender\", \"Marital Status\", \"Exercise Frequency\", \"Policy Type\", \"Location\"]\n    df = pd.get_dummies(df, columns=mul_features, dtype=int)\n    \n    df.fillna(0, inplace=True)\n    return df\n\nX = preprocess(X_orig)\nprint(X.head(2))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-05T00:36:36.449873Z","iopub.execute_input":"2024-12-05T00:36:36.450331Z","iopub.status.idle":"2024-12-05T00:36:37.818362Z","shell.execute_reply.started":"2024-12-05T00:36:36.450293Z","shell.execute_reply":"2024-12-05T00:36:37.817261Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.metrics import mean_absolute_error\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.ensemble import RandomForestRegressor\nfrom sklearn.preprocessing import OneHotEncoder\n\niowa_model=RandomForestRegressor(random_state=1)\niowa_model.fit(X, y)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-05T00:36:52.930286Z","iopub.execute_input":"2024-12-05T00:36:52.930711Z","iopub.status.idle":"2024-12-05T00:36:54.326539Z","shell.execute_reply.started":"2024-12-05T00:36:52.930677Z","shell.execute_reply":"2024-12-05T00:36:54.324658Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_X_orig = test_data[features]\ntest_X = preprocess(test_X_orig)\ntest_preds = iowa_model.predict(test_X)\nprint(test_preds)\n\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-04T15:09:12.806836Z","iopub.execute_input":"2024-12-04T15:09:12.807156Z","iopub.status.idle":"2024-12-04T15:10:16.503362Z","shell.execute_reply.started":"2024-12-04T15:09:12.807127Z","shell.execute_reply":"2024-12-04T15:10:16.502637Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"outputs = pd.DataFrame({\n    'Id': test_data['id'],\n    'Premium Amount':test_preds\n})\n\n\n\noutputs.to_csv('insurance_submission_v_1.0.csv', index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-04T15:14:53.211675Z","iopub.execute_input":"2024-12-04T15:14:53.212013Z","iopub.status.idle":"2024-12-04T15:14:54.147182Z","shell.execute_reply.started":"2024-12-04T15:14:53.211984Z","shell.execute_reply":"2024-12-04T15:14:54.14646Z"}},"outputs":[],"execution_count":null}]}