{"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":"gpu","dataSources":[{"sourceId":84896,"databundleVersionId":10305135,"sourceType":"competition"}],"dockerImageVersionId":30787,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# <p style=\"background-color: #4A5568; font-family: 'Courier New', monospace; font-weight: bold; color: #E2E8F0; font-size: 85%; text-align: center; border: 3px solid #A0AEC0; border-radius: 15px; padding: 15px; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);\">🌟 📦 Import Packages 🌟</p>","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import mean_squared_log_error\nfrom sklearn.preprocessing import LabelEncoder\nimport optuna\nfrom sklearn.metrics import mean_squared_error\nimport h2o\nfrom h2o.automl import H2OAutoML","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2024-12-03T17:07:54.033249Z","iopub.execute_input":"2024-12-03T17:07:54.033519Z","iopub.status.idle":"2024-12-03T17:07:56.887215Z","shell.execute_reply.started":"2024-12-03T17:07:54.033493Z","shell.execute_reply":"2024-12-03T17:07:56.886536Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"h2o.init()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-03T17:07:56.889238Z","iopub.execute_input":"2024-12-03T17:07:56.889701Z","iopub.status.idle":"2024-12-03T17:08:04.00884Z","shell.execute_reply.started":"2024-12-03T17:07:56.889674Z","shell.execute_reply":"2024-12-03T17:08:04.00783Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# <p style=\"background-color: #4A5568; font-family: 'Courier New', monospace; font-weight: bold; color: #E2E8F0; font-size: 85%; text-align: center; border: 3px solid #A0AEC0; border-radius: 15px; padding: 15px; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);\">🌟 📂 Load Dataset 🌟</p>\n\n","metadata":{}},{"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')\nsubmission = pd.read_csv('/kaggle/input/playground-series-s4e12/sample_submission.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-03T17:08:04.010212Z","iopub.execute_input":"2024-12-03T17:08:04.010556Z","iopub.status.idle":"2024-12-03T17:08:12.237753Z","shell.execute_reply.started":"2024-12-03T17:08:04.010527Z","shell.execute_reply":"2024-12-03T17:08:12.236982Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-03T17:08:12.239749Z","iopub.execute_input":"2024-12-03T17:08:12.240042Z","iopub.status.idle":"2024-12-03T17:08:12.275303Z","shell.execute_reply.started":"2024-12-03T17:08:12.240016Z","shell.execute_reply":"2024-12-03T17:08:12.274476Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-03T17:08:12.276296Z","iopub.execute_input":"2024-12-03T17:08:12.276551Z","iopub.status.idle":"2024-12-03T17:08:12.931169Z","shell.execute_reply.started":"2024-12-03T17:08:12.276527Z","shell.execute_reply":"2024-12-03T17:08:12.930271Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['Policy Start Date'] = pd.to_datetime(train['Policy Start Date'])\n\ntrain['Policy Start Year'] = train['Policy Start Date'].dt.year\ntrain['Policy Start Month'] = train['Policy Start Date'].dt.month\ntrain['Policy Start Day'] = train['Policy Start Date'].dt.day","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-03T17:08:12.932302Z","iopub.execute_input":"2024-12-03T17:08:12.932575Z","iopub.status.idle":"2024-12-03T17:08:13.414251Z","shell.execute_reply.started":"2024-12-03T17:08:12.932551Z","shell.execute_reply":"2024-12-03T17:08:13.413556Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.drop(columns=['Policy Start Date'], inplace=True)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# <p style=\"background-color: #4A5568; font-family: 'Courier New', monospace; font-weight: bold; color: #E2E8F0; font-size: 85%; text-align: center; border: 3px solid #A0AEC0; border-radius: 15px; padding: 15px; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);\">🌟 🧠 AutoML Setup and Initialization 🌟</p>\n\n","metadata":{}},{"cell_type":"code","source":"target = \"Premium Amount\"  \nfeatures = [col for col in train.columns if col != target]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-03T17:08:13.415261Z","iopub.execute_input":"2024-12-03T17:08:13.415549Z","iopub.status.idle":"2024-12-03T17:08:13.419881Z","shell.execute_reply.started":"2024-12-03T17:08:13.415524Z","shell.execute_reply":"2024-12-03T17:08:13.41891Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#train, test = train_test_split(train, test_size=0.1, random_state=42)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-03T17:08:13.421002Z","iopub.execute_input":"2024-12-03T17:08:13.421376Z","iopub.status.idle":"2024-12-03T17:08:13.430879Z","shell.execute_reply.started":"2024-12-03T17:08:13.421349Z","shell.execute_reply":"2024-12-03T17:08:13.430144Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_h2o = h2o.H2OFrame(train)\ntest_h2o = h2o.H2OFrame(test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-03T17:08:13.431866Z","iopub.execute_input":"2024-12-03T17:08:13.43214Z","iopub.status.idle":"2024-12-03T17:08:56.112703Z","shell.execute_reply.started":"2024-12-03T17:08:13.432116Z","shell.execute_reply":"2024-12-03T17:08:56.111992Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"automl = H2OAutoML(max_runtime_secs=1200, seed=42)\nautoml.train(x=features, y=target, training_frame=train_h2o)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-03T17:08:56.114683Z","iopub.execute_input":"2024-12-03T17:08:56.114943Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"leaderboard = automl.leaderboard\nprint(leaderboard)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# <p style=\"background-color: #4A5568; font-family: 'Courier New', monospace; font-weight: bold; color: #E2E8F0; font-size: 85%; text-align: center; border: 3px solid #A0AEC0; border-radius: 15px; padding: 15px; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);\">🌟 📊 Submission 🌟</p>","metadata":{}},{"cell_type":"code","source":"test.head()","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"predictions = automl.leader.predict(test_h2o)\npredictions_df = predictions.as_data_frame()","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission = pd.DataFrame({\n    'id': test['id'],  \n    'Premium Amount': predictions_df['predict']\n})","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(submission)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission.to_csv('submission.csv', index=False)\nprint(\"File saved...\")","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}