{"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":"# Ensembling: find the most frequent label for each sample from public notebooks\n\nThis notebook presents an automated ensembling using predicted results from the most relevant public notebooks. ","metadata":{"papermill":{"duration":0.008894,"end_time":"2021-12-31T14:48:41.466849","exception":false,"start_time":"2021-12-31T14:48:41.457955","status":"completed"},"tags":[]}},{"cell_type":"code","source":"import os\nimport numpy as np\nimport pandas as pd\nfrom scipy import stats\nimport plotly.express as px","metadata":{"papermill":{"duration":2.310801,"end_time":"2021-12-31T14:48:43.785659","exception":false,"start_time":"2021-12-31T14:48:41.474858","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-05-29T19:12:19.164568Z","iopub.execute_input":"2022-05-29T19:12:19.165274Z","iopub.status.idle":"2022-05-29T19:12:21.431156Z","shell.execute_reply.started":"2022-05-29T19:12:19.165178Z","shell.execute_reply":"2022-05-29T19:12:21.430186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"targetName = 'prediciton'\ncompetitionDir = '../input/amex-default-prediction'\nsubmission = pd.read_csv('../input/amex-default-prediction/sample_submission.csv')","metadata":{"papermill":{"duration":0.343502,"end_time":"2021-12-31T14:48:44.137086","exception":false,"start_time":"2021-12-31T14:48:43.793584","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-05-29T19:12:21.433226Z","iopub.execute_input":"2022-05-29T19:12:21.43364Z","iopub.status.idle":"2022-05-29T19:12:23.700881Z","shell.execute_reply.started":"2022-05-29T19:12:21.43356Z","shell.execute_reply":"2022-05-29T19:12:23.699975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import re\nregex = \"([^\\\\s]+(\\\\.(?i)(csv))$)\"\np = re.compile(regex)","metadata":{"execution":{"iopub.status.busy":"2022-05-29T19:12:23.70228Z","iopub.execute_input":"2022-05-29T19:12:23.702619Z","iopub.status.idle":"2022-05-29T19:12:23.709074Z","shell.execute_reply.started":"2022-05-29T19:12:23.702558Z","shell.execute_reply":"2022-05-29T19:12:23.707913Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds = []\n# for dirname, _, filenames in os.walk('/kaggle/input'):\n#     for filename in filenames:\n#         if (dirname != competitionDir) and (re.search(p, filename)):\n#             df = pd.read_csv(os.path.join(dirname, filename))\n#             preds.append(df[targetName]) ","metadata":{"papermill":{"duration":17.542154,"end_time":"2021-12-31T14:49:01.701331","exception":false,"start_time":"2021-12-31T14:48:44.159177","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-05-29T19:12:23.711652Z","iopub.execute_input":"2022-05-29T19:12:23.712215Z","iopub.status.idle":"2022-05-29T19:12:23.726022Z","shell.execute_reply.started":"2022-05-29T19:12:23.712169Z","shell.execute_reply":"2022-05-29T19:12:23.725163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nfrom sklearn.preprocessing import StandardScaler, LabelEncoder\nfrom scipy import stats\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-29T19:12:23.727203Z","iopub.execute_input":"2022-05-29T19:12:23.727553Z","iopub.status.idle":"2022-05-29T19:12:23.867052Z","shell.execute_reply.started":"2022-05-29T19:12:23.727524Z","shell.execute_reply":"2022-05-29T19:12:23.865877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('../input/amex-lightgbm-quickstart/submission.csv')\npreds.append((df['prediction']))\nprint(np.column_stack(preds).shape)\ndf2 = pd.read_csv('../input/amex-catboost-0-793/submission_cat_0.7887909351813577.csv')\npreds.append((df2['prediction']))\nprint(np.column_stack(preds).shape)\ndf3 = pd.read_csv('../input/fork-of-amex-lightgbm-quickstart/submission.csv')\npreds.append((df3['prediction']))\nprint(np.column_stack(preds).shape)\ndf4 = pd.read_csv('../input/lb-split-downsampling-trick-amex/submission.csv')\npreds.append(df4['prediction'])\ndf5 = pd.read_csv('../input/amex-lgbm-features-eng/submission.csv')\npreds.append((df5['prediction']))\ndf6 = pd.read_csv('../input/amex-lightautoml-starter/lightautoml_tabularautoml.csv')\npreds.append(df6['prediction'])\nprint(np.column_stack(preds).shape)","metadata":{"execution":{"iopub.status.busy":"2022-05-29T19:09:51.380401Z","iopub.execute_input":"2022-05-29T19:09:51.380921Z","iopub.status.idle":"2022-05-29T19:09:57.153699Z","shell.execute_reply.started":"2022-05-29T19:09:51.380888Z","shell.execute_reply":"2022-05-29T19:09:57.152628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\nblend_ss = submission.copy()\nblend_ss['prediction'] = (np.mean(np.column_stack(preds), axis=1))\nblend_ss.to_csv('submission.csv', index=False)\nblend_ss","metadata":{"execution":{"iopub.status.busy":"2022-05-29T19:09:57.15509Z","iopub.execute_input":"2022-05-29T19:09:57.155322Z","iopub.status.idle":"2022-05-29T19:10:02.677022Z","shell.execute_reply.started":"2022-05-29T19:09:57.15529Z","shell.execute_reply":"2022-05-29T19:10:02.676161Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# %%time\n# submission[targetName] = stats.mode(np.array(preds), axis=0)[0].transpose()\n# submission.to_csv(\"submission.csv\", index=False)","metadata":{"papermill":{"duration":2.10806,"end_time":"2021-12-31T14:49:03.831951","exception":false,"start_time":"2021-12-31T14:49:01.723891","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-05-29T19:08:27.939559Z","iopub.execute_input":"2022-05-29T19:08:27.940431Z","iopub.status.idle":"2022-05-29T19:08:27.944975Z","shell.execute_reply.started":"2022-05-29T19:08:27.940382Z","shell.execute_reply":"2022-05-29T19:08:27.943996Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# submission.head()","metadata":{"execution":{"iopub.status.busy":"2022-05-29T19:08:28.293899Z","iopub.execute_input":"2022-05-29T19:08:28.294219Z","iopub.status.idle":"2022-05-29T19:08:28.298206Z","shell.execute_reply.started":"2022-05-29T19:08:28.294183Z","shell.execute_reply":"2022-05-29T19:08:28.29762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# target_df = pd.DataFrame((blend_ss['prediction'].value_counts())).reset_index()\n# target_df.columns = [targetName, 'Log count']\n# fig = px.bar(data_frame = target_df, \n#              x = targetName,\n#              y = 'Log count' , \n#              color = \"Log count\",\n#              color_continuous_scale=\"Emrld\") \n# fig.show()","metadata":{"papermill":{"duration":1.381536,"end_time":"2021-12-31T14:49:05.236451","exception":false,"start_time":"2021-12-31T14:49:03.854915","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-05-29T19:08:52.920003Z","iopub.execute_input":"2022-05-29T19:08:52.920786Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# best = pd.read_csv('../input/sub-file/submission(1).csv')","metadata":{"execution":{"iopub.status.busy":"2022-02-15T18:29:44.601835Z","iopub.execute_input":"2022-02-15T18:29:44.602062Z","iopub.status.idle":"2022-02-15T18:29:44.606291Z","shell.execute_reply.started":"2022-02-15T18:29:44.602034Z","shell.execute_reply":"2022-02-15T18:29:44.605441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ne_stacked = (submission != best).stack()\n\n# changed = ne_stacked[ne_stacked]\n\n\n\n# changed.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T18:29:44.607777Z","iopub.execute_input":"2022-02-15T18:29:44.608009Z","iopub.status.idle":"2022-02-15T18:29:44.616281Z","shell.execute_reply.started":"2022-02-15T18:29:44.607981Z","shell.execute_reply":"2022-02-15T18:29:44.615571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}