{"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-16T07:29:55.045077Z","iopub.execute_input":"2024-12-16T07:29:55.045492Z","iopub.status.idle":"2024-12-16T07:29:56.496526Z","shell.execute_reply.started":"2024-12-16T07:29:55.045447Z","shell.execute_reply":"2024-12-16T07:29:56.495223Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/playground-series-s4e12/train.csv')\ntest = pd.read_csv('/kaggle/input/playground-series-s4e12/test.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-16T07:32:21.894801Z","iopub.execute_input":"2024-12-16T07:32:21.8955Z","iopub.status.idle":"2024-12-16T07:32:34.188018Z","shell.execute_reply.started":"2024-12-16T07:32:21.895454Z","shell.execute_reply":"2024-12-16T07:32:34.186516Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import h2o\nh2o.init()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-16T07:40:11.971228Z","iopub.execute_input":"2024-12-16T07:40:11.971905Z","iopub.status.idle":"2024-12-16T07:40:21.647945Z","shell.execute_reply.started":"2024-12-16T07:40:11.971854Z","shell.execute_reply":"2024-12-16T07:40:21.646659Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from h2o.frame import H2OFrame\ndata = h2o.import_file('/kaggle/input/playground-series-s4e12/train.csv')\n\ntrain, val = data.split_frame(ratios=[0.8], seed=123)\n\nX = data.columns[: -1]\ny = \"Premium Amount\"\n\ndata[y] = data[y].asnumeric()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-16T07:49:09.06977Z","iopub.execute_input":"2024-12-16T07:49:09.070241Z","iopub.status.idle":"2024-12-16T07:49:22.199073Z","shell.execute_reply.started":"2024-12-16T07:49:09.070204Z","shell.execute_reply":"2024-12-16T07:49:22.197594Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from h2o.automl import H2OAutoML\n\naml = H2OAutoML(max_runtime_secs=1200, max_models=50, seed=123, nfolds=5)\naml.train(x=X, y=y, training_frame=train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-16T07:51:56.082108Z","iopub.execute_input":"2024-12-16T07:51:56.082879Z","iopub.status.idle":"2024-12-16T08:11:59.557276Z","shell.execute_reply.started":"2024-12-16T07:51:56.082819Z","shell.execute_reply":"2024-12-16T08:11:59.555797Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Display the leaderboard\nlb = aml.leaderboard\nprint(lb)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-16T08:12:27.861978Z","iopub.execute_input":"2024-12-16T08:12:27.862678Z","iopub.status.idle":"2024-12-16T08:12:27.878562Z","shell.execute_reply.started":"2024-12-16T08:12:27.862633Z","shell.execute_reply":"2024-12-16T08:12:27.876962Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_data = h2o.import_file(\"/kaggle/input/playground-series-s4e12/test.csv\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-16T08:28:56.754297Z","iopub.execute_input":"2024-12-16T08:28:56.754748Z","iopub.status.idle":"2024-12-16T08:29:01.701591Z","shell.execute_reply.started":"2024-12-16T08:28:56.754714Z","shell.execute_reply":"2024-12-16T08:29:01.700266Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"predictions = aml.leader.predict(test_data)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-16T08:29:24.150796Z","iopub.execute_input":"2024-12-16T08:29:24.151275Z","iopub.status.idle":"2024-12-16T08:29:24.403933Z","shell.execute_reply.started":"2024-12-16T08:29:24.151237Z","shell.execute_reply":"2024-12-16T08:29:24.402654Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\n\n# Convert predictions to pandas DataFrame\npred_df = predictions.as_data_frame()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-16T08:29:43.754632Z","iopub.execute_input":"2024-12-16T08:29:43.755105Z","iopub.status.idle":"2024-12-16T08:29:44.534249Z","shell.execute_reply.started":"2024-12-16T08:29:43.755066Z","shell.execute_reply":"2024-12-16T08:29:44.53298Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_predictions = best_model.predict(test_h2o).as_data_frame()\n\nsubmission = pd.read_csv('/kaggle/input/playground-series-s4e12/sample_submission.csv')\n\n\nsubmission['Premium Amount'] = df_predictions\n\n# Save to CSV in the required format\nsubmission.to_csv('submission.csv', index=False)\n\nprint(submission.head())  # Preview the submission file\n\n\n  ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-16T09:07:40.324642Z","iopub.execute_input":"2024-12-16T09:07:40.325103Z","iopub.status.idle":"2024-12-16T09:07:43.477749Z","shell.execute_reply.started":"2024-12-16T09:07:40.325067Z","shell.execute_reply":"2024-12-16T09:07:43.476215Z"}},"outputs":[],"execution_count":null}]}