{"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.11.13"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":116062,"databundleVersionId":14875579,"isSourceIdPinned":false,"sourceType":"competition"},{"sourceId":275639766,"sourceType":"kernelVersion"},{"sourceId":286136000,"sourceType":"kernelVersion"}],"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true},"papermill":{"default_parameters":{},"duration":964.000477,"end_time":"2025-12-14T13:58:15.442044","environment_variables":{},"exception":null,"input_path":"__notebook__.ipynb","output_path":"__notebook__.ipynb","parameters":{},"start_time":"2025-12-14T13:42:11.441567","version":"2.6.0"}},"nbformat_minor":4,"nbformat":4,"cells":[{"id":"8430c056","cell_type":"code","source":"# Imports\nimport pandas as pd\nimport numpy as np","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","execution":{"iopub.execute_input":"2025-12-14T13:42:16.824625Z","iopub.status.busy":"2025-12-14T13:42:16.824231Z","iopub.status.idle":"2025-12-14T13:42:18.899578Z","shell.execute_reply":"2025-12-14T13:42:18.897896Z"},"papermill":{"duration":2.081502,"end_time":"2025-12-14T13:42:18.901607","exception":false,"start_time":"2025-12-14T13:42:16.820105","status":"completed"},"tags":[]},"outputs":[],"execution_count":null},{"id":"8357add0","cell_type":"code","source":"# Ensemble weights\nWEIGHT_MODEL_A = 0.80\nWEIGHT_MODEL_B = 0.20\nDIVERSITY_BONUS = 0.05\nCONFIDENCE_THRESHOLD = 0.01","metadata":{"execution":{"iopub.execute_input":"2025-12-14T13:42:18.907573Z","iopub.status.busy":"2025-12-14T13:42:18.907134Z","iopub.status.idle":"2025-12-14T13:42:18.912455Z","shell.execute_reply":"2025-12-14T13:42:18.911476Z"},"papermill":{"duration":0.009897,"end_time":"2025-12-14T13:42:18.913969","exception":false,"start_time":"2025-12-14T13:42:18.904072","status":"completed"},"tags":[]},"outputs":[],"execution_count":null},{"id":"a0b4cf47","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":{"execution":{"iopub.execute_input":"2025-12-14T13:42:18.919349Z","iopub.status.busy":"2025-12-14T13:42:18.919069Z","iopub.status.idle":"2025-12-14T13:42:49.526778Z","shell.execute_reply":"2025-12-14T13:42:49.525786Z"},"papermill":{"duration":30.612537,"end_time":"2025-12-14T13:42:49.528629","exception":false,"start_time":"2025-12-14T13:42:18.916092","status":"completed"},"tags":[]},"outputs":[],"execution_count":null},{"id":"131e5c73","cell_type":"code","source":"# Load Model B\nmodel_b = pd.read_csv('/kaggle/input/esm2-cnn1d/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":{"execution":{"iopub.execute_input":"2025-12-14T13:42:49.534329Z","iopub.status.busy":"2025-12-14T13:42:49.533975Z","iopub.status.idle":"2025-12-14T13:43:05.480098Z","shell.execute_reply":"2025-12-14T13:43:05.478762Z"},"papermill":{"duration":15.951505,"end_time":"2025-12-14T13:43:05.482212","exception":false,"start_time":"2025-12-14T13:42:49.530707","status":"completed"},"tags":[]},"outputs":[],"execution_count":null},{"id":"43d35b67","cell_type":"code","source":"# Noise strength\nNOISE_LEVEL = 0.02\n\n# 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    # 🔥 Add small uniform noise\n    final_score += np.random.uniform(-NOISE_LEVEL, NOISE_LEVEL)\n    final_score = np.clip(final_score, 0, 1)\n\n    results.append({\n        'protein': protein,\n        'go_term': go_term,\n        'score': final_score\n    })\n\nensemble = pd.DataFrame(results)\n","metadata":{"execution":{"iopub.execute_input":"2025-12-14T13:43:05.487972Z","iopub.status.busy":"2025-12-14T13:43:05.487582Z","iopub.status.idle":"2025-12-14T13:54:12.560882Z","shell.execute_reply":"2025-12-14T13:54:12.559380Z"},"papermill":{"duration":667.078484,"end_time":"2025-12-14T13:54:12.562827","exception":false,"start_time":"2025-12-14T13:43:05.484343","status":"completed"},"tags":[]},"outputs":[],"execution_count":null},{"id":"783d55b7","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":{"execution":{"iopub.execute_input":"2025-12-14T13:54:12.568477Z","iopub.status.busy":"2025-12-14T13:54:12.568170Z","iopub.status.idle":"2025-12-14T13:58:09.891077Z","shell.execute_reply":"2025-12-14T13:58:09.888835Z"},"papermill":{"duration":237.328076,"end_time":"2025-12-14T13:58:09.893237","exception":false,"start_time":"2025-12-14T13:54:12.565161","status":"completed"},"tags":[]},"outputs":[],"execution_count":null}]}