{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Exponentially Weighted Ensemble with 5 Notebook Submissions\n\nThis is an exponentially weighted ensemble inspired by this https://www.kaggle.com/code/heyspaceturtle/beware-the-spaceturtles.\n\nNote: I simply fine-tuned b and commented the notebook.","metadata":{}},{"cell_type":"code","source":"# Importing Libraries\nimport numpy as np # Library for linear algebra\nimport pandas as pd # Library for dataframes","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-08-24T13:06:15.312223Z","iopub.execute_input":"2022-08-24T13:06:15.312697Z","iopub.status.idle":"2022-08-24T13:06:15.341263Z","shell.execute_reply.started":"2022-08-24T13:06:15.312606Z","shell.execute_reply":"2022-08-24T13:06:15.340289Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Defining Ensemble Parameters\nb = 3750.0 # Only meaningful hyperparameter to tune\nS = 0.7991 # Best submission score\nq = 0.0 # Sum of unnormalized weights","metadata":{"execution":{"iopub.status.busy":"2022-08-24T13:06:15.343318Z","iopub.execute_input":"2022-08-24T13:06:15.343698Z","iopub.status.idle":"2022-08-24T13:06:15.348974Z","shell.execute_reply.started":"2022-08-24T13:06:15.343665Z","shell.execute_reply":"2022-08-24T13:06:15.347817Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_submission = pd.read_csv('../input/amex-default-prediction/sample_submission.csv') # Reading the default placeholder submission\nfinal_submission.sort_values(by=['customer_ID'], inplace=True) # Sorting it by the customer ID","metadata":{"execution":{"iopub.status.busy":"2022-08-24T13:06:15.350497Z","iopub.execute_input":"2022-08-24T13:06:15.350821Z","iopub.status.idle":"2022-08-24T13:06:18.285248Z","shell.execute_reply.started":"2022-08-24T13:06:15.350791Z","shell.execute_reply":"2022-08-24T13:06:18.284114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Reading the submission file for 5 models\nsub1 = pd.read_csv('../input/amex-lgbm-dart-cv-0-7977/test_lgbm_baseline_5fold_seed_blend.csv')\nsub2 = pd.read_csv('../input/amex-lgbm-dart-cv-0-7963-improved/submission.csv')\nsub3 = pd.read_csv('../input/the-fine-art-of-hyperparameter-tuning/submission.csv')\nsub4 = pd.read_csv('../input/amex-features-the-best-of-both-worlds/submission.csv')\nsub5 = pd.read_csv('../input/overfitting-public-lb/submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-08-24T13:06:18.286768Z","iopub.execute_input":"2022-08-24T13:06:18.287199Z","iopub.status.idle":"2022-08-24T13:06:28.200585Z","shell.execute_reply.started":"2022-08-24T13:06:18.287159Z","shell.execute_reply":"2022-08-24T13:06:28.199373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Sorting them by the customer ID\nsub1.sort_values(by=['customer_ID'], inplace=True)\nsub2.sort_values(by=['customer_ID'], inplace=True)\nsub3.sort_values(by=['customer_ID'], inplace=True)\nsub4.sort_values(by=['customer_ID'], inplace=True)\nsub5.sort_values(by=['customer_ID'], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-24T13:06:28.205515Z","iopub.execute_input":"2022-08-24T13:06:28.205871Z","iopub.status.idle":"2022-08-24T13:06:30.966914Z","shell.execute_reply.started":"2022-08-24T13:06:28.205836Z","shell.execute_reply":"2022-08-24T13:06:30.965780Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Adding the prediction multiplied by the weights\nfinal_submission['prediction'] = sub1['prediction']*np.exp(b*(0.79905-S))\nfinal_submission['prediction'] += sub2['prediction']*np.exp(b*(0.79909-S))\nfinal_submission['prediction'] += sub3['prediction']*np.exp(b*(0.79909-S))\nfinal_submission['prediction'] += sub4['prediction']*np.exp(b*(0.79905-S))\nfinal_submission['prediction'] += sub5['prediction']*np.exp(b*(0.7991-S))","metadata":{"execution":{"iopub.status.busy":"2022-08-24T13:06:30.968491Z","iopub.execute_input":"2022-08-24T13:06:30.968911Z","iopub.status.idle":"2022-08-24T13:06:31.017459Z","shell.execute_reply.started":"2022-08-24T13:06:30.968879Z","shell.execute_reply":"2022-08-24T13:06:31.016320Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Calculating the sum of the unnormalized weights\nq += np.exp(b*(0.79905-S))\nq += np.exp(b*(0.79909-S))\nq += np.exp(b*(0.79909-S))\nq += np.exp(b*(0.79905-S))\nq += np.exp(b*(0.7991-S))","metadata":{"execution":{"iopub.status.busy":"2022-08-24T13:06:31.019351Z","iopub.execute_input":"2022-08-24T13:06:31.019933Z","iopub.status.idle":"2022-08-24T13:06:31.027422Z","shell.execute_reply.started":"2022-08-24T13:06:31.019888Z","shell.execute_reply":"2022-08-24T13:06:31.026383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_submission['prediction'] /= q # Normalizing the predictions\nfinal_submission.to_csv('submission.csv', index=False) # Uploading the predictions\nfinal_submission.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-24T13:06:31.028494Z","iopub.execute_input":"2022-08-24T13:06:31.029259Z","iopub.status.idle":"2022-08-24T13:06:34.299720Z","shell.execute_reply.started":"2022-08-24T13:06:31.029227Z","shell.execute_reply":"2022-08-24T13:06:34.298818Z"},"trusted":true},"execution_count":null,"outputs":[]}]}