{"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":"import numpy as np\nimport pandas as pd\nfrom matplotlib import pyplot as plt\nimport seaborn as sns\nimport plotly.express as px\nimport tensorflow as tf\nimport keras\nimport keras.layers as L\nimport math\nfrom keras.utils import Sequence\nfrom keras.preprocessing import image\nfrom random import shuffle\nfrom sklearn.model_selection import train_test_split\nimport os","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels = pd.read_csv('../input/g2net-gravitational-wave-detection/training_labels.csv')\nsample_submission = pd.read_csv('../input/g2net-gravitational-wave-detection/sample_submission.csv')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels.head()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels.shape","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(x='target',data=train_labels,palette='Set2')","metadata":{"execution":{"iopub.status.busy":"2021-07-19T12:34:32.348904Z","iopub.execute_input":"2021-07-19T12:34:32.349408Z","iopub.status.idle":"2021-07-19T12:34:32.500877Z","shell.execute_reply.started":"2021-07-19T12:34:32.349368Z","shell.execute_reply":"2021-07-19T12:34:32.499796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels['id'][:5]","metadata":{"execution":{"iopub.status.busy":"2021-07-19T12:34:32.502365Z","iopub.execute_input":"2021-07-19T12:34:32.502716Z","iopub.status.idle":"2021-07-19T12:34:32.509403Z","shell.execute_reply.started":"2021-07-19T12:34:32.502681Z","shell.execute_reply":"2021-07-19T12:34:32.508401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#numpy Files are extracted\npath = list(train_labels['id'])  \nfor i in range(len(path)):\n    path[i] = '../input/g2net-gravitational-wave-detection/train/' +path[i][0]+'/'+path[i][1]+'/'+path[i][2]+'/' + path[i] + '.npy'","metadata":{"execution":{"iopub.status.busy":"2021-07-19T12:34:32.510923Z","iopub.execute_input":"2021-07-19T12:34:32.511381Z","iopub.status.idle":"2021-07-19T12:34:33.152656Z","shell.execute_reply.started":"2021-07-19T12:34:32.511345Z","shell.execute_reply":"2021-07-19T12:34:33.151578Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path[0:5]","metadata":{"execution":{"iopub.status.busy":"2021-07-19T12:34:33.155449Z","iopub.execute_input":"2021-07-19T12:34:33.155833Z","iopub.status.idle":"2021-07-19T12:34:33.161351Z","shell.execute_reply.started":"2021-07-19T12:34:33.155795Z","shell.execute_reply":"2021-07-19T12:34:33.160423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def id2path(idx,is_train=True):\n    path = '../input/g2net-gravitational-wave-detection'\n    if is_train:\n        path += '/train/'+idx[0]+'/'+idx[1]+'/'+idx[2]+'/'+idx+'.npy'\n    else:\n        path += '/test/'+idx[0]+'/'+idx[1]+'/'+idx[2]+'/'+idx+'.npy'\n    return path","metadata":{"execution":{"iopub.status.busy":"2021-07-19T12:34:33.16372Z","iopub.execute_input":"2021-07-19T12:34:33.164137Z","iopub.status.idle":"2021-07-19T12:34:33.170807Z","shell.execute_reply.started":"2021-07-19T12:34:33.164046Z","shell.execute_reply":"2021-07-19T12:34:33.169875Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install -q nnAudio","metadata":{"execution":{"iopub.status.busy":"2021-07-19T12:34:33.172276Z","iopub.execute_input":"2021-07-19T12:34:33.172624Z","iopub.status.idle":"2021-07-19T12:34:41.02592Z","shell.execute_reply.started":"2021-07-19T12:34:33.17259Z","shell.execute_reply":"2021-07-19T12:34:41.024754Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\nfrom nnAudio.Spectrogram import CQT1992v2\ndef increase_dimension(idx,is_train,transform=CQT1992v2(sr=2048, fmin=20, fmax=1024, hop_length=64)): # in order to use efficientnet we need 3 dimension images\n    waves = np.load(id2path(idx,is_train))\n    waves = np.hstack(waves)\n    waves = waves / np.max(waves)\n    waves = torch.from_numpy(waves).float()\n    image = transform(waves)\n    image = np.array(image)\n    image = np.transpose(image,(1,2,0))\n    return image","metadata":{"execution":{"iopub.status.busy":"2021-07-19T12:34:41.029874Z","iopub.execute_input":"2021-07-19T12:34:41.030185Z","iopub.status.idle":"2021-07-19T12:34:42.537953Z","shell.execute_reply.started":"2021-07-19T12:34:41.030152Z","shell.execute_reply":"2021-07-19T12:34:42.537129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"example = np.load(path[0])","metadata":{"execution":{"iopub.status.busy":"2021-07-19T12:34:42.539366Z","iopub.execute_input":"2021-07-19T12:34:42.539891Z","iopub.status.idle":"2021-07-19T12:34:42.5592Z","shell.execute_reply.started":"2021-07-19T12:34:42.539851Z","shell.execute_reply":"2021-07-19T12:34:42.558277Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig,a =  plt.subplots(3,1)\na[0].plot(example[1],color='green')\na[1].plot(example[1],color='red')\na[2].plot(example[1],color='yellow')\nfig.suptitle('Target 1', fontsize=16)\nplt.show()\nplt.imshow(increase_dimension(train_labels['id'][0],is_train=True))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-07-19T12:34:42.561683Z","iopub.execute_input":"2021-07-19T12:34:42.561926Z","iopub.status.idle":"2021-07-19T12:34:43.072218Z","shell.execute_reply.started":"2021-07-19T12:34:42.561898Z","shell.execute_reply":"2021-07-19T12:34:43.070932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"example = np.load(path[10])\nfig,a =  plt.subplots(3,1)\na[0].plot(example[1],color='green')\na[1].plot(example[1],color='red')\na[2].plot(example[1],color='yellow')\nfig.suptitle('Target 0', fontsize=16)\nplt.show()\nplt.imshow(increase_dimension(train_labels['id'][1],is_train=True))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-07-19T12:34:43.073834Z","iopub.execute_input":"2021-07-19T12:34:43.074233Z","iopub.status.idle":"2021-07-19T12:34:43.527616Z","shell.execute_reply.started":"2021-07-19T12:34:43.074191Z","shell.execute_reply":"2021-07-19T12:34:43.526823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"example = np.load(path[20])\nfig,a =  plt.subplots(3,1)\na[0].plot(example[1],color='green')\na[1].plot(example[1],color='red')\na[2].plot(example[1],color='yellow')\nfig.suptitle('Target 0', fontsize=16)\nplt.show()\nplt.imshow(increase_dimension(train_labels['id'][1],is_train=True))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-07-19T12:34:43.528835Z","iopub.execute_input":"2021-07-19T12:34:43.52917Z","iopub.status.idle":"2021-07-19T12:34:43.973489Z","shell.execute_reply.started":"2021-07-19T12:34:43.529136Z","shell.execute_reply":"2021-07-19T12:34:43.972546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"example = np.load(path[5012])\nfig,a =  plt.subplots(3,1)\na[0].plot(example[1],color='green')\na[1].plot(example[1],color='red')\na[2].plot(example[1],color='yellow')\nfig.suptitle('Target 0', fontsize=16)\nplt.show()\nplt.imshow(increase_dimension(train_labels['id'][1],is_train=True))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-07-19T12:34:43.974917Z","iopub.execute_input":"2021-07-19T12:34:43.975365Z","iopub.status.idle":"2021-07-19T12:34:44.421585Z","shell.execute_reply.started":"2021-07-19T12:34:43.975325Z","shell.execute_reply":"2021-07-19T12:34:44.420748Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class Dataset(Sequence):\n    def __init__(self,idx,y=None,batch_size=256,shuffle=True):\n        self.idx = idx\n        self.batch_size = batch_size\n        self.shuffle = shuffle\n        if y is not None:\n            self.is_train=True\n        else:\n            self.is_train=False\n        self.y = y\n    def __len__(self):\n        return math.ceil(len(self.idx)/self.batch_size)\n    def __getitem__(self,ids):\n        batch_ids = self.idx[ids * self.batch_size:(ids + 1) * self.batch_size]\n        if self.y is not None:\n            batch_y = self.y[ids * self.batch_size: (ids + 1) * self.batch_size]\n            \n        list_x = np.array([increase_dimension(x,self.is_train) for x in batch_ids])\n        batch_X = np.stack(list_x)\n        if self.is_train:\n            return batch_X, batch_y\n        else:\n            return batch_X\n    \n    def on_epoch_end(self):\n        if self.shuffle and self.is_train:\n            ids_y = list(zip(self.idx, self.y))\n            shuffle(ids_y)\n            self.idx, self.y = list(zip(*ids_y))","metadata":{"execution":{"iopub.status.busy":"2021-07-19T12:34:44.422828Z","iopub.execute_input":"2021-07-19T12:34:44.423186Z","iopub.status.idle":"2021-07-19T12:34:44.43295Z","shell.execute_reply.started":"2021-07-19T12:34:44.423148Z","shell.execute_reply":"2021-07-19T12:34:44.432043Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_idx =  train_labels['id'].values\ny = train_labels['target'].values\ntest_idx = sample_submission['id'].values","metadata":{"execution":{"iopub.status.busy":"2021-07-19T12:34:44.43423Z","iopub.execute_input":"2021-07-19T12:34:44.434571Z","iopub.status.idle":"2021-07-19T12:34:44.451375Z","shell.execute_reply.started":"2021-07-19T12:34:44.434525Z","shell.execute_reply":"2021-07-19T12:34:44.450556Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train,x_valid,y_train,y_valid = train_test_split(train_idx,y,test_size=0.05,random_state=42,stratify=y)","metadata":{"execution":{"iopub.status.busy":"2021-07-19T12:34:44.454441Z","iopub.execute_input":"2021-07-19T12:34:44.454692Z","iopub.status.idle":"2021-07-19T12:34:44.900839Z","shell.execute_reply.started":"2021-07-19T12:34:44.454664Z","shell.execute_reply":"2021-07-19T12:34:44.899978Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_dataset = Dataset(x_train,y_train)\nvalid_dataset = Dataset(x_valid,y_valid)\ntest_dataset = Dataset(test_idx)","metadata":{"execution":{"iopub.status.busy":"2021-07-19T18:31:12.656387Z","iopub.execute_input":"2021-07-19T18:31:12.656733Z","iopub.status.idle":"2021-07-19T18:31:12.662464Z","shell.execute_reply.started":"2021-07-19T18:31:12.656702Z","shell.execute_reply":"2021-07-19T18:31:12.661416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train","metadata":{"execution":{"iopub.status.busy":"2021-07-19T12:34:44.909728Z","iopub.execute_input":"2021-07-19T12:34:44.910101Z","iopub.status.idle":"2021-07-19T12:34:44.920647Z","shell.execute_reply.started":"2021-07-19T12:34:44.910049Z","shell.execute_reply":"2021-07-19T12:34:44.919667Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install -U efficientnet","metadata":{"execution":{"iopub.status.busy":"2021-07-19T12:34:44.922343Z","iopub.execute_input":"2021-07-19T12:34:44.922704Z","iopub.status.idle":"2021-07-19T12:34:51.728383Z","shell.execute_reply.started":"2021-07-19T12:34:44.922668Z","shell.execute_reply":"2021-07-19T12:34:51.727343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import efficientnet.keras as efn","metadata":{"execution":{"iopub.status.busy":"2021-07-19T12:34:58.517869Z","iopub.execute_input":"2021-07-19T12:34:58.518274Z","iopub.status.idle":"2021-07-19T12:34:58.79935Z","shell.execute_reply.started":"2021-07-19T12:34:58.518237Z","shell.execute_reply":"2021-07-19T12:34:58.798531Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = tf.keras.Sequential([L.InputLayer(input_shape=(69,193,1)),L.Conv2D(3,3,activation='relu',padding='same'),efn.EfficientNetB0\n                             (include_top=False,input_shape=(),weights='imagenet'),\n        L.GlobalAveragePooling2D(),\n        L.Dense(32,activation='relu'),\n        L.Dense(1, activation='sigmoid')])\n\nmodel.summary()\nmodel.compile(optimizer=keras.optimizers.Adam(learning_rate=0.001),\n              loss='binary_crossentropy', metrics=[keras.metrics.AUC()])","metadata":{"execution":{"iopub.status.busy":"2021-07-19T12:34:58.861565Z","iopub.execute_input":"2021-07-19T12:34:58.861869Z","iopub.status.idle":"2021-07-19T12:35:07.750244Z","shell.execute_reply.started":"2021-07-19T12:34:58.861841Z","shell.execute_reply":"2021-07-19T12:35:07.749423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(train_dataset,epochs=1,validation_data=valid_dataset)","metadata":{"execution":{"iopub.status.busy":"2021-07-19T12:35:15.714543Z","iopub.execute_input":"2021-07-19T12:35:15.714878Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.save('./model_efn.h5')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds = model.predict(test_dataset)\npreds = preds.reshape(-1)","metadata":{"execution":{"iopub.status.busy":"2021-07-19T15:30:16.305441Z","iopub.execute_input":"2021-07-19T15:30:16.305755Z","iopub.status.idle":"2021-07-19T16:09:46.540020Z","shell.execute_reply.started":"2021-07-19T15:30:16.305724Z","shell.execute_reply":"2021-07-19T16:09:46.537408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.DataFrame({'id':sample_submission['id'],'target':preds})","metadata":{"execution":{"iopub.status.busy":"2021-07-19T16:09:46.546811Z","iopub.execute_input":"2021-07-19T16:09:46.547229Z","iopub.status.idle":"2021-07-19T16:09:46.563255Z","shell.execute_reply.started":"2021-07-19T16:09:46.547192Z","shell.execute_reply":"2021-07-19T16:09:46.562284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.to_csv('submission_efn.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2021-07-19T16:09:46.566354Z","iopub.execute_input":"2021-07-19T16:09:46.568235Z","iopub.status.idle":"2021-07-19T16:09:47.341503Z","shell.execute_reply.started":"2021-07-19T16:09:46.568193Z","shell.execute_reply":"2021-07-19T16:09:47.340549Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.applications import ResNet50","metadata":{"execution":{"iopub.status.busy":"2021-07-19T16:09:47.344269Z","iopub.execute_input":"2021-07-19T16:09:47.344639Z","iopub.status.idle":"2021-07-19T16:09:47.349570Z","shell.execute_reply.started":"2021-07-19T16:09:47.344602Z","shell.execute_reply":"2021-07-19T16:09:47.348612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_res = tf.keras.Sequential([L.InputLayer(input_shape=(69,193,1)),\n                                 L.Conv2D(3,3,activation='relu',padding='same'),\n                                 ResNet50(include_top=False,input_shape=(),weights='imagenet'),\n        L.GlobalAveragePooling2D(),\n        L.Dense(32,activation='relu'),\n        L.Dense(1, activation='sigmoid')])\n\nmodel_res.summary()\nmodel_res.compile(optimizer=keras.optimizers.Adam(learning_rate=0.001),\n              loss='binary_crossentropy', metrics=[keras.metrics.AUC()])","metadata":{"execution":{"iopub.status.busy":"2021-07-19T16:09:47.352094Z","iopub.execute_input":"2021-07-19T16:09:47.352454Z","iopub.status.idle":"2021-07-19T16:09:49.268571Z","shell.execute_reply.started":"2021-07-19T16:09:47.352418Z","shell.execute_reply":"2021-07-19T16:09:49.262429Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_dataset = Dataset(x_train,y_train)\nvalid_dataset = Dataset(x_valid,y_valid)\ntest_dataset = Dataset(test_idx)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_res.fit(train_dataset,epochs=1,validation_data=valid_dataset)","metadata":{"execution":{"iopub.status.busy":"2021-07-19T16:10:30.024207Z","iopub.execute_input":"2021-07-19T16:10:30.024564Z","iopub.status.idle":"2021-07-19T17:50:12.122502Z","shell.execute_reply.started":"2021-07-19T16:10:30.024526Z","shell.execute_reply":"2021-07-19T17:50:12.120213Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_res.save('./model_res.h5')","metadata":{"execution":{"iopub.status.busy":"2021-07-19T17:50:12.129729Z","iopub.execute_input":"2021-07-19T17:50:12.130149Z","iopub.status.idle":"2021-07-19T17:50:13.345291Z","shell.execute_reply.started":"2021-07-19T17:50:12.130108Z","shell.execute_reply":"2021-07-19T17:50:13.344361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds = model_res.predict(test_dataset)\npreds = preds.reshape(-1)","metadata":{"execution":{"iopub.status.busy":"2021-07-19T17:50:13.348457Z","iopub.execute_input":"2021-07-19T17:50:13.348812Z","iopub.status.idle":"2021-07-19T18:25:59.010930Z","shell.execute_reply.started":"2021-07-19T17:50:13.348776Z","shell.execute_reply":"2021-07-19T18:25:59.008834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_res = pd.DataFrame({'id':sample_submission['id'],'target':preds})","metadata":{"execution":{"iopub.status.busy":"2021-07-19T18:25:59.016709Z","iopub.execute_input":"2021-07-19T18:25:59.017110Z","iopub.status.idle":"2021-07-19T18:25:59.043050Z","shell.execute_reply.started":"2021-07-19T18:25:59.017056Z","shell.execute_reply":"2021-07-19T18:25:59.042252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_res.to_csv('submission_res.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2021-07-19T18:25:59.045589Z","iopub.execute_input":"2021-07-19T18:25:59.047365Z","iopub.status.idle":"2021-07-19T18:25:59.861847Z","shell.execute_reply.started":"2021-07-19T18:25:59.047326Z","shell.execute_reply":"2021-07-19T18:25:59.860997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.applications import Xception","metadata":{"execution":{"iopub.status.busy":"2021-07-19T18:25:59.864914Z","iopub.execute_input":"2021-07-19T18:25:59.865296Z","iopub.status.idle":"2021-07-19T18:25:59.871251Z","shell.execute_reply.started":"2021-07-19T18:25:59.865258Z","shell.execute_reply":"2021-07-19T18:25:59.870381Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_xce = tf.keras.Sequential([L.InputLayer(input_shape=(69,193,1)),\n                                 L.Conv2D(3,3,activation='relu',padding='same'),\n                                 Xception(include_top=False,input_shape=(),weights='imagenet'),\n        L.GlobalAveragePooling2D(),\n        L.Dense(32,activation='relu'),\n        L.Dense(1, activation='sigmoid')])\n\nmodel_xce.summary()\nmodel_xce.compile(optimizer=keras.optimizers.Adam(learning_rate=0.001),\n              loss='binary_crossentropy', metrics=[keras.metrics.AUC()])","metadata":{"execution":{"iopub.status.busy":"2021-07-19T18:25:59.874645Z","iopub.execute_input":"2021-07-19T18:25:59.876899Z","iopub.status.idle":"2021-07-19T18:26:02.806219Z","shell.execute_reply.started":"2021-07-19T18:25:59.876858Z","shell.execute_reply":"2021-07-19T18:26:02.805146Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_dataset = Dataset(x_train,y_train)\nvalid_dataset = Dataset(x_valid,y_valid)\ntest_dataset = Dataset(test_idx)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_xce.fit(train_dataset,epochs=1,validation_data=valid_dataset)","metadata":{"execution":{"iopub.status.busy":"2021-07-19T18:31:30.733664Z","iopub.execute_input":"2021-07-19T18:31:30.733988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_xce.save('./model_xce.h5')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds = model_xce.predict(test_dataset)\npreds = preds.reshape(-1)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_xce = pd.DataFrame({'id':sample_submission['id'],'target':preds})","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_xce.to_csv('submission_xce.csv',index=False)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('tb')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Ensemble Process","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def voting(a,b,c):\n    if a==b:\n        return a\n    if b==c:\n        return c\n    if a==c:\n        return a","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"id1 = df['id']\ntarget = []\nfor i in range(len(df['target'])):\n    target.append(voting(df['target'][i],df_res['target'][i],df_xce['target'][i]))\n\n    \nfinalsubmission = pd.DataFrame(columns = ['id','target'])\n\nfinalsubmission['id'] = id1\nfinalsubmission['target'] = target\nfinalsubmission.to_csv('submission.csv', index = False)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}