{"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":"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\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-07-13T18:54:31.594261Z","iopub.execute_input":"2023-07-13T18:54:31.594717Z","iopub.status.idle":"2023-07-13T18:54:31.639608Z","shell.execute_reply.started":"2023-07-13T18:54:31.594668Z","shell.execute_reply":"2023-07-13T18:54:31.638600Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_domains = pd.read_csv('/kaggle/input/domains/true_train_domains_12jul', sep=',')\ntest_domains = pd.read_csv('/kaggle/input/domains/true_test_domains_12jul',  sep=',')","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:02:39.706721Z","iopub.execute_input":"2023-07-13T20:02:39.707954Z","iopub.status.idle":"2023-07-13T20:03:13.381779Z","shell.execute_reply.started":"2023-07-13T20:02:39.707900Z","shell.execute_reply":"2023-07-13T20:03:13.380573Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_domains.pop('Unnamed: 0')\ntest_domains.pop('Unnamed: 0')","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:03:13.384127Z","iopub.execute_input":"2023-07-13T20:03:13.384499Z","iopub.status.idle":"2023-07-13T20:03:13.395709Z","shell.execute_reply.started":"2023-07-13T20:03:13.384469Z","shell.execute_reply":"2023-07-13T20:03:13.394466Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_domains","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:03:13.397337Z","iopub.execute_input":"2023-07-13T20:03:13.397777Z","iopub.status.idle":"2023-07-13T20:03:13.433223Z","shell.execute_reply.started":"2023-07-13T20:03:13.397732Z","shell.execute_reply":"2023-07-13T20:03:13.431738Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_domains","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:03:13.436371Z","iopub.execute_input":"2023-07-13T20:03:13.437175Z","iopub.status.idle":"2023-07-13T20:03:13.461475Z","shell.execute_reply.started":"2023-07-13T20:03:13.437138Z","shell.execute_reply":"2023-07-13T20:03:13.460137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"unique_trains = train_domains['domain_name'].unique().tolist()\nunique_test = test_domains['domain_name'].unique().tolist()","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:03:13.463035Z","iopub.execute_input":"2023-07-13T20:03:13.463455Z","iopub.status.idle":"2023-07-13T20:03:13.588280Z","shell.execute_reply.started":"2023-07-13T20:03:13.463421Z","shell.execute_reply":"2023-07-13T20:03:13.587230Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"common_popular_domains= []\nfor i in range(len(unique_test)):\n    if unique_test[i] in unique_trains:\n        common_popular_domains.append(unique_test[i])","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:03:13.590258Z","iopub.execute_input":"2023-07-13T20:03:13.591638Z","iopub.status.idle":"2023-07-13T20:03:13.921036Z","shell.execute_reply.started":"2023-07-13T20:03:13.591588Z","shell.execute_reply":"2023-07-13T20:03:13.919690Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(common_popular_domains)\n","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:03:13.922816Z","iopub.execute_input":"2023-07-13T20:03:13.924060Z","iopub.status.idle":"2023-07-13T20:03:13.932528Z","shell.execute_reply.started":"2023-07-13T20:03:13.924012Z","shell.execute_reply":"2023-07-13T20:03:13.931350Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"domain_name_num = train_domains['domain_name'].value_counts().to_frame()\npopular_domains_train= domain_name_num[domain_name_num['domain_name']>100].index.tolist()\ndomain_name_num2 = test_domains['domain_name'].value_counts().to_frame()\npopular_domains_test= domain_name_num2[domain_name_num2['domain_name']>59].index.tolist()","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:03:13.935068Z","iopub.execute_input":"2023-07-13T20:03:13.935879Z","iopub.status.idle":"2023-07-13T20:03:14.168868Z","shell.execute_reply.started":"2023-07-13T20:03:13.935832Z","shell.execute_reply":"2023-07-13T20:03:14.167566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"domain_name_num2.describe()","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:03:14.170259Z","iopub.execute_input":"2023-07-13T20:03:14.170581Z","iopub.status.idle":"2023-07-13T20:03:14.188955Z","shell.execute_reply.started":"2023-07-13T20:03:14.170554Z","shell.execute_reply":"2023-07-13T20:03:14.187700Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_domains_new = train_domains[train_domains['domain_name'].isin(popular_domains_train)]\ntest_domains_new = test_domains[test_domains['domain_name'].isin(popular_domains_test)]","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:03:14.193392Z","iopub.execute_input":"2023-07-13T20:03:14.193807Z","iopub.status.idle":"2023-07-13T20:03:14.406932Z","shell.execute_reply.started":"2023-07-13T20:03:14.193774Z","shell.execute_reply":"2023-07-13T20:03:14.405460Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## PCA","metadata":{}},{"cell_type":"code","source":"one_hot_train_domains = pd.get_dummies(train_domains_new, columns = ['domain_name'])","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:03:14.408569Z","iopub.execute_input":"2023-07-13T20:03:14.409018Z","iopub.status.idle":"2023-07-13T20:03:18.990597Z","shell.execute_reply.started":"2023-07-13T20:03:14.408977Z","shell.execute_reply":"2023-07-13T20:03:18.989301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"one_hot_train_domains.pop('seq_prot')\none_hot_train_domains.pop('Pf_id')\none_hot_train_domains.pop('coord')\none_hot_train_domains.pop('domain_seq')\none_hot_train_domains.pop('Pf_id2')\none_hot_train_domains.pop('domain_num2')\n","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:03:18.992613Z","iopub.execute_input":"2023-07-13T20:03:18.993086Z","iopub.status.idle":"2023-07-13T20:03:19.010667Z","shell.execute_reply.started":"2023-07-13T20:03:18.993052Z","shell.execute_reply":"2023-07-13T20:03:19.008796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"domains = list(set(one_hot_train_domains['id_prot'].tolist()))","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:03:19.012600Z","iopub.execute_input":"2023-07-13T20:03:19.013164Z","iopub.status.idle":"2023-07-13T20:03:19.056621Z","shell.execute_reply.started":"2023-07-13T20:03:19.013103Z","shell.execute_reply":"2023-07-13T20:03:19.053901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(domains)","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:03:19.058593Z","iopub.execute_input":"2023-07-13T20:03:19.059095Z","iopub.status.idle":"2023-07-13T20:03:19.071476Z","shell.execute_reply.started":"2023-07-13T20:03:19.059042Z","shell.execute_reply":"2023-07-13T20:03:19.070152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"one_hot_train_domains_ = pd.DataFrame()\nl=0\nfor i in range(10000, 120000, 10000):\n    data = one_hot_train_domains[one_hot_train_domains['id_prot'].isin(domains[l:i])]\n    l=i\n    data = data.groupby(['id_prot']).sum().reset_index()\n\n    one_hot_train_domains_ = pd.concat([one_hot_train_domains_, data])","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:03:19.074848Z","iopub.execute_input":"2023-07-13T20:03:19.075307Z","iopub.status.idle":"2023-07-13T20:03:35.482616Z","shell.execute_reply.started":"2023-07-13T20:03:19.075274Z","shell.execute_reply":"2023-07-13T20:03:35.481013Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"one_hot_train_domains_","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:03:35.485364Z","iopub.execute_input":"2023-07-13T20:03:35.485882Z","iopub.status.idle":"2023-07-13T20:03:35.568283Z","shell.execute_reply.started":"2023-07-13T20:03:35.485837Z","shell.execute_reply":"2023-07-13T20:03:35.566908Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#one_hot_train_domains2 = pd.get_dummies(train_domains_new, columns = ['domain_num2'])","metadata":{"execution":{"iopub.status.busy":"2023-07-13T18:55:34.071791Z","iopub.execute_input":"2023-07-13T18:55:34.072497Z","iopub.status.idle":"2023-07-13T18:55:39.971485Z","shell.execute_reply.started":"2023-07-13T18:55:34.072459Z","shell.execute_reply":"2023-07-13T18:55:39.969802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#one_hot_train_domains2","metadata":{"execution":{"iopub.status.busy":"2023-07-13T18:55:39.973993Z","iopub.execute_input":"2023-07-13T18:55:39.974418Z","iopub.status.idle":"2023-07-13T18:55:40.327416Z","shell.execute_reply.started":"2023-07-13T18:55:39.974387Z","shell.execute_reply":"2023-07-13T18:55:40.325615Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#domains = list(set(one_hot_train_domains['id_prot'].tolist()))","metadata":{"execution":{"iopub.status.busy":"2023-07-13T18:55:40.347820Z","iopub.status.idle":"2023-07-13T18:55:40.348490Z","shell.execute_reply.started":"2023-07-13T18:55:40.348174Z","shell.execute_reply":"2023-07-13T18:55:40.348204Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#one_hot_train_domains2.pop('seq_prot')\n#one_hot_train_domains2.pop('Pf_id')\n#one_hot_train_domains2.pop('coord')\n#one_hot_train_domains2.pop('domain_seq')\n#one_hot_train_domains2.pop('Pf_id2')\n#one_hot_train_domains2.pop('domain_name')\n","metadata":{"execution":{"iopub.status.busy":"2023-07-13T19:10:13.980927Z","iopub.execute_input":"2023-07-13T19:10:13.981618Z","iopub.status.idle":"2023-07-13T19:10:14.000408Z","shell.execute_reply.started":"2023-07-13T19:10:13.981553Z","shell.execute_reply":"2023-07-13T19:10:13.999079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"one_hot_train_domains_2 = pd.DataFrame()\nl=0\nfor i in range(10000, 120000, 10000):\n    data = one_hot_train_domains2[one_hot_train_domains2['id_prot'].isin(domains[l:i])]\n    l=i\n    data = data.groupby(['id_prot']).sum().reset_index()\n\n    one_hot_train_domains_2 = pd.concat([one_hot_train_domains_2, data])","metadata":{"execution":{"iopub.status.busy":"2023-07-13T19:10:14.308896Z","iopub.execute_input":"2023-07-13T19:10:14.309307Z","iopub.status.idle":"2023-07-13T19:10:37.449650Z","shell.execute_reply.started":"2023-07-13T19:10:14.309274Z","shell.execute_reply":"2023-07-13T19:10:37.448190Z"}}},{"cell_type":"code","source":"#one_hot_train_domains_2","metadata":{"execution":{"iopub.status.busy":"2023-07-13T19:10:37.452016Z","iopub.execute_input":"2023-07-13T19:10:37.452418Z","iopub.status.idle":"2023-07-13T19:10:37.498049Z","shell.execute_reply.started":"2023-07-13T19:10:37.452384Z","shell.execute_reply":"2023-07-13T19:10:37.496436Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#one_hot_train_domains_2 = one_hot_train_domains_2.sort_values(['id_prot'], ascending=(True))\n#one_hot_train_domains_2","metadata":{"execution":{"iopub.status.busy":"2023-07-13T19:10:37.499862Z","iopub.execute_input":"2023-07-13T19:10:37.500275Z","iopub.status.idle":"2023-07-13T19:10:38.522654Z","shell.execute_reply.started":"2023-07-13T19:10:37.500233Z","shell.execute_reply":"2023-07-13T19:10:38.521149Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"one_hot_train_domains_ = one_hot_train_domains_.sort_values(['id_prot'], ascending=(True))\none_hot_train_domains_","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:04:25.866766Z","iopub.execute_input":"2023-07-13T20:04:25.867248Z","iopub.status.idle":"2023-07-13T20:04:27.660950Z","shell.execute_reply.started":"2023-07-13T20:04:25.867213Z","shell.execute_reply":"2023-07-13T20:04:27.659511Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#one_hot_train_domains_new = one_hot_train_domains_2.merge(one_hot_train_domains_, on='id_prot', how='right')\n","metadata":{"execution":{"iopub.status.busy":"2023-07-13T18:55:40.364470Z","iopub.status.idle":"2023-07-13T18:55:40.366161Z","shell.execute_reply.started":"2023-07-13T18:55:40.365895Z","shell.execute_reply":"2023-07-13T18:55:40.365924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#one_hot_train_domains_new","metadata":{"execution":{"iopub.status.busy":"2023-07-13T18:55:40.367855Z","iopub.status.idle":"2023-07-13T18:55:40.368338Z","shell.execute_reply.started":"2023-07-13T18:55:40.368125Z","shell.execute_reply":"2023-07-13T18:55:40.368146Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"one_hot_train_domains_","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:05:28.466664Z","iopub.execute_input":"2023-07-13T20:05:28.467073Z","iopub.status.idle":"2023-07-13T20:05:28.528730Z","shell.execute_reply.started":"2023-07-13T20:05:28.467043Z","shell.execute_reply":"2023-07-13T20:05:28.527233Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cols = one_hot_train_domains_.columns","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:05:06.210196Z","iopub.execute_input":"2023-07-13T20:05:06.210658Z","iopub.status.idle":"2023-07-13T20:05:06.217609Z","shell.execute_reply.started":"2023-07-13T20:05:06.210624Z","shell.execute_reply":"2023-07-13T20:05:06.215857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cols = cols.tolist()","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:05:06.412384Z","iopub.execute_input":"2023-07-13T20:05:06.413374Z","iopub.status.idle":"2023-07-13T20:05:06.418402Z","shell.execute_reply.started":"2023-07-13T20:05:06.413336Z","shell.execute_reply":"2023-07-13T20:05:06.416977Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(cols)","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:05:07.522057Z","iopub.execute_input":"2023-07-13T20:05:07.522538Z","iopub.status.idle":"2023-07-13T20:05:07.529947Z","shell.execute_reply.started":"2023-07-13T20:05:07.522501Z","shell.execute_reply":"2023-07-13T20:05:07.528775Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(10000, 85000, 10000):\n    print(i)","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:05:08.673838Z","iopub.execute_input":"2023-07-13T20:05:08.675401Z","iopub.status.idle":"2023-07-13T20:05:08.681222Z","shell.execute_reply.started":"2023-07-13T20:05:08.675343Z","shell.execute_reply":"2023-07-13T20:05:08.680249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"one_hot_train_domains_.pop('id_prot')","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:06:03.338583Z","iopub.execute_input":"2023-07-13T20:06:03.339126Z","iopub.status.idle":"2023-07-13T20:06:03.352863Z","shell.execute_reply.started":"2023-07-13T20:06:03.339084Z","shell.execute_reply":"2023-07-13T20:06:03.351175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.decomposition import PCA\nnew_features = pd.DataFrame()\nl=0\nfor i in range(10000, 85000, 10000):\n    pca = PCA(n_components=300)\n    pca_features = pca.fit_transform(one_hot_train_domains_[l:i])\n    l=i\n    pca_features=pd.DataFrame(pca_features)\n    new_features = pd.concat([new_features, pca_features])","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:06:05.600922Z","iopub.execute_input":"2023-07-13T20:06:05.601730Z","iopub.status.idle":"2023-07-13T20:06:36.986878Z","shell.execute_reply.started":"2023-07-13T20:06:05.601642Z","shell.execute_reply":"2023-07-13T20:06:36.985275Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_features.to_csv('pca_features_for_train')","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:06:36.989919Z","iopub.execute_input":"2023-07-13T20:06:36.990449Z","iopub.status.idle":"2023-07-13T20:07:36.842774Z","shell.execute_reply.started":"2023-07-13T20:06:36.990399Z","shell.execute_reply":"2023-07-13T20:07:36.841097Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_features","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:07:36.844857Z","iopub.execute_input":"2023-07-13T20:07:36.846316Z","iopub.status.idle":"2023-07-13T20:07:36.895746Z","shell.execute_reply.started":"2023-07-13T20:07:36.846260Z","shell.execute_reply":"2023-07-13T20:07:36.894365Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Target data","metadata":{}},{"cell_type":"code","source":"fn = '/kaggle/input/t5embeds/train_ids.npy'\nvec_train_protein_ids = np.load(fn)\nprint(vec_train_protein_ids.shape)\nvec_train_protein_ids","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:07:36.900242Z","iopub.execute_input":"2023-07-13T20:07:36.900859Z","iopub.status.idle":"2023-07-13T20:07:36.973333Z","shell.execute_reply.started":"2023-07-13T20:07:36.900806Z","shell.execute_reply":"2023-07-13T20:07:36.971971Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fn = '/kaggle/input/baseline-multilabel-to-multitarget-binary/Y_1499.npy'\n\nY = np.load(fn)\nprint(Y.shape)\nY = pd.DataFrame(Y)\nY","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:07:36.975268Z","iopub.execute_input":"2023-07-13T20:07:36.976236Z","iopub.status.idle":"2023-07-13T20:07:39.779168Z","shell.execute_reply.started":"2023-07-13T20:07:36.976163Z","shell.execute_reply":"2023-07-13T20:07:39.777788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y.insert (loc= 0 , column='id_prot', value=vec_train_protein_ids)\nY","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:07:39.781142Z","iopub.execute_input":"2023-07-13T20:07:39.781625Z","iopub.status.idle":"2023-07-13T20:07:40.009662Z","shell.execute_reply.started":"2023-07-13T20:07:39.781579Z","shell.execute_reply":"2023-07-13T20:07:40.006881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Load train features - precalculated embeddings for the proteins\n","metadata":{}},{"cell_type":"markdown","source":"fn = '/kaggle/input/t5embeds/train_embeds.npy'\n\nX = np.load(fn)\nprint(X.shape)\nX_frame = pd.DataFrame(X)","metadata":{"execution":{"iopub.status.busy":"2023-07-13T18:55:40.403954Z","iopub.status.idle":"2023-07-13T18:55:40.404436Z","shell.execute_reply.started":"2023-07-13T18:55:40.404222Z","shell.execute_reply":"2023-07-13T18:55:40.404243Z"}}},{"cell_type":"markdown","source":"X_frame.insert (loc= 0 , column='id_prot', value=vec_train_protein_ids)\nX_frame","metadata":{"execution":{"iopub.status.busy":"2023-07-13T18:55:40.406338Z","iopub.status.idle":"2023-07-13T18:55:40.407319Z","shell.execute_reply.started":"2023-07-13T18:55:40.407082Z","shell.execute_reply":"2023-07-13T18:55:40.407107Z"}}},{"cell_type":"code","source":"len(domains)","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:07:59.427504Z","iopub.execute_input":"2023-07-13T20:07:59.428123Z","iopub.status.idle":"2023-07-13T20:07:59.438328Z","shell.execute_reply.started":"2023-07-13T20:07:59.428064Z","shell.execute_reply":"2023-07-13T20:07:59.436539Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y_new = Y[Y['id_prot'].isin(domains)]\nY_new","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:08:00.987299Z","iopub.execute_input":"2023-07-13T20:08:00.987708Z","iopub.status.idle":"2023-07-13T20:08:01.590239Z","shell.execute_reply.started":"2023-07-13T20:08:00.987662Z","shell.execute_reply":"2023-07-13T20:08:01.589284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y_new =  Y_new.sort_values(['id_prot'], ascending=(True))\nY_new","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:08:03.080402Z","iopub.execute_input":"2023-07-13T20:08:03.080858Z","iopub.status.idle":"2023-07-13T20:08:03.996515Z","shell.execute_reply.started":"2023-07-13T20:08:03.080827Z","shell.execute_reply":"2023-07-13T20:08:03.994833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"X_frame_new = X_frame[X_frame['id_prot'].isin(domains)]\nX_frame_new","metadata":{"execution":{"iopub.status.busy":"2023-07-13T18:55:40.414370Z","iopub.status.idle":"2023-07-13T18:55:40.414801Z","shell.execute_reply.started":"2023-07-13T18:55:40.414573Z","shell.execute_reply":"2023-07-13T18:55:40.414592Z"}}},{"cell_type":"markdown","source":"X_frame_new =  X_frame_new.sort_values(['id_prot'], ascending=(True))\nX_frame_new","metadata":{"execution":{"iopub.status.busy":"2023-07-13T18:55:40.415749Z","iopub.status.idle":"2023-07-13T18:55:40.416116Z","shell.execute_reply.started":"2023-07-13T18:55:40.415936Z","shell.execute_reply":"2023-07-13T18:55:40.415954Z"}}},{"cell_type":"code","source":"Y_new.pop('id_prot')\n","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:08:21.245715Z","iopub.execute_input":"2023-07-13T20:08:21.247538Z","iopub.status.idle":"2023-07-13T20:08:21.261615Z","shell.execute_reply.started":"2023-07-13T20:08:21.247480Z","shell.execute_reply":"2023-07-13T20:08:21.260210Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_features","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:08:38.145200Z","iopub.execute_input":"2023-07-13T20:08:38.145734Z","iopub.status.idle":"2023-07-13T20:08:38.188367Z","shell.execute_reply.started":"2023-07-13T20:08:38.145667Z","shell.execute_reply":"2023-07-13T20:08:38.186964Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = new_features.to_numpy()","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:08:57.971710Z","iopub.execute_input":"2023-07-13T20:08:57.972199Z","iopub.status.idle":"2023-07-13T20:08:57.978887Z","shell.execute_reply.started":"2023-07-13T20:08:57.972148Z","shell.execute_reply":"2023-07-13T20:08:57.977570Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y= Y_new.to_numpy()\n","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:09:03.963455Z","iopub.execute_input":"2023-07-13T20:09:03.963984Z","iopub.status.idle":"2023-07-13T20:09:03.969905Z","shell.execute_reply.started":"2023-07-13T20:09:03.963941Z","shell.execute_reply":"2023-07-13T20:09:03.968507Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:09:08.621279Z","iopub.execute_input":"2023-07-13T20:09:08.621945Z","iopub.status.idle":"2023-07-13T20:09:08.633314Z","shell.execute_reply.started":"2023-07-13T20:09:08.621882Z","shell.execute_reply":"2023-07-13T20:09:08.631607Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Prepare Train-Test split ","metadata":{}},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nIX = np.arange(len(X))\nIX_train, IX_test, _,_ = train_test_split( IX, IX, train_size=0.1, random_state=42)\nprint(len(IX_train), len(IX_test),  IX_train[:10], IX_test[:10] )","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:09:14.943512Z","iopub.execute_input":"2023-07-13T20:09:14.943994Z","iopub.status.idle":"2023-07-13T20:09:14.957491Z","shell.execute_reply.started":"2023-07-13T20:09:14.943960Z","shell.execute_reply":"2023-07-13T20:09:14.956300Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Ridge regression","metadata":{}},{"cell_type":"code","source":"from sklearn.linear_model import Ridge\n\nmodel = Ridge(alpha=1.0)\nstr_model_id = 'Ridge1'\n\ndf_models_stat = pd.DataFrame()\nmodel","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:09:16.938035Z","iopub.execute_input":"2023-07-13T20:09:16.938943Z","iopub.status.idle":"2023-07-13T20:09:16.950935Z","shell.execute_reply.started":"2023-07-13T20:09:16.938888Z","shell.execute_reply":"2023-07-13T20:09:16.949220Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time \nimport time\nfrom sklearn.metrics import roc_auc_score\n\nt0 = time.time()\nmodel.fit(X[IX_train,:],Y[IX_train,:])\nY_pred_test = model.predict(X[IX_test,:])\ntt = time.time() - t0\nprint(str_model_id, tt)\nl = []\nfor i in range(Y.shape[1]):\n    if len(np.unique(Y[IX_test,i]) ) > 1:\n        s = roc_auc_score(Y[IX_test,i], Y_pred_test[:,i]);\n    else:\n        s = 0.5\n    l.append(s)        \n    if i %10 == 0:\n        print(i, s)\ndf_models_stat.loc[str_model_id,'RocAuc Mean Test'] = np.mean(l)\ndf_models_stat.loc[str_model_id,'Time'] = np.round(tt,1)\ndf_models_stat.loc[str_model_id,'Test Size'] = len(IX_test)\ndf_models_stat","metadata":{"execution":{"iopub.status.busy":"2023-07-13T20:09:19.581884Z","iopub.execute_input":"2023-07-13T20:09:19.583262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nplt.hist(l)\nplt.show()\npd.Series(l).describe()","metadata":{"execution":{"iopub.status.busy":"2023-07-13T18:55:40.483623Z","iopub.status.idle":"2023-07-13T18:55:40.484222Z","shell.execute_reply.started":"2023-07-13T18:55:40.483974Z","shell.execute_reply":"2023-07-13T18:55:40.483997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}