{"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"},{"sourceId":9178166,"sourceType":"datasetVersion","datasetId":5547076}],"dockerImageVersionId":30786,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# <p style=\"background-color:Skyblue; font-family:'Orbitron', sans-serif; color:black; font-size:140%; text-align:center; border: 1px solid black; border-radius:50px; padding: 15px; box-shadow: 5px 5px 20px rgba(0, 0, 0, 0.5); font-weight: bold; letter-spacing: 1px;\">RID || AbdBase</p>","metadata":{}},{"cell_type":"code","source":"%%time\n\nimport numpy as np\nimport polars as pl\nimport pandas as pd\n!pip install -qq pytorch_tabnet\nfrom tqdm import tqdm\nfrom IPython.display import clear_output\n\nimport warnings\nwarnings.filterwarnings('ignore')\npd.options.display.max_columns = None\n\nfrom sklearn.model_selection import *\nfrom sklearn.metrics import *","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2024-12-02T00:39:14.530252Z","iopub.execute_input":"2024-12-02T00:39:14.531147Z","iopub.status.idle":"2024-12-02T00:39:24.992092Z","shell.execute_reply.started":"2024-12-02T00:39:14.531085Z","shell.execute_reply":"2024-12-02T00:39:24.991148Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# <p style=\"background-color:Skyblue; font-family:'Orbitron', sans-serif; color:black; font-size:140%; text-align:center; border: 1px solid black; border-radius:50px; padding: 15px; box-shadow: 5px 5px 20px rgba(0, 0, 0, 0.5); font-weight: bold; letter-spacing: 1px;\">Basic PreProcessing Data</p>","metadata":{}},{"cell_type":"code","source":"%%time\n\n!git clone https://github.com/muhammadabdullah0303/AbdML\n\nimport sys\nsys.path.append('/kaggle/working/repository')\n\nfrom AbdML.main import AbdBase\n\ntrain = pd.read_csv('/kaggle/input/playground-series-s4e12/train.csv')\ntest = pd.read_csv('/kaggle/input/playground-series-s4e12/test.csv')\nsample = pd.read_csv('/kaggle/input/playground-series-s4e12/sample_submission.csv')\n\ntrain.drop('id', axis=1, inplace=True)\ntest.drop('id', axis=1, inplace=True) \n\ndef date(Df):\n\n    Df['Policy Start Date'] = pd.to_datetime(Df['Policy Start Date'])\n    Df['Year'] = Df['Policy Start Date'].dt.year\n    Df['Day'] = Df['Policy Start Date'].dt.day\n    Df['Month'] = Df['Policy Start Date'].dt.month\n    Df['Month_name'] = Df['Policy Start Date'].dt.month_name()\n    Df['Day_of_week'] = Df['Policy Start Date'].dt.day_name()\n    Df['Week'] = Df['Policy Start Date'].dt.isocalendar().week\n    Df['Year_sin'] = np.sin(2 * np.pi * Df['Year'])\n    Df['Year_cos'] = np.cos(2 * np.pi * Df['Year'])\n    min_year = Df['Year'].min()\n    max_year = Df['Year'].max()\n    Df['Year_sin'] = np.sin(2 * np.pi * (Df['Year'] - min_year) / (max_year - min_year))\n    Df['Year_cos'] = np.cos(2 * np.pi * (Df['Year'] - min_year) / (max_year - min_year))\n    Df['Month_sin'] = np.sin(2 * np.pi * Df['Month'] / 12) \n    Df['Month_cos'] = np.cos(2 * np.pi * Df['Month'] / 12)\n    Df['Day_sin'] = np.sin(2 * np.pi * Df['Day'] / 31)  \n    Df['Day_cos'] = np.cos(2 * np.pi * Df['Day'] / 31)\n    Df['Group']=(Df['Year']-2020)*48+Df['Month']*4+Df['Day']//7\n    \n    Df.drop('Policy Start Date', axis=1, inplace=True)\n\n    return Df\n\ntrain = date(train)\ntest = date(test)\n\ncat_c = [col for col in train.columns if train[col].dtype == 'object']\n\ndef update(df):\n    global cat_c\n\n    for c in cat_c:\n        df[c] = df[c].fillna('None').astype('category')\n                \n    return df\n\ntrain = update(train)\ntest = update(test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-02T00:39:24.994078Z","iopub.execute_input":"2024-12-02T00:39:24.994942Z","iopub.status.idle":"2024-12-02T00:39:46.95495Z","shell.execute_reply.started":"2024-12-02T00:39:24.994899Z","shell.execute_reply":"2024-12-02T00:39:46.953956Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%%time\n\ntrain.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-02T00:39:46.95616Z","iopub.execute_input":"2024-12-02T00:39:46.95645Z","iopub.status.idle":"2024-12-02T00:39:46.988338Z","shell.execute_reply.started":"2024-12-02T00:39:46.95642Z","shell.execute_reply":"2024-12-02T00:39:46.987512Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%%time\n\ntest.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-02T00:39:46.990252Z","iopub.execute_input":"2024-12-02T00:39:46.990569Z","iopub.status.idle":"2024-12-02T00:39:47.016626Z","shell.execute_reply.started":"2024-12-02T00:39:46.990538Z","shell.execute_reply":"2024-12-02T00:39:47.015616Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# <p style=\"background-color:Skyblue; font-family:'Orbitron', sans-serif; color:black; font-size:140%; text-align:center; border: 1px solid black; border-radius:50px; padding: 15px; box-shadow: 5px 5px 20px rgba(0, 0, 0, 0.5); font-weight: bold; letter-spacing: 1px;\">AbdBase || Baseline</p>","metadata":{}},{"cell_type":"code","source":"%%time\n\nSEED = 42\nn_splits = 10\n\nbase = AbdBase(train_data=train, test_data=test, target_column='Premium Amount',gpu=False,\n                 problem_type=\"regression\", metric=\"rmsle\", seed=SEED,\n                 n_splits=n_splits,early_stop=True,num_classes=0,\n                 fold_type='RSKF')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-02T00:39:47.017538Z","iopub.execute_input":"2024-12-02T00:39:47.017749Z","iopub.status.idle":"2024-12-02T00:39:47.086669Z","shell.execute_reply.started":"2024-12-02T00:39:47.017728Z","shell.execute_reply":"2024-12-02T00:39:47.085745Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%%time\n\nParams = {'n_estimators': 200,\"n_jobs\":-1}\n\nresults = base.Train_ML(Params,'LGBM',e_stop=40, y_log=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-02T00:39:47.0878Z","iopub.execute_input":"2024-12-02T00:39:47.088079Z","iopub.status.idle":"2024-12-02T00:41:43.380134Z","shell.execute_reply.started":"2024-12-02T00:39:47.088052Z","shell.execute_reply":"2024-12-02T00:41:43.379291Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%%time\n\nimport lightgbm as lgb\nimport matplotlib.pyplot as plt\n\nxModel = results[2] \nlgb.plot_importance(xModel, max_num_features=50, importance_type='split', figsize=(20, 10))\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-02T00:41:43.381062Z","iopub.execute_input":"2024-12-02T00:41:43.381377Z","iopub.status.idle":"2024-12-02T00:41:43.935506Z","shell.execute_reply.started":"2024-12-02T00:41:43.381339Z","shell.execute_reply":"2024-12-02T00:41:43.934652Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# <p style=\"background-color:Skyblue; font-family:'Orbitron', sans-serif; color:black; font-size:140%; text-align:center; border: 1px solid black; border-radius:50px; padding: 15px; box-shadow: 5px 5px 20px rgba(0, 0, 0, 0.5); font-weight: bold; letter-spacing: 1px;\">Submission</p>","metadata":{}},{"cell_type":"code","source":"%%time\n\nsample['Premium Amount'] = results[1] # test_preds\n\nsample.to_csv('submission.csv', index = False)\nsample.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-02T00:41:43.936614Z","iopub.execute_input":"2024-12-02T00:41:43.936889Z","iopub.status.idle":"2024-12-02T00:41:45.293217Z","shell.execute_reply.started":"2024-12-02T00:41:43.936861Z","shell.execute_reply":"2024-12-02T00:41:45.292313Z"}},"outputs":[],"execution_count":null}]}