{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":116062,"databundleVersionId":14084779,"isSourceIdPinned":false,"sourceType":"competition"},{"sourceId":13773523,"sourceType":"datasetVersion","datasetId":8764946},{"sourceId":268734519,"sourceType":"kernelVersion"},{"sourceId":274175765,"sourceType":"kernelVersion"},{"sourceId":275639766,"sourceType":"kernelVersion"}],"dockerImageVersionId":31192,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"### [CAFA 6 Protein Function Prediction](https://www.kaggle.com/competitions/cafa-6-protein-function-prediction/code?competitionId=116062&sortBy=scoreDescending&excludeNonAccessedDatasources=true)\n\nPredict the biological function of a protein\n\n&nbsp;\n\npublic solutions:\n\n| | | &nbsp; | | &nbsp; | &nbsp; | &nbsp; |\n|:-|:-| :-: | :-: | :-: | :-: | :-: |\n| A. | [0.337](https://www.kaggle.com/code/seddiktrk/cafa-6-blend-goa-negative-propagation?scriptVersionId=275639766) |&nbsp;v.3&nbsp;| [🧬 CAFA 6: Blend . GOA Negative Propagation](https://www.kaggle.com/code/seddiktrk/cafa-6-blend-goa-negative-propagation) | contributor | [seddik turki](https://www.kaggle.com/seddiktrk) | Tunisia |\n| B. | [0.203](https://www.kaggle.com/code/momerer/cafa-6-protein-function-prediction-with-1d-cnn) |&nbsp;v.4&nbsp;| [CAFA 6: Protein Function Prediction with 1D-CNN](https://www.kaggle.com/code/momerer/cafa-6-protein-function-prediction-with-1d-cnn?scriptVersionId=268550839) | contributor | [Muhammed Ömer ERKOÇ](https://www.kaggle.com/momerer) | Türkiye |\n| C. | [0.237](https://www.kaggle.com/code/amirrezaaleyasin/cafa-6-protein-function-starter-eda-model?scriptVersionId=274175765) |&nbsp;v.1&nbsp;| [CAFA 6 Protein Function: STARTER EDA + MODEL](https://www.kaggle.com/code/amirrezaaleyasin/cafa-6-protein-function-starter-eda-model) | contributor | [Amirreza Aleyasin](https://www.kaggle.com/amirrezaaleyasin) | World |\n|||||||\n| A+B. | [0.355](https://www.kaggle.com/code/liamarden/cafa-6-multi-model-blend-with-noise?scriptVersionId=278913152) |&nbsp;v.14&nbsp;| [CAFA 6 . Multi-Model Blend with noise](https://www.kaggle.com/code/liamarden/cafa-6-multi-model-blend-with-noise) | contributor | [Liam Arden](https://www.kaggle.com/liamarden) | World |\n| A+C. | [0.345](https://www.kaggle.com/code/tonylica/cafa-6-protein-function-prediction-0-345?scriptVersionId=278471612) |&nbsp;v.2&nbsp;| [CAFA 6 Protein Function Prediction 0.345](https://www.kaggle.com/code/tonylica/cafa-6-protein-function-prediction-0-345) | master | [Tony Li](https://www.kaggle.com/tonylica) | World |\n|||||||\n|||| **solutions** + **weights** | noise | **DB**, **CT** |\n|  | [0.342](https://www.kaggle.com/code/nina2025/cafa-6-protein-function-prediction?scriptVersionId=279098127) | v.6 | &nbsp;[ A + B + C ] . weights [ 0.80 +0.09 +0.01 ] != 100% |  0.0015 | [ 0.04, 0.007 ] |\n|||||||\n|  | [0.346](https://www.kaggle.com/code/nina2025/cafa-6-protein-function-prediction?scriptVersionId=279326945) | [v.7](#Version.7) | [ A + B + C ] . weights [[ 0.80 +0.19 +0.01 ](#Version.7)] &nbsp;= 100%| 0.0015 | [ 0.04, 0.007 ] |\n|  | [0.347](https://www.kaggle.com/code/nina2025/cafa-6-protein-function-prediction?scriptVersionId=279328271) | [v.8](#Version.8) | [ A + B + C ] . weights [[ 0.80 +0.15 +0.05 ](#Version.8)] &nbsp;= 100%| 0.0015 | [ 0.04, 0.007 ] |\n|  | [0.342](https://www.kaggle.com/code/nina2025/cafa-6-protein-function-prediction?scriptVersionId=279329869) | [v.9](#Version.8) | [ A + B + C ] . weights [[ 0.80 +0.10 +0.10 ](#Version.9)] &nbsp;= 100%| 0.0015 | [ 0.05, 0.01 ] |\n|||||||\n|  | [0.342](https://www.kaggle.com/code/nina2025/cafa-6-protein-function-prediction?scriptVersionId=279436680) | [v.10](#Version.10) | **[** [ A+B ] &nbsp;**+**&nbsp; C **]** . weights [[ 0.94 +0.06 ](#Version.10)] | absent | [ 0.05, 0.01 ] + [ 0.08, 0.013 ] |\n|||||||\n|  | [ 0.340 ](https://www.kaggle.com/code/nina2025/cafa-6-protein-function-prediction?scriptVersionId=279576605) | [v.11](#Version.11) | [ A + B + C ] . weights [[ 0.50 +0.20 +0.30 ](#Version.8)] | 0.00 | [ 0.00, 0.00 ] |\n|  | [ 0.342 ](https://www.kaggle.com/code/nina2025/cafa-6-protein-function-prediction?scriptVersionId=279972730) | [v.12](#Version.12) | [ A + B + C ] . weights [[ 0.50 +0.30 +0.20 ](#Version.8)] | 0.00 | [ 0.00, 0.00 ] |\n|  | [ 0.340 ](https://www.kaggle.com/code/nina2025/cafa-6-protein-function-prediction) | [v.13](#Version.13) | [ A + B + C ] . weights [[ 0.60 +0.30 +0.10 ](#Version.8)] | 0.00 | [ 0.00, 0.00 ] |\n|||||||\n|  | [ 0.339 ](https://www.kaggle.com/code/nina2025/cafa-6-protein-function-prediction?scriptVersionId=280071281) | [v.14](#Version.14) | [ A + B + C ] . weights [[ 0.80 +0.25 -0.05 ](#Version.14)] | - | - |\n|  | [ 0.338 ](https://www.kaggle.com/code/nina2025/cafa-6-protein-function-prediction?scriptVersionId=280075223) | [v.15](#Version.15) | [ A + B + C ] . weights [[ 0.85 +0.20 -0.05 ](#Version.15)] | - | - |\n|  | [ ? ](https://www.kaggle.com/code/nina2025/cafa-6-protein-function-prediction) | [v.16](#Version.16) | [ A + B + C ] . weights [[ 0.40 +0.33 +0.27 ](#Version.16)] | - | - |\n\n&nbsp;\n\n'Diversity bonuses ( **DB** )', 'confidences thresholds ( **CT** )', 'various **noises**', and so on - will not be used in this notebook.","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\n\npath = '/kaggle/input/'\n\ndef read_tsv(a,p=path):\n    df = pd.read_csv(p+a, sep='\\t', header=None, names=['protein','go_term','score'])\n    df['key']   = df['protein'] + '|' + df['go_term']\n    df['score'] = df['score'].clip(0, 1.0)\n    return df","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-18T12:37:44.323662Z","iopub.execute_input":"2025-11-18T12:37:44.324543Z","iopub.status.idle":"2025-11-18T12:37:44.662705Z","shell.execute_reply.started":"2025-11-18T12:37:44.324512Z","shell.execute_reply":"2025-11-18T12:37:44.662002Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model_A = read_tsv('cafa-6-blend-goa-negative-propagation/submission.tsv')\nmodel_B = read_tsv('cafa-6-protein-function-prediction-with-1d-cnn/submission.tsv')\nmodel_C = read_tsv('cafa-6-protein-function-starter-eda-model/submission.tsv')\n\nfeats = ['protein','go_term','score']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-15T16:50:41.400552Z","iopub.execute_input":"2025-11-15T16:50:41.400934Z","iopub.status.idle":"2025-11-15T16:51:09.358417Z","shell.execute_reply.started":"2025-11-15T16:50:41.400913Z","shell.execute_reply":"2025-11-15T16:51:09.35765Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"wts = [0.50, 0.20, 0.30]   # LB = 0.340\nwts = [0.50, 0.30, 0.20]   # LB = 0.342 \nwts = [0.60, 0.30, 0.10]   # LB = 0.340\n\nwts = [0.80, 0.25, -0.05]  # LB = 0.339\nwts = [0.85, 0.20, -0.05]  # LB = 0.338\n\nwts = [0.40, 0.33, 0.27]   # LB = ?","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"dict_A = dict(zip(model_A['key'], model_A['score']))\ndict_B = dict(zip(model_B['key'], model_B['score']))\ndict_C = dict(zip(model_C['key'], model_C['score']))\n\nall_keys =\\\n    set(model_A['key'].unique()) | \\\n    set(model_B['key'].unique()) | \\\n    set(model_C['key'].unique()) \n\n\nresults = []\n\nfor key in all_keys:\n    protein, go_term = key.split('|')\n    \n    scoreA,scoreB,scoreC = dict_A.get(key,0), dict_B.get(key,0), dict_C.get(key,0)\n    \n    weighted_score       = scoreA *wts[0]   + scoreB *wts[1]   + scoreC *wts[2]\n\n    clip_score           = np.clip(weighted_score, 0, 1)\n    \n    results.append(dict(zip(feats, [ protein, go_term, clip_score ] )))\n\n\nensemble = pd.DataFrame(results)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-15T16:51:19.910939Z","iopub.execute_input":"2025-11-15T16:51:19.911229Z","iopub.status.idle":"2025-11-15T16:54:49.501876Z","shell.execute_reply.started":"2025-11-15T16:51:19.911206Z","shell.execute_reply":"2025-11-15T16:54:49.500186Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"ensemble = ensemble.sort_values('score', ascending=False)  \n\nensemble [ feats ] .to_csv('submission.tsv', sep='\\t', index=False, header=False)\nensemble","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-15T16:54:49.503792Z","iopub.execute_input":"2025-11-15T16:54:49.504102Z","iopub.status.idle":"2025-11-15T16:56:39.266663Z","shell.execute_reply.started":"2025-11-15T16:54:49.504072Z","shell.execute_reply":"2025-11-15T16:56:39.26558Z"}},"outputs":[],"execution_count":null}]}