{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","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":30822,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"pip install pycaret","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-29T11:41:51.063844Z","iopub.execute_input":"2024-12-29T11:41:51.0643Z","iopub.status.idle":"2024-12-29T11:42:22.336374Z","shell.execute_reply.started":"2024-12-29T11:41:51.064269Z","shell.execute_reply":"2024-12-29T11:42:22.335018Z"},"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"PyCaret is an open-source, low-code machine learning library in Python that automates machine learning workflows (https://pycaret.org/)\n\nOK, let's go check it!","metadata":{}},{"cell_type":"markdown","source":"## Data loading","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-29T11:42:22.338219Z","iopub.execute_input":"2024-12-29T11:42:22.338557Z","iopub.status.idle":"2024-12-29T11:42:22.343348Z","shell.execute_reply.started":"2024-12-29T11:42:22.33853Z","shell.execute_reply":"2024-12-29T11:42:22.342015Z"}},"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')\nsubmission = pd.read_csv('/kaggle/input/playground-series-s4e12/sample_submission.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-29T11:42:26.986546Z","iopub.execute_input":"2024-12-29T11:42:26.987147Z","iopub.status.idle":"2024-12-29T11:42:37.716091Z","shell.execute_reply.started":"2024-12-29T11:42:26.987108Z","shell.execute_reply":"2024-12-29T11:42:37.715166Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# change dtype 'Policy Start Date' for preprosessing\ntrain = train.drop('id', axis=1)\ntrain['Policy Start Date'] = pd.to_datetime(train['Policy Start Date'])\ntrain.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-29T11:42:37.717165Z","iopub.execute_input":"2024-12-29T11:42:37.717488Z","iopub.status.idle":"2024-12-29T11:42:38.999245Z","shell.execute_reply.started":"2024-12-29T11:42:37.717461Z","shell.execute_reply":"2024-12-29T11:42:38.998203Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# change dtype 'Policy Start Date' for preprosessing\ntest['Policy Start Date'] = pd.to_datetime(test['Policy Start Date'])\ntest.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-29T11:42:39.000192Z","iopub.execute_input":"2024-12-29T11:42:39.000481Z","iopub.status.idle":"2024-12-29T11:42:39.830631Z","shell.execute_reply.started":"2024-12-29T11:42:39.000456Z","shell.execute_reply":"2024-12-29T11:42:39.829534Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Preprocessing","metadata":{}},{"cell_type":"markdown","source":"Make new class pycaret.regression.RegressionExperiment (https://pycaret.readthedocs.io/en/latest/api/regression.html#regression) for data preprocessing and models creation","metadata":{}},{"cell_type":"code","source":"from pycaret.regression import RegressionExperiment","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-29T11:42:22.345698Z","iopub.execute_input":"2024-12-29T11:42:22.346001Z","iopub.status.idle":"2024-12-29T11:42:26.985066Z","shell.execute_reply.started":"2024-12-29T11:42:22.345975Z","shell.execute_reply":"2024-12-29T11:42:26.984085Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"s = RegressionExperiment()\ns.setup(train, target = 'Premium Amount', normalize = True, normalize_method = 'minmax', session_id = 1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-29T11:42:39.831589Z","iopub.execute_input":"2024-12-29T11:42:39.831858Z","iopub.status.idle":"2024-12-29T11:43:24.102832Z","shell.execute_reply.started":"2024-12-29T11:42:39.831836Z","shell.execute_reply":"2024-12-29T11:43:24.10196Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"s.dataset_transformed","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-29T11:43:24.104734Z","iopub.execute_input":"2024-12-29T11:43:24.105435Z","iopub.status.idle":"2024-12-29T11:43:25.432524Z","shell.execute_reply.started":"2024-12-29T11:43:24.1054Z","shell.execute_reply":"2024-12-29T11:43:25.431544Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Choose models","metadata":{}},{"cell_type":"code","source":"best_model = s.compare_models(sort = 'RMSLE', fold=3)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-29T11:43:25.433826Z","iopub.execute_input":"2024-12-29T11:43:25.434241Z","iopub.status.idle":"2024-12-29T13:15:41.992286Z","shell.execute_reply.started":"2024-12-29T11:43:25.434203Z","shell.execute_reply":"2024-12-29T13:15:41.990971Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"par_model = s.create_model('par')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-29T13:29:28.609181Z","iopub.execute_input":"2024-12-29T13:29:28.609679Z","iopub.status.idle":"2024-12-29T13:30:54.566807Z","shell.execute_reply.started":"2024-12-29T13:29:28.609651Z","shell.execute_reply":"2024-12-29T13:30:54.565629Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Prediction","metadata":{}},{"cell_type":"code","source":"par_predictions = s.predict_model(par_model, data = test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-29T14:29:51.898111Z","iopub.execute_input":"2024-12-29T14:29:51.898691Z","iopub.status.idle":"2024-12-29T14:29:53.635423Z","shell.execute_reply.started":"2024-12-29T14:29:51.898661Z","shell.execute_reply":"2024-12-29T14:29:53.634347Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"par_predictions.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-29T14:30:19.844524Z","iopub.execute_input":"2024-12-29T14:30:19.844895Z","iopub.status.idle":"2024-12-29T14:30:19.873984Z","shell.execute_reply.started":"2024-12-29T14:30:19.844867Z","shell.execute_reply":"2024-12-29T14:30:19.872689Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Make submission","metadata":{}},{"cell_type":"code","source":"submission['Premium Amount'] = par_predictions['prediction_label']\n\nsubmission.to_csv('submission.csv', index=False)\n\nsubmission.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-29T14:32:25.226844Z","iopub.execute_input":"2024-12-29T14:32:25.227285Z","iopub.status.idle":"2024-12-29T14:32:26.889021Z","shell.execute_reply.started":"2024-12-29T14:32:25.227249Z","shell.execute_reply":"2024-12-29T14:32:26.887931Z"}},"outputs":[],"execution_count":null}]}