{"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":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"%%capture\n!pip install -U lightautoml==0.3.8","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-01T17:23:44.367358Z","iopub.execute_input":"2024-12-01T17:23:44.367874Z","iopub.status.idle":"2024-12-01T17:26:34.261603Z","shell.execute_reply.started":"2024-12-01T17:23:44.367815Z","shell.execute_reply":"2024-12-01T17:26:34.259028Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Standard python libraries\nimport os\nimport time\nimport pickle\n\n# Essential DS libraries\nimport numpy as np\nimport pandas as pd\nimport torch\n\n# LightAutoML\nfrom lightautoml.automl.presets.tabular_presets import TabularAutoML, TabularUtilizedAutoML\nfrom lightautoml.tasks import Task\n\nimport warnings\nwarnings.filterwarnings('ignore')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-01T17:26:34.26497Z","iopub.execute_input":"2024-12-01T17:26:34.265437Z","iopub.status.idle":"2024-12-01T17:27:09.666145Z","shell.execute_reply.started":"2024-12-01T17:26:34.265389Z","shell.execute_reply":"2024-12-01T17:27:09.664935Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/playground-series-s4e12/train.csv')\nprint(df.shape)\ndf.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-01T17:27:16.442885Z","iopub.execute_input":"2024-12-01T17:27:16.443547Z","iopub.status.idle":"2024-12-01T17:27:23.516928Z","shell.execute_reply.started":"2024-12-01T17:27:16.443492Z","shell.execute_reply":"2024-12-01T17:27:23.515538Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# basic lightautoml parameters\nN_THREADS = 4\nN_FOLDS = 5 # for cross-validation\nRANDOM_STATE = 42\nTEST_SIZE = 0.2\nTARGET_NAME = 'Premium Amount'\n\ntask = Task('reg')\nroles = {\n    'target': TARGET_NAME,\n    'drop': 'id'\n}","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-01T17:27:54.294441Z","iopub.execute_input":"2024-12-01T17:27:54.294857Z","iopub.status.idle":"2024-12-01T17:27:54.302603Z","shell.execute_reply.started":"2024-12-01T17:27:54.29482Z","shell.execute_reply":"2024-12-01T17:27:54.301345Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"automl = TabularAutoML(\n    general_params = {'use_algos': ['lgb_tuned' ]}, # we use tuned LGBM\n    task = task, \n    cpu_limit = N_THREADS,\n    reader_params = {'n_jobs': N_THREADS, 'cv': N_FOLDS, 'random_state': RANDOM_STATE},\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-01T17:28:02.357539Z","iopub.execute_input":"2024-12-01T17:28:02.357989Z","iopub.status.idle":"2024-12-01T17:28:02.396717Z","shell.execute_reply.started":"2024-12-01T17:28:02.35795Z","shell.execute_reply":"2024-12-01T17:28:02.395406Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%%time \nout_of_fold_predictions = automl.fit_predict(df, roles = roles, verbose = 1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-01T17:29:19.508254Z","iopub.execute_input":"2024-12-01T17:29:19.509164Z","iopub.status.idle":"2024-12-01T17:41:14.888267Z","shell.execute_reply.started":"2024-12-01T17:29:19.509124Z","shell.execute_reply":"2024-12-01T17:41:14.886613Z"},"scrolled":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test = pd.read_csv('/kaggle/input/playground-series-s4e12/test.csv')\ntest_predictions = automl.predict(test).data # we get the results","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-01T17:42:16.728808Z","iopub.execute_input":"2024-12-01T17:42:16.729263Z","iopub.status.idle":"2024-12-01T17:43:52.367316Z","shell.execute_reply.started":"2024-12-01T17:42:16.729227Z","shell.execute_reply":"2024-12-01T17:43:52.366162Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pd.DataFrame({'id': test.id, TARGET_NAME: test_predictions.reshape(-1)}).to_csv('submission.csv', index=0)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-01T17:44:29.865241Z","iopub.execute_input":"2024-12-01T17:44:29.865963Z","iopub.status.idle":"2024-12-01T17:44:31.128785Z","shell.execute_reply.started":"2024-12-01T17:44:29.865898Z","shell.execute_reply":"2024-12-01T17:44:31.127238Z"}},"outputs":[],"execution_count":null}]}