{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":59093,"databundleVersionId":7469972,"sourceType":"competition"},{"sourceId":7392733,"sourceType":"datasetVersion","datasetId":4297749},{"sourceId":7758969,"sourceType":"datasetVersion","datasetId":4537430},{"sourceId":7771038,"sourceType":"datasetVersion","datasetId":4546156}],"dockerImageVersionId":30664,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Submission","metadata":{"execution":{"iopub.status.busy":"2024-03-04T14:18:00.679058Z","iopub.execute_input":"2024-03-04T14:18:00.679476Z","iopub.status.idle":"2024-03-04T14:18:00.687198Z","shell.execute_reply.started":"2024-03-04T14:18:00.679445Z","shell.execute_reply":"2024-03-04T14:18:00.685664Z"}}},{"cell_type":"code","source":"import os\nimport gc\nimport cv2\nimport sys\nimport math\nimport time\nimport torch\nimport random\nimport shutil\nimport joblib\nimport numpy as np\nimport pandas as pd\nfrom glob import glob\nimport torch.nn as nn\nfrom pathlib import Path\nfrom tqdm.auto import tqdm\nfrom functools import partial\nfrom typing import Dict, List\nimport pytorch_lightning as pl\nimport torch.nn.functional as F\nfrom scipy.stats import entropy\nfrom sklearn import preprocessing\nimport torchvision.models as models\nfrom matplotlib import pyplot as plt\nfrom torchvision.transforms import v2\nfrom contextlib import contextmanager\nfrom torch.nn.parameter import Parameter\nfrom torch.optim import Adam, SGD, AdamW\nfrom collections import defaultdict, Counter\nfrom sklearn.preprocessing import LabelEncoder\nfrom sklearn.model_selection import GroupKFold\nfrom albumentations.pytorch import ToTensorV2\nfrom albumentations import ImageOnlyTransform\nfrom sklearn.preprocessing import LabelEncoder\nfrom scipy.signal import butter, lfilter, freqz\nfrom torch.utils.data import DataLoader, Dataset\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import accuracy_score, log_loss\nfrom torch.optim.lr_scheduler import ReduceLROnPlateau, OneCycleLR, CosineAnnealingLR, CosineAnnealingWarmRestarts\nfrom albumentations import (Compose, Normalize, Resize, RandomResizedCrop, HorizontalFlip, VerticalFlip, ShiftScaleRotate, Transpose)\nfrom logging import getLogger, INFO, FileHandler,  Formatter,  StreamHandler\n\nimport timm\nimport warnings \nwarnings.filterwarnings('ignore')\ndevice  = torch.device('cuda' if torch.cuda.is_available() else 'cpu')\n\nos.environ['CUDA_VISIBLE_DEVICES'] = \"0,1\"\nVERSION = 2\n\nsys.path.append('/kaggle/input/kaggle-kl-div')\nfrom kaggle_kl_div import score","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:42:48.790025Z","iopub.execute_input":"2024-03-06T01:42:48.790287Z","iopub.status.idle":"2024-03-06T01:43:00.767738Z","shell.execute_reply.started":"2024-03-06T01:42:48.790262Z","shell.execute_reply":"2024-03-06T01:43:00.766775Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class CONFIG:\n    WANDB             = False\n    DEBUG             = True\n    TRAIN             = True\n    APEX              = True\n    STAGE1_POP1       = True\n    STAGE2_POP2       = False\n    VISUALIZE         = True\n    FREEZE            = False\n    SPARK             = False\n    OUTPUT_DIR        = './'\n    SCHEDULER                = 'OneCycleLR'  # ['ReduceLROnPlateau', 'CosineAnnealingLR', 'CosineAnnealingWarmRestarts', 'OneCycleLR']\n    COSANNEAL_PARAMS         = {'T_max'     : 6,'eta_min'   : 1e-5,'last_epoch': -1} # CosineAnnealingLR params\n    REDUCE_PARAMS            = {'mode'    : 'min','factor'  : 0.2,'patience': 4,'eps'     : 1e-6,'verbose' : True} # ReduceLROnPlateau params\n    COSANNEAL_RES_PARAMS     = {'T_0'       : 20,'eta_min'   : 1e-6,'T_mult'    : 1,'last_epoch': -1} # CosineAnnealingWarmRestarts params\n    PRINT_FREQ               = 50\n    NUM_WORKERS              = 2\n    MODEL_NAME               = 'tf_efficientnet_b0_ns'\n    OPTIMIZER                = 'Adan'\n    EPOCHS                   = 5\n    FACTOR                   = 0.9\n    PATIENCE                 = 2\n    EPS                      = 1e-6\n    LR                       = 1e-3\n    MIN_LR                   = 1e-6\n    BATCH_SIZE               = 64\n    WEIGHT_DECAY             = 1e-2\n    BATCH_SCHEDULER          = True\n    GRADIENT_ACCUMULATION_STEPS = 1\n    MAX_GRAD_NORM               = 1e7\n    SEED                        = 2024\n    TARGET_COLS                 = ['seizure_vote', 'lpd_vote', 'gpd_vote', 'lrda_vote', 'grda_vote', 'other_vote']\n    TARGET_SIZE                 = 6\n    PRED_COLS                   = ['pred_seizure_vote', 'pred_lpd_vote', 'pred_gpd_vote', 'pred_lrda_vote', 'pred_grda_vote', 'pred_other_vote']\n    N_FOLD                      = 5\n    TRN_FOLD                    = [0, 1, 2, 3, 4]\n    PATH                        = '/kaggle/input/hms-harmful-brain-activity-classification/'\n    DATA_ROOT                   = \"/kaggle/input/hms-harmful-brain-activity-classification/train_eegs/\"\n    RAW_EEG_PATH                = \"/kaggle/input/brain-eegs/eegs.npy\"\n    \nconfig = CONFIG()","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:00.769785Z","iopub.execute_input":"2024-03-06T01:43:00.770060Z","iopub.status.idle":"2024-03-06T01:43:00.779412Z","shell.execute_reply.started":"2024-03-06T01:43:00.770036Z","shell.execute_reply":"2024-03-06T01:43:00.778351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class KLDivLossWithLogits(nn.KLDivLoss):\n\n    def __init__(self):\n        super().__init__(reduction=\"batchmean\")\n\n    def forward(self, y, t):\n        y = nn.functional.log_softmax(y,  dim=1)\n        loss = super().forward(y, t)\n\n        return loss","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:00.783917Z","iopub.execute_input":"2024-03-06T01:43:00.784202Z","iopub.status.idle":"2024-03-06T01:43:00.797821Z","shell.execute_reply.started":"2024-03-06T01:43:00.784179Z","shell.execute_reply":"2024-03-06T01:43:00.797061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class CustomDataset(Dataset):\n    def __init__(self, df, augment, mode,spectrograms,eeg_specs): \n        self.df              = df\n        self.augment         = augment\n        self.mode            = mode\n        self.spectograms     = spectrograms\n        self.eeg_spectograms = eeg_specs\n    def __len__(self):\n        \"\"\"\n        Denotes the number of batches per epoch.\n        \"\"\"\n        return len(self.df)\n        \n    def __getitem__(self, index):\n        \"\"\"\n        Generate one batch of data.\n        \"\"\"\n        X, y = self.__data_generation(index)\n        if self.augment:\n            X = self.__transform(X) \n        return {\"spectrogram\":torch.tensor(X, dtype=torch.float32), \"labels\":torch.tensor(y, dtype=torch.float32)}\n                        \n    def __data_generation(self, index):\n        \"\"\"\n        Generates data containing batch_size samples.\n        \"\"\"\n        X    = np.zeros((128, 256, 8), dtype='float32')\n        y    = np.zeros(6, dtype='float32')\n        img  = np.ones((128,256), dtype='float32')\n        row  = self.df.iloc[index]\n        if self.mode=='test': \n            r = 0\n        else: \n            r = int(row['spectrogram_label_offset_seconds'] // 2)\n                \n        for region in range(4):\n            img = self.spectograms[row.spectrogram_id][r:r+300, region*100:(region+1)*100].T\n            \n            # Log transform spectogram\n            img = np.clip(img, np.exp(-4), np.exp(8))\n            img = np.log(img)\n\n            # Standarize per image\n            ep  = 1e-6\n            mu  = np.nanmean(img.flatten())\n            std = np.nanstd(img.flatten())\n            img = (img-mu)/(std+ep)\n            img = np.nan_to_num(img, nan=0.0)\n            X[14:-14, :, region] = img[:, 22:-22] / 2.0\n            img = self.eeg_spectograms[row.eeg_id]\n            X[:, :, 4:] = img\n                \n            if self.mode != 'test':\n                y = row[TARGETS].values.astype(np.float32)\n            \n        return X, y\n    \n    def __transform(self, img):\n        params1 = {\n                    \"num_masks_x\"  : 1,    \n                    \"mask_x_length\": (0, 20), # This line changed from fixed  to a range\n                    \"fill_value\"   : (0, 1, 2, 3, 4, 5, 6, 7),\n                    }\n        params2 = {    \n                    \"num_masks_y\"  : 1,    \n                    \"mask_y_length\": (0, 20),\n                    \"fill_value\"   : (0, 1, 2, 3, 4, 5, 6, 7),    \n                    }\n        params3 = {    \n                    \"num_masks_x\"  : (2, 4),\n                    \"num_masks_y\"  : 5,    \n                    \"mask_y_length\": 8,\n                    \"mask_x_length\": (10, 20),\n                    \"fill_value\"   : (0, 1, 2, 3, 4, 5, 6, 7),  \n                    }\n        \n        transforms = A.Compose([])\n        return transforms(image=img)['image']","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:00.798786Z","iopub.execute_input":"2024-03-06T01:43:00.799052Z","iopub.status.idle":"2024-03-06T01:43:00.815306Z","shell.execute_reply.started":"2024-03-06T01:43:00.799031Z","shell.execute_reply":"2024-03-06T01:43:00.814416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df = pd.read_csv(\"/kaggle/input/hms-harmful-brain-activity-classification/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:00.816386Z","iopub.execute_input":"2024-03-06T01:43:00.816697Z","iopub.status.idle":"2024-03-06T01:43:00.835037Z","shell.execute_reply.started":"2024-03-06T01:43:00.816675Z","shell.execute_reply":"2024-03-06T01:43:00.834267Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:00.836015Z","iopub.execute_input":"2024-03-06T01:43:00.836271Z","iopub.status.idle":"2024-03-06T01:43:00.849449Z","shell.execute_reply.started":"2024-03-06T01:43:00.836249Z","shell.execute_reply":"2024-03-06T01:43:00.848522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# READ ALL SPECTROGRAMS\nspec_path = \"/kaggle/input/hms-harmful-brain-activity-classification/test_spectrograms/\"\nfiles2    = os.listdir(spec_path)\nprint(f'There are {len(files2)} test spectrogram parquets')\n    \nall_spectrograms = {}\nfor i,f in enumerate(files2):\n    if i%100==0: print(i,', ',end='')\n    tmp = pd.read_parquet(f'{spec_path}{f}')\n    name = int(f.split('.')[0])\n    all_spectrograms[name] = tmp.iloc[:,1:].values","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:00.850470Z","iopub.execute_input":"2024-03-06T01:43:00.850749Z","iopub.status.idle":"2024-03-06T01:43:01.066585Z","shell.execute_reply.started":"2024-03-06T01:43:00.850727Z","shell.execute_reply":"2024-03-06T01:43:01.065635Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all_spectrograms.get(853520).shape","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:01.067910Z","iopub.execute_input":"2024-03-06T01:43:01.068661Z","iopub.status.idle":"2024-03-06T01:43:01.074619Z","shell.execute_reply.started":"2024-03-06T01:43:01.068626Z","shell.execute_reply":"2024-03-06T01:43:01.073668Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"NAMES = ['LL','LP','RP','RR']\nFEATS = [['Fp1','F7','T3','T5','O1'],\n         ['Fp1','F3','C3','P3','O1'],\n         ['Fp2','F8','T4','T6','O2'],\n         ['Fp2','F4','C4','P4','O2']]","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:01.077440Z","iopub.execute_input":"2024-03-06T01:43:01.077757Z","iopub.status.idle":"2024-03-06T01:43:01.083836Z","shell.execute_reply.started":"2024-03-06T01:43:01.077724Z","shell.execute_reply":"2024-03-06T01:43:01.082985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pywt, librosa\n\ndef spectrogram_from_eeg(parquet_path, display=False, offset=None):\n    \n    eeg = pd.read_parquet(parquet_path)\n\n    if offset is None:\n        middle = (len(eeg)-10_000)//2\n        eeg = eeg.iloc[middle:middle+10_000]\n    else:\n        eeg = eeg.iloc[offset:offset+10_000]\n    \n    img = np.zeros((128,256,4),dtype='float32')\n    \n    signals = []\n    for k in range(4):\n        COLS = FEATS[k]\n        \n        for kk in range(4):\n        \n            # COMPUTE PAIR DIFFERENCES\n            x = eeg[COLS[kk]].values - eeg[COLS[kk+1]].values\n\n            # FILL NANS\n            m = np.nanmean(x)\n            if np.isnan(x).mean() < 1: \n                x = np.nan_to_num(x,nan=m)\n            else: x[:] = 0\n                \n            signals.append(x)\n\n            # RAW SPECTROGRAM\n            mel_spec = librosa.feature.melspectrogram(y=x, sr=200, hop_length=len(x)//256, \n                  n_fft=1024, n_mels=128, fmin=0, fmax=20, win_length=128)\n\n            # LOG TRANSFORM\n            width = (mel_spec.shape[1]//32)*32\n            mel_spec_db = librosa.power_to_db(mel_spec, ref=np.max).astype(np.float32)[:,:width]\n\n            # STANDARDIZE TO -1 TO 1\n            mel_spec_db = (mel_spec_db+40)/40 \n            img[:,:,k] += mel_spec_db\n                \n        # AVERAGE THE 4 MONTAGE DIFFERENCES\n        img[:,:,k] /= 4.0\n        \n    return img","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:01.085082Z","iopub.execute_input":"2024-03-06T01:43:01.085699Z","iopub.status.idle":"2024-03-06T01:43:01.160060Z","shell.execute_reply.started":"2024-03-06T01:43:01.085649Z","shell.execute_reply":"2024-03-06T01:43:01.159232Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# READ ALL EEG SPECTROGRAMS\nroot_eeg = \"/kaggle/input/hms-harmful-brain-activity-classification/test_eegs/\"\nDISPLAY = 1\nEEG_IDS2 = test_df.eeg_id.unique()\nall_eegs = {}\n\nprint('Converting Test EEG to Spectrograms...')\nfor i,eeg_id in enumerate(EEG_IDS2):\n        \n    # CREATE SPECTROGRAM FROM EEG PARQUET\n    img = spectrogram_from_eeg(f'{root_eeg}{eeg_id}.parquet', i<DISPLAY)\n    all_eegs[eeg_id] = img","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:01.161135Z","iopub.execute_input":"2024-03-06T01:43:01.161977Z","iopub.status.idle":"2024-03-06T01:43:10.970693Z","shell.execute_reply.started":"2024-03-06T01:43:01.161946Z","shell.execute_reply":"2024-03-06T01:43:10.969372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_dataset = CustomDataset(test_df,False,\"test\",all_spectrograms,all_eegs)\ntest_loader = DataLoader(\n    test_dataset,\n    batch_size=config.BATCH_SIZE,\n    shuffle=False,\n    num_workers=config.NUM_WORKERS, pin_memory=True, drop_last=False\n)","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:10.972546Z","iopub.execute_input":"2024-03-06T01:43:10.973547Z","iopub.status.idle":"2024-03-06T01:43:10.981462Z","shell.execute_reply.started":"2024-03-06T01:43:10.973500Z","shell.execute_reply":"2024-03-06T01:43:10.980361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = test_dataset[0]\nprint(f\"X shape: {X['spectrogram'].shape}\")","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:10.983359Z","iopub.execute_input":"2024-03-06T01:43:10.984217Z","iopub.status.idle":"2024-03-06T01:43:11.044874Z","shell.execute_reply.started":"2024-03-06T01:43:10.984171Z","shell.execute_reply":"2024-03-06T01:43:11.043748Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class CustomModel(nn.Module):\n    def __init__(self, config, num_classes: int = 6, pretrained: bool = True):\n        super(CustomModel, self).__init__()\n        self.USE_KAGGLE_SPECTROGRAMS = True\n        self.USE_EEG_SPECTROGRAMS    = True\n        self.model                   = timm.create_model(\n                                                            config.MODEL_NAME,\n                                                            pretrained=pretrained,\n                                                        )\n        if config.FREEZE:\n            for i,(name, param) in enumerate(list(self.model.named_parameters())[0:config.NUM_FROZEN_LAYERS]):\n                param.requires_grad = False\n\n        self.features      = nn.Sequential(*list(self.model.children())[:-2])\n        self.custom_layers = nn.Sequential(\n                                                nn.AdaptiveAvgPool2d(1),\n                                                nn.Flatten(),\n                                                nn.Linear(self.model.num_features, num_classes)\n                                            )\n\n    def __reshape_input(self, x):\n        \"\"\"\n        Reshapes input (128, 256, 8) -> (512, 512, 3) monotone image.\n        \"\"\" \n        # === Get spectograms ===\n        spectograms = [x[:, :, :, i:i+1] for i in range(4)]\n        spectograms = torch.cat(spectograms, dim=1)\n        \n        # === Get EEG spectograms ===\n        eegs = [x[:, :, :, i:i+1] for i in range(4,8)]\n        eegs = torch.cat(eegs, dim=1)\n        \n        # === Reshape (512,512,3) ===\n        if self.USE_KAGGLE_SPECTROGRAMS & self.USE_EEG_SPECTROGRAMS:\n            x = torch.cat([spectograms, eegs], dim=2)\n        elif self.USE_EEG_SPECTROGRAMS:\n            x = eegs\n        else:\n            x = spectograms\n            \n        x = torch.cat([x,x,x], dim=3)\n        x = x.permute(0, 3, 1, 2)\n        return x\n    \n    def forward(self, x):\n        x = self.__reshape_input(x)\n        x = self.features(x)\n        x = self.custom_layers(x)\n        return x","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:11.046432Z","iopub.execute_input":"2024-03-06T01:43:11.047006Z","iopub.status.idle":"2024-03-06T01:43:11.072630Z","shell.execute_reply.started":"2024-03-06T01:43:11.046966Z","shell.execute_reply":"2024-03-06T01:43:11.071392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def test_loop(model_path, test_loader1):\n    model        = CustomModel(config,pretrained=False)\n    model_weight = model_path\n    checkpoint   = torch.load(model_weight, map_location=device)\n    model.load_state_dict(checkpoint[\"model\"])\n           \n    model.to(device)\n    predictions = test_fn(test_loader1,model,device)\n    return predictions\n    \ndef test_fn(test_loader1, model, device):\n    softmax = nn.Softmax(dim=1)\n    model.eval()\n    preds  = []\n    for step, batch in enumerate(test_loader1):\n            X = batch.pop(\"spectrogram\").to(device) # send inputs to `device`\n            batch_size = X.size(0)\n                \n            with torch.no_grad():\n                y_preds = model(X) # forward propagation pass\n            y_preds = softmax(y_preds)\n            preds.append(y_preds.to('cpu').numpy()) # save predictions\n                 # np.array() of shape (fold_size, target_cols)\n    return np.concatenate(preds)\n","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:11.074379Z","iopub.execute_input":"2024-03-06T01:43:11.075458Z","iopub.status.idle":"2024-03-06T01:43:11.089338Z","shell.execute_reply.started":"2024-03-06T01:43:11.075410Z","shell.execute_reply":"2024-03-06T01:43:11.088131Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds = []\nroot_path = \"/kaggle/input/hms-efficientnetb0-5-spectrograms\"\nfor model_path in os.listdir(root_path):\n    print(root_path+'/'+model_path)\n    full_path = root_path+'/'+model_path\n    pred      = test_loop(full_path,test_loader)\n    print(pred)\n    preds.append(pred)","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:16.751663Z","iopub.execute_input":"2024-03-06T01:43:16.752727Z","iopub.status.idle":"2024-03-06T01:43:21.081704Z","shell.execute_reply.started":"2024-03-06T01:43:16.752693Z","shell.execute_reply":"2024-03-06T01:43:21.080568Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:24.052092Z","iopub.execute_input":"2024-03-06T01:43:24.052726Z","iopub.status.idle":"2024-03-06T01:43:24.060881Z","shell.execute_reply.started":"2024-03-06T01:43:24.052690Z","shell.execute_reply":"2024-03-06T01:43:24.059972Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds.append(test_loop(\"/kaggle/input/hms-efficientnetb0-adam-lrwr-5e/tf_efficientnet_b0_ns_fold_best_version2_stage2.pth\",test_loader))","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:29.874089Z","iopub.execute_input":"2024-03-06T01:43:29.874446Z","iopub.status.idle":"2024-03-06T01:43:30.495082Z","shell.execute_reply.started":"2024-03-06T01:43:29.874417Z","shell.execute_reply":"2024-03-06T01:43:30.493860Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:35.851322Z","iopub.execute_input":"2024-03-06T01:43:35.851715Z","iopub.status.idle":"2024-03-06T01:43:35.860897Z","shell.execute_reply.started":"2024-03-06T01:43:35.851681Z","shell.execute_reply":"2024-03-06T01:43:35.859904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds = np.array(preds)\npreds = np.average(preds,axis=0)","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:42.707014Z","iopub.execute_input":"2024-03-06T01:43:42.707687Z","iopub.status.idle":"2024-03-06T01:43:42.712418Z","shell.execute_reply.started":"2024-03-06T01:43:42.707657Z","shell.execute_reply":"2024-03-06T01:43:42.711417Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:44.828301Z","iopub.execute_input":"2024-03-06T01:43:44.829002Z","iopub.status.idle":"2024-03-06T01:43:44.835520Z","shell.execute_reply.started":"2024-03-06T01:43:44.828964Z","shell.execute_reply":"2024-03-06T01:43:44.834515Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"TARGETS = ['seizure_vote', 'lpd_vote','gpd_vote', 'lrda_vote', 'grda_vote', 'other_vote']","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:49.642040Z","iopub.execute_input":"2024-03-06T01:43:49.642759Z","iopub.status.idle":"2024-03-06T01:43:49.647176Z","shell.execute_reply.started":"2024-03-06T01:43:49.642720Z","shell.execute_reply":"2024-03-06T01:43:49.646113Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df = test_df[['eeg_id']].copy()\nsub_df[TARGETS] = 0.0\nsub_df","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:50.239573Z","iopub.execute_input":"2024-03-06T01:43:50.240116Z","iopub.status.idle":"2024-03-06T01:43:50.257516Z","shell.execute_reply.started":"2024-03-06T01:43:50.240089Z","shell.execute_reply":"2024-03-06T01:43:50.256671Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df[TARGETS] = preds","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:53.056038Z","iopub.execute_input":"2024-03-06T01:43:53.057095Z","iopub.status.idle":"2024-03-06T01:43:53.061556Z","shell.execute_reply.started":"2024-03-06T01:43:53.057061Z","shell.execute_reply":"2024-03-06T01:43:53.060595Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:53.256582Z","iopub.execute_input":"2024-03-06T01:43:53.256881Z","iopub.status.idle":"2024-03-06T01:43:53.267449Z","shell.execute_reply.started":"2024-03-06T01:43:53.256856Z","shell.execute_reply":"2024-03-06T01:43:53.266601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df.to_csv('submission.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:56.053573Z","iopub.execute_input":"2024-03-06T01:43:56.053932Z","iopub.status.idle":"2024-03-06T01:43:56.062899Z","shell.execute_reply.started":"2024-03-06T01:43:56.053903Z","shell.execute_reply":"2024-03-06T01:43:56.062137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df","metadata":{"execution":{"iopub.status.busy":"2024-03-06T01:43:56.253217Z","iopub.execute_input":"2024-03-06T01:43:56.253864Z","iopub.status.idle":"2024-03-06T01:43:56.268098Z","shell.execute_reply.started":"2024-03-06T01:43:56.253836Z","shell.execute_reply":"2024-03-06T01:43:56.266941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}