{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.10","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":41875,"databundleVersionId":5521661,"sourceType":"competition"},{"sourceId":5449416,"sourceType":"datasetVersion","datasetId":3150539},{"sourceId":5499219,"sourceType":"datasetVersion","datasetId":3167603}],"dockerImageVersionId":30497,"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\n\n\n# linear algebra\n# data processing, CSV file I/O (e.g. pd.read_csv)\nimport pandas as pd\nimport numpy as np\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\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","scrolled":true,"execution":{"iopub.status.busy":"2023-12-02T14:59:27.660941Z","iopub.execute_input":"2023-12-02T14:59:27.661426Z","iopub.status.idle":"2023-12-02T14:59:27.746188Z","shell.execute_reply.started":"2023-12-02T14:59:27.661385Z","shell.execute_reply":"2023-12-02T14:59:27.744959Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**CAFA 5 Protein Function Prediction with CNN TensorFLow**\n\n\nProtein Funtion\nProteins are fundamental molecules that play crucial roles in nearly all biological processes. They are involved in various functions, \nsuch as catalyzing chemical reactions, providing structural support, transporting molecules, signaling within cells, \nand regulating gene expression. Understanding protein function is essential for unraveling the complexities of biological systems and advancing fields like medicine, biotechnology, and drug discovery.\n\nProtein function refers to the specific roles and activities that proteins perform within living organisms.\nProteins are composed of amino acids, which are linked together in a specific sequence to form a linear chain.\nThe sequence of amino acids determines the protein's three-dimensional structure, and this structure, in turn, dictates its function.\n\n![](https://atomstalk.com/wp-content/uploads/2020/09/Proteins-consist-of-chains-of-amino-acids.jpg)","metadata":{}},{"cell_type":"markdown","source":"Machine learning (ML) models have emerged as powerful tools for protein function prediction. ML algorithms can analyze large datasets and extract patterns, enabling the prediction of protein functions based on known examples. These models leverage features such as protein sequence, structure, evolutionary information, and functional annotations to learn relationships and make predictions.\nprotein function prediction using ML models involves encoding protein data, extracting informative features, training ML models with labeled data, evaluating model performance, optimizing the models, and using them for predicting protein functions. These models have the potential to accelerate protein research, provide insights into biological processes, and facilitate the development of novel therapeutics and treatments.","metadata":{}},{"cell_type":"markdown","source":"**Note**: This notebook runs on distributed processing with limited or else depends on user requriments we can go with GPU utilization but there is some issuses with memory allocations even with without GPU run because we trained using convolutional neural network .but for that we use library called **\"DASK\"  memory-efficient computing**.provide memory-efficient alternatives to Pandas for working with large datasets. They enable distributed computing or lazy evaluation, which can help mitigate memory issues.","metadata":{}},{"cell_type":"code","source":"import tensorflow as tf\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom tensorflow.keras import layers\nfrom tensorflow.keras.layers import Dense,Flatten,Conv1D, GlobalMaxPooling1D,  Dropout\nfrom tensorflow.keras import Sequential\nimport progressbar\nfrom tensorflow import keras\nimport tensorflow as tf\nfrom tensorflow.keras.callbacks import ModelCheckpoint","metadata":{"execution":{"iopub.status.busy":"2023-12-02T14:59:42.673814Z","iopub.execute_input":"2023-12-02T14:59:42.674231Z","iopub.status.idle":"2023-12-02T14:59:54.285079Z","shell.execute_reply.started":"2023-12-02T14:59:42.674198Z","shell.execute_reply":"2023-12-02T14:59:54.283808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras import mixed_precision\nmixed_precision.set_global_policy('mixed_float16')\nfrom tensorflow.keras import backend as K\nK.clear_session()\n","metadata":{"execution":{"iopub.status.busy":"2023-12-02T14:59:54.28717Z","iopub.execute_input":"2023-12-02T14:59:54.287985Z","iopub.status.idle":"2023-12-02T14:59:54.326157Z","shell.execute_reply.started":"2023-12-02T14:59:54.287943Z","shell.execute_reply":"2023-12-02T14:59:54.324901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Amino Acids and Protein Sequences**\n\nEach protein or peptide consists of a linear sequence of amino acids. The protein primary structure conventionally begins at the amino-terminal (N) end and continues until the carboxyl-terminal (C) end. The structure of a protein may be directly sequenced or inferred from the sequence of DNA.\n\nThe amino acid sequence of a protein or peptide is useful information to understand the protein or peptide, identify it in a sample and categorize its post-translational modifications. The process of determining the amino acid sequence is known as protein sequencing.\n\n\n![](http://d2jx2rerrg6sh3.cloudfront.net/image-handler/ts/20170523082107/ri/673/picture/2017/5/DNA_translation_to_prtoein_680x_-_udaix.jpg)\n\n\n\n![](https://cnvrg.io/wp-content/uploads/2021/07/Deep-learning-for-Protein-Sequencing.jpg)","metadata":{}},{"cell_type":"markdown","source":"**Load Dataset**\n\nFirst we will load the file train_terms.tsv which contains the list of annotated terms (functions) for the proteins. We will extract the labels  GO term ID and create a label dataframe for the protein embeddings.\n","metadata":{}},{"cell_type":"code","source":"train_protein=pd.read_csv(\"/kaggle/input/cafa-5-protein-function-prediction/Train/train_terms.tsv\",sep=\"\\t\")\nprint(train_protein.shape,\"\\n\")\nprint(train_protein.head(5),\"\\n\")\n","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2023-12-02T14:59:54.327593Z","iopub.execute_input":"2023-12-02T14:59:54.327972Z","iopub.status.idle":"2023-12-02T14:59:58.2736Z","shell.execute_reply.started":"2023-12-02T14:59:54.327937Z","shell.execute_reply":"2023-12-02T14:59:58.272399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(train_protein[\"term\"].iloc[:5])\n","metadata":{"execution":{"iopub.status.busy":"2023-12-02T14:59:58.2756Z","iopub.execute_input":"2023-12-02T14:59:58.275958Z","iopub.status.idle":"2023-12-02T14:59:58.283363Z","shell.execute_reply.started":"2023-12-02T14:59:58.275925Z","shell.execute_reply":"2023-12-02T14:59:58.282023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Load Protein Embeddings**\n\nWe will now load the pre calculated protein embeddings created by Sergei Fironov using the Rost Lab's T5 protein language model.\n\nThe protein embeddings to be used for training are recorded in train_embeddings.npy and the corresponding protein ids are available in train_ids.npy.","metadata":{}},{"cell_type":"code","source":"train_ids=np.load(\"/kaggle/input/t5embeds/train_ids.npy\")\nprint(train_ids[:5])\nprint(train_ids.shape,\"\\n\")\n\nprint(\"------>train_embeddings---->\")\ntrain_embeddings=np.load(\"/kaggle/input/t5embeds/train_embeds.npy\")\nprint(train_embeddings[:3],\"\\n\")\nprint(train_embeddings.shape)","metadata":{"execution":{"iopub.status.busy":"2023-12-02T15:00:44.600127Z","iopub.execute_input":"2023-12-02T15:00:44.600569Z","iopub.status.idle":"2023-12-02T15:01:03.017286Z","shell.execute_reply.started":"2023-12-02T15:00:44.600537Z","shell.execute_reply":"2023-12-02T15:01:03.015977Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_embeddings.shape[1]\ntrain_df=pd.DataFrame(train_embeddings,columns=[\"Column\"+str(i) for i in range(1,train_embeddings.shape[1]+1)])\n\ntrain_df.head(3)","metadata":{"execution":{"iopub.status.busy":"2023-12-02T15:01:03.020257Z","iopub.execute_input":"2023-12-02T15:01:03.020813Z","iopub.status.idle":"2023-12-02T15:01:03.063316Z","shell.execute_reply.started":"2023-12-02T15:01:03.020765Z","shell.execute_reply":"2023-12-02T15:01:03.062002Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"check is there any duplicates presented in dataset ","metadata":{}},{"cell_type":"code","source":"df_duplicated = train_df[train_df.loc[:, train_df.columns != 'ID'].duplicated(keep=False)]\nprint(df_duplicated.shape[0],\"\\n\")\n\nnum_labels=1500\nlabels=train_protein[\"term\"].value_counts().index[:num_labels].tolist()\nprint(f\"number of labels ->{len(labels)}\")","metadata":{"execution":{"iopub.status.busy":"2023-12-02T15:01:03.064984Z","iopub.execute_input":"2023-12-02T15:01:03.065387Z","iopub.status.idle":"2023-12-02T15:01:45.669488Z","shell.execute_reply.started":"2023-12-02T15:01:03.06535Z","shell.execute_reply":"2023-12-02T15:01:45.668139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pie_df = train_protein['aspect'].value_counts()\npalette_color = sns.color_palette('bright')\nplt.pie(pie_df.values, labels=np.array(pie_df.index), colors=palette_color, autopct='%.0f%%')\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2023-12-02T15:01:45.672707Z","iopub.execute_input":"2023-12-02T15:01:45.673186Z","iopub.status.idle":"2023-12-02T15:01:46.226078Z","shell.execute_reply.started":"2023-12-02T15:01:45.673148Z","shell.execute_reply":"2023-12-02T15:01:46.224537Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\n# Fetch the train_terms data for the relevant labels only\ntrain_updated = train_protein.loc[train_protein['term'].isin(labels)]\n\n\n    ","metadata":{"execution":{"iopub.status.busy":"2023-12-02T15:01:46.228492Z","iopub.execute_input":"2023-12-02T15:01:46.229287Z","iopub.status.idle":"2023-12-02T15:01:46.923036Z","shell.execute_reply.started":"2023-12-02T15:01:46.22921Z","shell.execute_reply":"2023-12-02T15:01:46.921887Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"***Note***:this above code is taken by another notebook for reference","metadata":{}},{"cell_type":"code","source":"bar = progressbar.ProgressBar(maxval=num_labels, \\\n    widgets=[progressbar.Bar('=', '[', ']'), ' ', progressbar.Percentage()])\nbar.start()\n# Create an empty dataframe of required size for storing the labels,\n# i.e, train_size x num_of_labels (142246 x 1500)\ntrain_size = train_ids.shape[0] # len(X)\ntrain_labels = np.zeros((train_size ,num_labels))\n\n# Convert from numpy to pandas\n\n#series for better handling\nseries_train_protein_ids = pd.Series(train_ids)\n\n# Loop through each label\nfor i in range(num_labels):\n    # For each label, fetch the corresponding train_terms data\n    n_train_terms = train_updated[train_updated['term'] ==  labels[i]]\n    \n    # Fetch all the unique EntryId aka proteins related to the current label(GO term ID)\n    label_related_proteins = n_train_terms['EntryID'].unique()\n    \n    # In the series_train_protein_ids pandas series, if a protein is related\n    # to the current label, then mark it as 1, else 0.\n    # Replace the ith column of train_Y with with that pandas series.\n    train_labels[:,i] =  series_train_protein_ids.isin(label_related_proteins).astype(float)\n    \n    # Progress bar percentage increase\n    bar.update(i+1)\n\n# Notify the end of progress bar \nbar.finish()\n\n# Convert train_Y numpy into pandas dataframe\nlabels_df = pd.DataFrame(data = train_labels, columns = labels)\nprint(labels_df.shape)","metadata":{"execution":{"iopub.status.busy":"2023-12-02T15:01:46.925807Z","iopub.execute_input":"2023-12-02T15:01:46.926375Z","iopub.status.idle":"2023-12-02T15:10:30.051384Z","shell.execute_reply.started":"2023-12-02T15:01:46.926321Z","shell.execute_reply":"2023-12-02T15:10:30.050007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\"\"\"\nimport tensorflow as tf\ngpus = tf.config.experimental.list_physical_devices('GPU')\nif gpus:\n    try:\n        tf.config.experimental.set_virtual_device_configuration(gpus[0], [\n            tf.config.experimental.VirtualDeviceConfiguration(memory_limit=4096)])  # Limit GPU memory to 4GB\n    except RuntimeError as e:\n        print(e)\n\"\"\"","metadata":{"execution":{"iopub.status.busy":"2023-06-21T15:09:07.18959Z","iopub.execute_input":"2023-06-21T15:09:07.190026Z","iopub.status.idle":"2023-06-21T15:09:07.199005Z","shell.execute_reply.started":"2023-06-21T15:09:07.189986Z","shell.execute_reply":"2023-06-21T15:09:07.197804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\"\"\"\ncheckpoint_path = 'best_model_checkpoint.h5'\n\n# Define the ModelCheckpoint callback\ncheckpoint = ModelCheckpoint(checkpoint_path, monitor='val_loss', verbose=1, save_best_only=True, mode='min')\n\"\"\"","metadata":{"execution":{"iopub.status.busy":"2023-06-21T15:09:07.200389Z","iopub.execute_input":"2023-06-21T15:09:07.200778Z","iopub.status.idle":"2023-06-21T15:09:07.21251Z","shell.execute_reply.started":"2023-06-21T15:09:07.200749Z","shell.execute_reply":"2023-06-21T15:09:07.211443Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#concat train_df and labels_df into single dataframe for feeding to cnn-model\n# Combine the protein embeddings with the labels dataframe\n#train_data = pd.concat([train_df, labels_df], axis=1)","metadata":{"execution":{"iopub.status.busy":"2023-06-21T15:09:07.214034Z","iopub.execute_input":"2023-06-21T15:09:07.214422Z","iopub.status.idle":"2023-06-21T15:09:07.225689Z","shell.execute_reply.started":"2023-06-21T15:09:07.214392Z","shell.execute_reply":"2023-06-21T15:09:07.224416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Split the data into input features (X) and target labels (Y)\n#X = train_data.iloc[:, :-num_labels].values  # Input features (protein embeddings)\n\n#Y = train_data.iloc[:, -num_labels:].values #Target variables","metadata":{"execution":{"iopub.status.busy":"2023-06-21T15:09:07.227025Z","iopub.execute_input":"2023-06-21T15:09:07.22745Z","iopub.status.idle":"2023-06-21T15:09:07.245932Z","shell.execute_reply.started":"2023-06-21T15:09:07.227409Z","shell.execute_reply":"2023-06-21T15:09:07.244651Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#distributed training for easy training \n\"\"\"\nstrategy = tf.distribute.MirroredStrategy()\nwith strategy.scope():\n    mixed_precision.set_global_policy('mixed_float16')\n    #cnn model\n    model = Sequential()\n    model.add(Conv1D(filters=32, kernel_size=3, activation='relu', input_shape=(train_embeddings.shape[1], 1)))\n    model.add(GlobalMaxPooling1D())\n    model.add(Dense(64, activation='relu'))\n    model.add(Dropout(0.5))\n    model.add(Dense(num_labels, activation='sigmoid'))\n    model.compile( tf.keras.optimizers.Adam(learning_rate=1e-2),loss='binary_crossentropy',metrics=['accuracy'])\n    model.summary()\n    \"\"\"","metadata":{"execution":{"iopub.status.busy":"2023-06-21T15:09:07.24703Z","iopub.execute_input":"2023-06-21T15:09:07.247358Z","iopub.status.idle":"2023-06-21T15:09:07.261964Z","shell.execute_reply.started":"2023-06-21T15:09:07.247331Z","shell.execute_reply":"2023-06-21T15:09:07.260817Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\"\"\"# Reshape the input features to match the expected input shape of the CNN model\nX = X.reshape(X.shape[0], X.shape[1], 1)\nprint(X.shape)\n\"\"\"","metadata":{"execution":{"iopub.status.busy":"2023-06-21T15:09:07.263856Z","iopub.execute_input":"2023-06-21T15:09:07.264293Z","iopub.status.idle":"2023-06-21T15:09:07.276583Z","shell.execute_reply.started":"2023-06-21T15:09:07.264255Z","shell.execute_reply":"2023-06-21T15:09:07.275513Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\"\"\"history=model.fit(X, Y, batch_size=16, epochs=10, validation_split=0.2,callbacks=[checkpoint])\"\"\"","metadata":{"execution":{"iopub.status.busy":"2023-06-21T15:09:07.278017Z","iopub.execute_input":"2023-06-21T15:09:07.278329Z","iopub.status.idle":"2023-06-21T15:09:07.291239Z","shell.execute_reply.started":"2023-06-21T15:09:07.278304Z","shell.execute_reply":"2023-06-21T15:09:07.290336Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#history = pd.DataFrame(history.history)\n#history.loc[:, ['loss']].plot(title=\"Cross-entropy\")\n#history.loc[:, ['accuracy']].plot(title=\"Accuracy\")\n","metadata":{"execution":{"iopub.status.busy":"2023-06-21T15:09:07.292964Z","iopub.execute_input":"2023-06-21T15:09:07.293281Z","iopub.status.idle":"2023-06-21T15:09:07.305317Z","shell.execute_reply.started":"2023-06-21T15:09:07.293254Z","shell.execute_reply":"2023-06-21T15:09:07.304195Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#strategy = tf.distribute.MirroredStrategy()\n\n#with strategy.scope():\nmodel=tf.keras.Sequential([\n    keras.layers.BatchNormalization(input_shape=[train_df.shape[1]]),\n    keras.layers.Dense(1024,activation=\"relu\"),\n    keras.layers.Dense(512,activation=\"relu\"),\n    keras.layers.Dense(513,activation=\"relu\"),\n    keras.layers.Dense(512,activation=\"relu\"),\n        \n    keras.layers.Dense(num_labels,activation=\"sigmoid\")\n])","metadata":{"execution":{"iopub.status.busy":"2023-12-02T15:10:41.81386Z","iopub.execute_input":"2023-12-02T15:10:41.81433Z","iopub.status.idle":"2023-12-02T15:10:42.115373Z","shell.execute_reply.started":"2023-12-02T15:10:41.814294Z","shell.execute_reply":"2023-12-02T15:10:42.113928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nmodel.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.001),loss='binary_crossentropy',metrics=['binary_accuracy'])\nhistory=model.fit(train_df,labels_df,epochs=10,batch_size=5123,verbose=1)","metadata":{"execution":{"iopub.status.busy":"2023-12-02T15:10:44.027346Z","iopub.execute_input":"2023-12-02T15:10:44.028513Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.subplot(212)\nplt.plot(history.history[\"loss\"],label=\"training_loss\")\nplt.plot(history.history[\"accuracy\"],label=\"accuracy\")\nplt.legend()\nplt.title(\"loss and accuracy\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-06-21T15:10:25.799151Z","iopub.status.idle":"2023-06-21T15:10:25.800074Z","shell.execute_reply.started":"2023-06-21T15:10:25.799864Z","shell.execute_reply":"2023-06-21T15:10:25.799885Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras import backend as K\nK.clear_session()","metadata":{"execution":{"iopub.status.busy":"2023-06-21T15:10:25.801335Z","iopub.status.idle":"2023-06-21T15:10:25.802003Z","shell.execute_reply.started":"2023-06-21T15:10:25.801801Z","shell.execute_reply":"2023-06-21T15:10:25.801821Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\"\"\"\nsubmission_df = pd.read_csv('/kaggle/input/cafa-5-submission/submission.tsv',\n    sep='\\t', header=None)\n\n\nsubmission_df.to_csv('submission.tsv',\n    sep='\\t', header=False, index=False)\n    \"\"\"","metadata":{"execution":{"iopub.status.busy":"2023-06-21T15:10:25.803158Z","iopub.status.idle":"2023-06-21T15:10:25.80383Z","shell.execute_reply.started":"2023-06-21T15:10:25.803598Z","shell.execute_reply":"2023-06-21T15:10:25.803618Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df.head(10)","metadata":{"execution":{"iopub.status.busy":"2023-06-21T15:10:25.805466Z","iopub.status.idle":"2023-06-21T15:10:25.806138Z","shell.execute_reply.started":"2023-06-21T15:10:25.805937Z","shell.execute_reply":"2023-06-21T15:10:25.805957Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test=np.load(\"/kaggle/input/t5embeds/test_embeds.npy\")\nprint(test.shape)","metadata":{"execution":{"iopub.status.busy":"2023-06-21T15:10:25.807318Z","iopub.status.idle":"2023-06-21T15:10:25.807982Z","shell.execute_reply.started":"2023-06-21T15:10:25.807781Z","shell.execute_reply":"2023-06-21T15:10:25.807801Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.shape[1]\ntest_df=pd.DataFrame(test,columns=[\"Column\"+str(i) for i in range(1,test.shape[1]+1)])\nprint(test.shape,\"\\n\")\ntest_df.head(3)","metadata":{"execution":{"iopub.status.busy":"2023-06-21T15:10:25.809905Z","iopub.status.idle":"2023-06-21T15:10:25.810685Z","shell.execute_reply.started":"2023-06-21T15:10:25.810426Z","shell.execute_reply":"2023-06-21T15:10:25.810448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions=model.predict(test_df)\ntest_ids = np.load('/kaggle/input/t5embeds/test_ids.npy')","metadata":{"execution":{"iopub.status.busy":"2023-06-21T15:10:25.811924Z","iopub.status.idle":"2023-06-21T15:10:25.812578Z","shell.execute_reply.started":"2023-06-21T15:10:25.812378Z","shell.execute_reply":"2023-06-21T15:10:25.812398Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"    Since the predictions are probabilities for each label, you can choose a threshold to determine the predicted labels. For example, if a prediction probability is above a certain threshold (e.g., 0.5), you can consider it as a positive prediction for that label.\n\n    Convert the predictions into the appropriate format for submission. Assuming the submission requires the protein IDs along with the predicted labels, you can create a DataFrame with the protein IDs and the predicted labels:\n\n","metadata":{}},{"cell_type":"code","source":"submission = pd.DataFrame(columns = ['Protein Id', 'GO Term Id','Prediction'])\n\nlavel = []\nfor pred in list(test_ids):\n    lavel += [ pred] * predictions.shape[1]   \n\nsubmission['Protein Id'] = lavel\nsubmission['GO Term Id'] = labels * predictions.shape[0]\nsubmission['Prediction'] = predictions.ravel()\nsubmission.to_csv(\"submission.tsv\",header=False, index=False, sep=\"\\t\")","metadata":{"execution":{"iopub.status.busy":"2023-06-21T15:10:25.81382Z","iopub.status.idle":"2023-06-21T15:10:25.814465Z","shell.execute_reply.started":"2023-06-21T15:10:25.814266Z","shell.execute_reply":"2023-06-21T15:10:25.814285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.head()","metadata":{"execution":{"iopub.status.busy":"2023-06-21T15:10:25.8157Z","iopub.status.idle":"2023-06-21T15:10:25.816327Z","shell.execute_reply.started":"2023-06-21T15:10:25.816131Z","shell.execute_reply":"2023-06-21T15:10:25.81615Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The resulting CSV file, named 'submission.csv', will contain the protein IDs and the predicted labels based on the trained model's predictions","metadata":{}}]}