{"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"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":116062,"databundleVersionId":14084779,"sourceType":"competition"},{"sourceId":274175765,"sourceType":"kernelVersion"},{"sourceId":275639766,"sourceType":"kernelVersion"}],"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Imports\nimport pandas as pd\nimport numpy as np\n\n# Ensemble weights\nWEIGHT_MODEL_A = 0.90\nWEIGHT_MODEL_B = 0.10\nDIVERSITY_BONUS = 0.05\nCONFIDENCE_THRESHOLD = 0.01","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Load Model A\nmodel_a = pd.read_csv('/kaggle/input/cafa-6-blend-goa-negative-propagation/submission.tsv',\n                      sep='\\t', header=None, \n                      names=['protein', 'go_term', 'score'])\nmodel_a['key'] = model_a['protein'] + '|' + model_a['go_term']\nmodel_a['score'] = model_a['score'].clip(0, 1.0)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model_b = pd.read_csv('/kaggle/input/cafa-6-protein-function-starter-eda-model/submission.tsv',\n                      sep='\\t', header=None,\n                      names=['protein', 'go_term', 'score'])\nmodel_b['key'] = model_b['protein'] + '|' + model_b['go_term']\nmodel_b['score'] = model_b['score'].clip(0, 1.0)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Create Ensemble\ndict_a = dict(zip(model_a['key'], model_a['score']))\ndict_b = dict(zip(model_b['key'], model_b['score']))\n\nall_keys = set(model_a['key'].unique()) | set(model_b['key'].unique())\n\nresults = []\nfor key in all_keys:\n    protein, go_term = key.split('|')\n    \n    score_a = dict_a.get(key, 0)\n    score_b = dict_b.get(key, 0)\n    \n    weighted_score = (score_a * WEIGHT_MODEL_A + score_b * WEIGHT_MODEL_B)\n    \n    if score_a > 0 and score_b > 0:\n        final_score = min(weighted_score + DIVERSITY_BONUS, 1.0)\n    else:\n        final_score = weighted_score\n    \n    results.append({\n        'protein': protein,\n        'go_term': go_term,\n        'score': final_score\n    })\n\nensemble = pd.DataFrame(results)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Filter and Save\nensemble = ensemble.sort_values('score', ascending=False)\nensemble = ensemble[ensemble['score'] >= CONFIDENCE_THRESHOLD]\n\nensemble[['protein', 'go_term', 'score']].to_csv('submission.tsv', \n                                                   sep='\\t', \n                                                   index=False, \n                                                   header=False)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# second submiaaion","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# # https://www.kaggle.com/code/seddiktrk/cafa-6-blend-goa-negative-propagation\n# import pandas as pd","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# pd.read_csv('/kaggle/input/cafa-6-blend-goa-negative-propagation/submission.tsv',sep='\\t',header=None).to_csv('submission.tsv',sep='\\t',header=None,index=False)","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}