{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"markdown","source":"This notebook uses two of my submission while one submission from below public notebook by Nitesh Chaudhry\nhttps://www.kaggle.com/niteshx2/full-pipeline-dual-input-cnn-model-with-tpus/output?select=effB1_512_5x15epochs_3Stratif.csv\n    \nHere I will be ranking the submissions and then blending them using weighted average.","execution_count":null},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"import pandas as pd","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Loading all the submission files**","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"sub_1 = pd.read_csv('../input/third-ensemble/effB1_512_5x15epochs_3Stratif.csv')\nsub_2 = pd.read_csv('../input/third-ensemble/submission_blending.csv')\nsub_3 = pd.read_csv('../input/third-ensemble/submission_blending_2.csv')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Function to rank data in each submission file**","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"def rank_data(sub):\n    sub['target'] = sub['target'].rank() / sub['target'].rank().max()\n    return sub","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sub_1 = rank_data(sub_1)\nsub_2 = rank_data(sub_2)\nsub_3 = rank_data(sub_3)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sub_1.columns = ['image_name', 'target1']\nsub_2.columns = ['image_name', 'target2']\nsub_3.columns = ['image_name', 'target3']","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Merge all the submission files using weighted average for target**","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"f_sub = sub_1.merge(sub_2, on = 'image_name').merge(sub_3, on ='image_name')\nf_sub['target'] = f_sub['target1'] * 0.6 + f_sub['target2'] * 0.2 + f_sub['target3'] * 0.2 ","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Generating the final submission file**","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"f_sub = f_sub[['image_name', 'target']]\nf_sub.to_csv('Finalblend_sub_3.csv', index = False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}