{"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_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# My EDA\n\nDo EDA on the CAFA 5 data","metadata":{"papermill":{"duration":0.008875,"end_time":"2023-05-09T08:30:09.052999","exception":false,"start_time":"2023-05-09T08:30:09.044124","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"# Import Libraries","metadata":{"papermill":{"duration":0.009086,"end_time":"2023-05-09T08:30:09.140473","exception":false,"start_time":"2023-05-09T08:30:09.131387","status":"completed"},"tags":[]}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport seaborn as sns\nimport matplotlib.pyplot as plt","metadata":{"papermill":{"duration":9.85331,"end_time":"2023-05-09T08:30:19.002985","exception":false,"start_time":"2023-05-09T08:30:09.149675","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-07-10T16:11:13.407054Z","iopub.execute_input":"2023-07-10T16:11:13.409257Z","iopub.status.idle":"2023-07-10T16:11:14.544351Z","shell.execute_reply.started":"2023-07-10T16:11:13.409226Z","shell.execute_reply":"2023-07-10T16:11:14.543105Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Load the train_terms Dataset","metadata":{"papermill":{"duration":0.008429,"end_time":"2023-05-09T08:30:19.047756","exception":false,"start_time":"2023-05-09T08:30:19.039327","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"First we will load the file `train_terms.tsv` which contains the list of annotated terms (functions) for the proteins. We will extract the labels aka `GO term ID` and create a label dataframe for the protein embeddings.","metadata":{"papermill":{"duration":0.008388,"end_time":"2023-05-09T08:30:19.065367","exception":false,"start_time":"2023-05-09T08:30:19.056979","status":"completed"},"tags":[]}},{"cell_type":"code","source":"train_terms = pd.read_csv(\"/kaggle/input/cafa-5-protein-function-prediction/Train/train_terms.tsv\",sep=\"\\t\")\nprint(train_terms.shape)","metadata":{"papermill":{"duration":3.69155,"end_time":"2023-05-09T08:30:22.766144","exception":false,"start_time":"2023-05-09T08:30:19.074594","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-07-10T16:11:14.54689Z","iopub.execute_input":"2023-07-10T16:11:14.54761Z","iopub.status.idle":"2023-07-10T16:11:19.574711Z","shell.execute_reply.started":"2023-07-10T16:11:14.547575Z","shell.execute_reply":"2023-07-10T16:11:19.573727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"`train_terms` dataframe is composed of 3 columns and 5363863 entries. We can see all 3 dimensions of our dataset by printing out the first 5 entries using the following code:","metadata":{"papermill":{"duration":0.008358,"end_time":"2023-05-09T08:30:22.783293","exception":false,"start_time":"2023-05-09T08:30:22.774935","status":"completed"},"tags":[]}},{"cell_type":"code","source":"train_terms.head()","metadata":{"papermill":{"duration":0.038607,"end_time":"2023-05-09T08:30:22.830633","exception":false,"start_time":"2023-05-09T08:30:22.792026","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-07-10T16:11:19.580736Z","iopub.execute_input":"2023-07-10T16:11:19.581434Z","iopub.status.idle":"2023-07-10T16:11:19.599984Z","shell.execute_reply.started":"2023-07-10T16:11:19.581393Z","shell.execute_reply":"2023-07-10T16:11:19.598934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"If we look at the first entry of `train_terms.tsv`, we can see that it contains protein id(`A0A009IHW8`), the GO term(`GO:0008152`) and its aspect(`BPO`). ","metadata":{"papermill":{"duration":0.008764,"end_time":"2023-05-09T08:30:22.848867","exception":false,"start_time":"2023-05-09T08:30:22.840103","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"# Look at the content of train_sequence.fasta","metadata":{}},{"cell_type":"code","source":"with open(\"/kaggle/input/cafa-5-protein-function-prediction/Train/train_sequences.fasta\", \"r\") as file:\n    fasta_100 = file.readlines()[:100]","metadata":{"execution":{"iopub.status.busy":"2023-07-10T16:11:19.601495Z","iopub.execute_input":"2023-07-10T16:11:19.601843Z","iopub.status.idle":"2023-07-10T16:11:20.956725Z","shell.execute_reply.started":"2023-07-10T16:11:19.601811Z","shell.execute_reply":"2023-07-10T16:11:20.955714Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fasta_100[:10]","metadata":{"execution":{"iopub.status.busy":"2023-07-10T16:11:20.957949Z","iopub.execute_input":"2023-07-10T16:11:20.958323Z","iopub.status.idle":"2023-07-10T16:11:20.965098Z","shell.execute_reply.started":"2023-07-10T16:11:20.958291Z","shell.execute_reply":"2023-07-10T16:11:20.963489Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Understand the fasta header: https://www.uniprot.org/help/fasta-headers","metadata":{}},{"cell_type":"markdown","source":"# Loading the protein embeddings\n\n\nWe will now load the pre calculated protein embeddings created by [Sergei Fironov](https://www.kaggle.com/sergeifironov) using the Rost Lab's T5 protein language model.\n\nIf the `tfembeds` is not yet on the input data of the notebook, you can add it to your enviromentby clicking on `Add Data` and search for `t5embeds` (make sure that it's the correct [one](https://www.kaggle.com/datasets/sergeifironov/t5embeds) ) and then click on the `+` beside it.\n\nThe protein embeddings to be used for training are recorded in `train_embeds.npy` and the corresponding protein ids are available in `train_ids.npy`.","metadata":{}},{"cell_type":"markdown","source":"First, we will load the protein ids of the protein embeddings in the train dataset contained in `train_ids.npy` into a numpy array.","metadata":{"papermill":{"duration":0.009256,"end_time":"2023-05-09T08:30:22.867158","exception":false,"start_time":"2023-05-09T08:30:22.857902","status":"completed"},"tags":[]}},{"cell_type":"code","source":"train_protein_ids = np.load('/kaggle/input/t5embeds/train_ids.npy')\nprint(train_protein_ids.shape)","metadata":{"papermill":{"duration":0.067806,"end_time":"2023-05-09T08:30:22.944355","exception":false,"start_time":"2023-05-09T08:30:22.876549","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-07-10T16:11:20.966597Z","iopub.execute_input":"2023-07-10T16:11:20.967334Z","iopub.status.idle":"2023-07-10T16:11:21.05574Z","shell.execute_reply.started":"2023-07-10T16:11:20.967298Z","shell.execute_reply":"2023-07-10T16:11:21.054712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The `train_protein_ids` array consists of 142246 protein_ids. Let us print out the first 5 entries using the following code:","metadata":{"papermill":{"duration":0.009498,"end_time":"2023-05-09T08:30:22.963291","exception":false,"start_time":"2023-05-09T08:30:22.953793","status":"completed"},"tags":[]}},{"cell_type":"code","source":"train_protein_ids[:5]","metadata":{"papermill":{"duration":0.019907,"end_time":"2023-05-09T08:30:22.992625","exception":false,"start_time":"2023-05-09T08:30:22.972718","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-07-10T16:11:21.057269Z","iopub.execute_input":"2023-07-10T16:11:21.05771Z","iopub.status.idle":"2023-07-10T16:11:21.06447Z","shell.execute_reply.started":"2023-07-10T16:11:21.057675Z","shell.execute_reply":"2023-07-10T16:11:21.063503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<!-- Now, we will load`train_embeds.py` which contains the pre-calculated embeddings of the proteins in the train dataset. with protein_ids (`id`s we loaded previously from the **train_ids.npy**) into a numpy array. This array now contains the precalculated embeddings for the protein_ids( Ids we loaded above from **train_ids.npy**) needed for training. -->\n\nAfter loading the files as numpy arrays, we will convert them into Pandas dataframe.\n\nEach protein embedding is a vector of length 1024. We create the resulting dataframe such that there are 1024 columns to represent the values in each of the 1024 places in the vector.","metadata":{"papermill":{"duration":0.009375,"end_time":"2023-05-09T08:30:23.011402","exception":false,"start_time":"2023-05-09T08:30:23.002027","status":"completed"},"tags":[]}},{"cell_type":"code","source":"train_embeddings = np.load('/kaggle/input/t5embeds/train_embeds.npy')\n\n# Now lets convert embeddings numpy array(train_embeddings) into pandas dataframe.\ncolumn_num = train_embeddings.shape[1]\ntrain_df = pd.DataFrame(train_embeddings, columns = [\"Column_\" + str(i) for i in range(1, column_num+1)])\nprint(train_df.shape)","metadata":{"papermill":{"duration":9.719957,"end_time":"2023-05-09T08:30:32.741095","exception":false,"start_time":"2023-05-09T08:30:23.021138","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-07-10T16:11:21.065962Z","iopub.execute_input":"2023-07-10T16:11:21.06692Z","iopub.status.idle":"2023-07-10T16:11:30.863126Z","shell.execute_reply.started":"2023-07-10T16:11:21.066887Z","shell.execute_reply":"2023-07-10T16:11:30.862078Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head()","metadata":{"papermill":{"duration":0.036828,"end_time":"2023-05-09T08:30:32.807222","exception":false,"start_time":"2023-05-09T08:30:32.770394","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-07-10T16:11:30.868548Z","iopub.execute_input":"2023-07-10T16:11:30.868839Z","iopub.status.idle":"2023-07-10T16:11:30.893256Z","shell.execute_reply.started":"2023-07-10T16:11:30.868812Z","shell.execute_reply":"2023-07-10T16:11:30.892268Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_terms.shape","metadata":{"execution":{"iopub.status.busy":"2023-07-10T16:11:30.894759Z","iopub.execute_input":"2023-07-10T16:11:30.895413Z","iopub.status.idle":"2023-07-10T16:11:30.902889Z","shell.execute_reply.started":"2023-07-10T16:11:30.895373Z","shell.execute_reply":"2023-07-10T16:11:30.901901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_terms['term'].nunique()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T16:11:30.904457Z","iopub.execute_input":"2023-07-10T16:11:30.905128Z","iopub.status.idle":"2023-07-10T16:11:31.387897Z","shell.execute_reply.started":"2023-07-10T16:11:30.905096Z","shell.execute_reply":"2023-07-10T16:11:31.386918Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's plot the most frequent 100 `GO Term ID`s in `train_terms.tsv`.","metadata":{"papermill":{"duration":0.009238,"end_time":"2023-05-09T08:30:32.863785","exception":false,"start_time":"2023-05-09T08:30:32.854547","status":"completed"},"tags":[]}},{"cell_type":"code","source":"train_terms.term.value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T16:11:31.389554Z","iopub.execute_input":"2023-07-10T16:11:31.390273Z","iopub.status.idle":"2023-07-10T16:11:32.199226Z","shell.execute_reply.started":"2023-07-10T16:11:31.390236Z","shell.execute_reply":"2023-07-10T16:11:32.198325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Select first 100 values for plotting\nplot_df = train_terms['term'].value_counts().iloc[:100]\n\nfigure, axis = plt.subplots(1, 1, figsize=(12, 6))\n\nbp = sns.barplot(ax=axis, x=np.array(plot_df.index), y=plot_df.values)\nbp.set_xticklabels(bp.get_xticklabels(), rotation=90, size = 6)\naxis.set_title('Top 100 frequent GO term IDs')\nbp.set_xlabel(\"GO term IDs\", fontsize = 12)\nbp.set_ylabel(\"Count\", fontsize = 12)\nplt.show()","metadata":{"papermill":{"duration":1.592489,"end_time":"2023-05-09T08:30:34.465912","exception":false,"start_time":"2023-05-09T08:30:32.873423","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-07-10T16:11:32.200625Z","iopub.execute_input":"2023-07-10T16:11:32.201224Z","iopub.status.idle":"2023-07-10T16:11:34.041465Z","shell.execute_reply.started":"2023-07-10T16:11:32.20119Z","shell.execute_reply":"2023-07-10T16:11:34.040543Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We will now extrac the top 1 GO term Id.","metadata":{"papermill":{"duration":0.010458,"end_time":"2023-05-09T08:30:34.487707","exception":false,"start_time":"2023-05-09T08:30:34.477249","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"Next, we will create a new dataframe by filtering the train terms with the selected `GO Term ID`.","metadata":{"papermill":{"duration":0.009833,"end_time":"2023-05-09T08:30:35.042088","exception":false,"start_time":"2023-05-09T08:30:35.032255","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"# Use random forest to classify proteins","metadata":{}},{"cell_type":"code","source":"train_terms.head()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T16:11:34.042894Z","iopub.execute_input":"2023-07-10T16:11:34.04349Z","iopub.status.idle":"2023-07-10T16:11:34.057333Z","shell.execute_reply.started":"2023-07-10T16:11:34.043442Z","shell.execute_reply":"2023-07-10T16:11:34.056225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# list of 10 most common proteins in the dataset\nno_labels = 10\ntop_10_label_list = train_terms.value_counts('term', ascending=False).index[:no_labels].tolist()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T16:11:34.058682Z","iopub.execute_input":"2023-07-10T16:11:34.059152Z","iopub.status.idle":"2023-07-10T16:11:34.72153Z","shell.execute_reply.started":"2023-07-10T16:11:34.059115Z","shell.execute_reply":"2023-07-10T16:11:34.720497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"top_10_label_list","metadata":{"execution":{"iopub.status.busy":"2023-07-10T16:11:34.724026Z","iopub.execute_input":"2023-07-10T16:11:34.724764Z","iopub.status.idle":"2023-07-10T16:11:34.730943Z","shell.execute_reply.started":"2023-07-10T16:11:34.724727Z","shell.execute_reply":"2023-07-10T16:11:34.730077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# if 'term' in 'train_terms' df is not in list then assign value '11' (for other)\ntrain_terms['label'] = train_terms['term'].apply(lambda x: top_10_label_list.index(x) if x in top_10_label_list else 11)\ntrain_terms.head()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T16:11:34.732615Z","iopub.execute_input":"2023-07-10T16:11:34.733295Z","iopub.status.idle":"2023-07-10T16:11:39.758822Z","shell.execute_reply.started":"2023-07-10T16:11:34.73326Z","shell.execute_reply":"2023-07-10T16:11:39.757914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# create an empty series of required size for storing the labels\n# train_labels = np.zeros((train_protein_ids.shape[0], 1))\ntrain_protein_ids_df = pd.DataFrame(train_protein_ids, columns=['EntryID'])\ntrain_terms_label_agg = train_terms.groupby('EntryID')['label'].agg(lambda x: list(set(x))).reset_index()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T16:11:39.76024Z","iopub.execute_input":"2023-07-10T16:11:39.76126Z","iopub.status.idle":"2023-07-10T16:11:45.27629Z","shell.execute_reply.started":"2023-07-10T16:11:39.761225Z","shell.execute_reply":"2023-07-10T16:11:45.275313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label_df = pd.merge(train_protein_ids_df, train_terms_label_agg, on='EntryID', how='inner')\n# label_df = list(label_df.loc[:,'label'])","metadata":{"execution":{"iopub.status.busy":"2023-07-10T16:11:45.277626Z","iopub.execute_input":"2023-07-10T16:11:45.277977Z","iopub.status.idle":"2023-07-10T16:11:45.426958Z","shell.execute_reply.started":"2023-07-10T16:11:45.277942Z","shell.execute_reply":"2023-07-10T16:11:45.425985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import MultiLabelBinarizer\nmlb = MultiLabelBinarizer()\nmlb.fit(label_df['label'])","metadata":{"execution":{"iopub.status.busy":"2023-07-10T16:11:45.428216Z","iopub.execute_input":"2023-07-10T16:11:45.428553Z","iopub.status.idle":"2023-07-10T16:11:45.562102Z","shell.execute_reply.started":"2023-07-10T16:11:45.428522Z","shell.execute_reply":"2023-07-10T16:11:45.560072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# transform label df into multilabel binary dataframe\nbinary_matrix = mlb.transform(label_df['label'])\nbinary_df = pd.DataFrame(binary_matrix, columns=mlb.classes_)\nbinary_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T16:11:45.563394Z","iopub.execute_input":"2023-07-10T16:11:45.564344Z","iopub.status.idle":"2023-07-10T16:11:46.049476Z","shell.execute_reply.started":"2023-07-10T16:11:45.564308Z","shell.execute_reply":"2023-07-10T16:11:46.048349Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\nfrom sklearn.multioutput import MultiOutputClassifier","metadata":{"execution":{"iopub.status.busy":"2023-07-10T16:11:46.051093Z","iopub.execute_input":"2023-07-10T16:11:46.051467Z","iopub.status.idle":"2023-07-10T16:11:46.450811Z","shell.execute_reply.started":"2023-07-10T16:11:46.051433Z","shell.execute_reply":"2023-07-10T16:11:46.449821Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rf_classifier = RandomForestClassifier(n_estimators=3)\nmulti_target_classifier = MultiOutputClassifier(rf_classifier)","metadata":{"execution":{"iopub.status.busy":"2023-07-10T16:11:46.452456Z","iopub.execute_input":"2023-07-10T16:11:46.452793Z","iopub.status.idle":"2023-07-10T16:11:46.458308Z","shell.execute_reply.started":"2023-07-10T16:11:46.45276Z","shell.execute_reply":"2023-07-10T16:11:46.456987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"multi_target_classifier.fit(train_df, binary_df)","metadata":{"execution":{"iopub.status.busy":"2023-07-10T16:11:46.459796Z","iopub.execute_input":"2023-07-10T16:11:46.460401Z","iopub.status.idle":"2023-07-10T16:15:37.922901Z","shell.execute_reply.started":"2023-07-10T16:11:46.460368Z","shell.execute_reply":"2023-07-10T16:15:37.921947Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pickle\nwith open('multi_target_classifier_model.pkl', 'wb') as file:\n    pickle.dump(multi_target_classifier, file)","metadata":{"execution":{"iopub.status.busy":"2023-07-10T16:15:37.924656Z","iopub.execute_input":"2023-07-10T16:15:37.925426Z","iopub.status.idle":"2023-07-10T16:15:38.019255Z","shell.execute_reply.started":"2023-07-10T16:15:37.92539Z","shell.execute_reply":"2023-07-10T16:15:38.018271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.shape","metadata":{"execution":{"iopub.status.busy":"2023-07-10T16:15:53.971433Z","iopub.execute_input":"2023-07-10T16:15:53.971795Z","iopub.status.idle":"2023-07-10T16:15:53.979314Z","shell.execute_reply.started":"2023-07-10T16:15:53.97176Z","shell.execute_reply":"2023-07-10T16:15:53.978266Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"binary_df.shape","metadata":{"execution":{"iopub.status.busy":"2023-07-10T16:15:57.398859Z","iopub.execute_input":"2023-07-10T16:15:57.39935Z","iopub.status.idle":"2023-07-10T16:15:57.414612Z","shell.execute_reply.started":"2023-07-10T16:15:57.399311Z","shell.execute_reply":"2023-07-10T16:15:57.412715Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Model evaluation","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Submission","metadata":{"papermill":{"duration":0.021665,"end_time":"2023-05-09T08:41:01.780867","exception":false,"start_time":"2023-05-09T08:41:01.759202","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"For submission we will use the protein embeddings of the test data created by [Sergei Fironov](https://www.kaggle.com/sergeifironov) using the Rost Lab's T5 protein language model.","metadata":{"papermill":{"duration":0.02075,"end_time":"2023-05-09T08:41:01.82296","exception":false,"start_time":"2023-05-09T08:41:01.80221","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"convert to submission: 141865 x 1500\n- why 1500?? last step output binary is 1500?","metadata":{}},{"cell_type":"code","source":"test_embeddings = np.load('/kaggle/input/t5embeds/test_embeds.npy')\n\n# Convert test_embeddings to dataframe\ncolumn_num = test_embeddings.shape[1]\ntest_df = pd.DataFrame(test_embeddings, columns = [\"Column_\" + str(i) for i in range(1, column_num+1)])\nprint(test_df.shape)","metadata":{"papermill":{"duration":10.290827,"end_time":"2023-05-09T08:41:12.134919","exception":false,"start_time":"2023-05-09T08:41:01.844092","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-07-05T17:01:47.742167Z","iopub.execute_input":"2023-07-05T17:01:47.742537Z","iopub.status.idle":"2023-07-05T17:01:58.229482Z","shell.execute_reply.started":"2023-07-05T17:01:47.742507Z","shell.execute_reply":"2023-07-05T17:01:58.228551Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The `test_df` is composed of 1024 columns and 141865 entries. We can see all 1024 dimensions(results will be truncated since column length is too long) of our dataset by printing out the first 5 entries using the following code:","metadata":{"papermill":{"duration":0.020857,"end_time":"2023-05-09T08:41:12.17776","exception":false,"start_time":"2023-05-09T08:41:12.156903","status":"completed"},"tags":[]}},{"cell_type":"code","source":"test_df.head()","metadata":{"papermill":{"duration":0.050123,"end_time":"2023-05-09T08:41:12.248732","exception":false,"start_time":"2023-05-09T08:41:12.198609","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-07-04T02:25:09.51869Z","iopub.execute_input":"2023-07-04T02:25:09.519219Z","iopub.status.idle":"2023-07-04T02:25:09.548641Z","shell.execute_reply.started":"2023-07-04T02:25:09.519181Z","shell.execute_reply":"2023-07-04T02:25:09.547469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We will now use the model to make predictions on the test embeddings. ","metadata":{}},{"cell_type":"code","source":"predictions =  multi_target_classifier.predict_proba(test_df)","metadata":{"papermill":{"duration":663.907351,"end_time":"2023-05-09T08:52:16.178461","exception":false,"start_time":"2023-05-09T08:41:12.27111","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-07-05T17:02:20.414364Z","iopub.execute_input":"2023-07-05T17:02:20.41542Z","iopub.status.idle":"2023-07-05T17:02:25.959047Z","shell.execute_reply.started":"2023-07-05T17:02:20.415372Z","shell.execute_reply":"2023-07-05T17:02:25.957962Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions","metadata":{"execution":{"iopub.status.busy":"2023-07-05T17:12:34.947471Z","iopub.execute_input":"2023-07-05T17:12:34.948286Z","iopub.status.idle":"2023-07-05T17:12:34.956582Z","shell.execute_reply.started":"2023-07-05T17:12:34.948256Z","shell.execute_reply":"2023-07-05T17:12:34.955591Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(predictions)","metadata":{"execution":{"iopub.status.busy":"2023-07-05T17:06:23.942745Z","iopub.execute_input":"2023-07-05T17:06:23.943095Z","iopub.status.idle":"2023-07-05T17:06:23.949116Z","shell.execute_reply.started":"2023-07-05T17:06:23.943066Z","shell.execute_reply":"2023-07-05T17:06:23.948181Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_submission = pd.DataFrame(columns = ['Protein Id', 'GO Term Id','Prediction'])\ntest_protein_ids = np.load('/kaggle/input/t5embeds/test_ids.npy')","metadata":{"execution":{"iopub.status.busy":"2023-06-28T20:55:17.959315Z","iopub.execute_input":"2023-06-28T20:55:17.959737Z","iopub.status.idle":"2023-06-28T20:55:18.023507Z","shell.execute_reply.started":"2023-06-28T20:55:17.9597Z","shell.execute_reply":"2023-06-28T20:55:18.022483Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_submission['Protein Id'] = test_protein_ids\ndf_submission['GO Term Id'] = 'GO:0005575'\ndf_submission['Prediction'] = predictions[:,1]","metadata":{"execution":{"iopub.status.busy":"2023-06-28T20:55:23.575241Z","iopub.execute_input":"2023-06-28T20:55:23.575611Z","iopub.status.idle":"2023-06-28T20:55:23.645731Z","shell.execute_reply.started":"2023-06-28T20:55:23.575578Z","shell.execute_reply":"2023-06-28T20:55:23.644787Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_submission","metadata":{"execution":{"iopub.status.busy":"2023-06-28T20:55:27.197777Z","iopub.execute_input":"2023-06-28T20:55:27.198131Z","iopub.status.idle":"2023-06-28T20:55:27.211792Z","shell.execute_reply.started":"2023-06-28T20:55:27.198098Z","shell.execute_reply":"2023-06-28T20:55:27.210573Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_submission.to_csv(\"submission.tsv\",header=False, index=False, sep=\"\\t\")","metadata":{"papermill":{"duration":0.063739,"end_time":"2023-05-09T08:52:16.292974","exception":false,"start_time":"2023-05-09T08:52:16.229235","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-06-28T20:57:39.605827Z","iopub.execute_input":"2023-06-28T20:57:39.606214Z","iopub.status.idle":"2023-06-28T20:57:40.216069Z","shell.execute_reply.started":"2023-06-28T20:57:39.60618Z","shell.execute_reply":"2023-06-28T20:57:40.215163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}