{"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\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-12-06T03:42:39.078439Z","iopub.execute_input":"2022-12-06T03:42:39.078809Z","iopub.status.idle":"2022-12-06T03:42:46.885423Z","shell.execute_reply.started":"2022-12-06T03:42:39.078776Z","shell.execute_reply":"2022-12-06T03:42:46.88441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install pytorch-lightning==1.7.7\n!pip install opencv-python","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:42:46.889153Z","iopub.execute_input":"2022-12-06T03:42:46.890796Z","iopub.status.idle":"2022-12-06T03:43:45.610426Z","shell.execute_reply.started":"2022-12-06T03:42:46.890756Z","shell.execute_reply":"2022-12-06T03:43:45.608943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"try:\n    import pylibjpeg\nexcept:\n    !pip install /kaggle/input/rsna-2022-whl/{pydicom-2.3.0-py3-none-any.whl,pylibjpeg-1.4.0-py3-none-any.whl,python_gdcm-3.0.15-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl}","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:43:45.612635Z","iopub.execute_input":"2022-12-06T03:43:45.613051Z","iopub.status.idle":"2022-12-06T03:43:45.622005Z","shell.execute_reply.started":"2022-12-06T03:43:45.61301Z","shell.execute_reply":"2022-12-06T03:43:45.621036Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import sys\nsys.path.append('/kaggle/input/timm0611/pytorch-image-models-0.6.11')\nimport timm\ntimm.__version__","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:43:45.625366Z","iopub.execute_input":"2022-12-06T03:43:45.626418Z","iopub.status.idle":"2022-12-06T03:43:45.636449Z","shell.execute_reply.started":"2022-12-06T03:43:45.62636Z","shell.execute_reply":"2022-12-06T03:43:45.635433Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!cp -r /kaggle/input/hydracore105 /kaggle/working\n!mv /kaggle/working/hydracore105/antlr4-python3-runtime-4.8.tar.gz.tmp /kaggle/working/hydracore105/antlr4-python3-runtime-4.8.tar.gz\n!ls /kaggle/working/hydracore105","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:43:45.638308Z","iopub.execute_input":"2022-12-06T03:43:45.639147Z","iopub.status.idle":"2022-12-06T03:43:48.610316Z","shell.execute_reply.started":"2022-12-06T03:43:45.63911Z","shell.execute_reply":"2022-12-06T03:43:48.60915Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install /kaggle/working/hydracore105/* --ignore-installed PyYAML\n!rm -r /kaggle/working/hydracore105","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:43:48.61232Z","iopub.execute_input":"2022-12-06T03:43:48.61276Z","iopub.status.idle":"2022-12-06T03:44:21.057471Z","shell.execute_reply.started":"2022-12-06T03:43:48.612716Z","shell.execute_reply":"2022-12-06T03:44:21.056113Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import hydra\nimport omegaconf\nprint('hydra', hydra.__version__)\nprint('omegaconf', omegaconf.__version__)","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:44:21.060245Z","iopub.execute_input":"2022-12-06T03:44:21.060595Z","iopub.status.idle":"2022-12-06T03:44:21.068719Z","shell.execute_reply.started":"2022-12-06T03:44:21.060564Z","shell.execute_reply":"2022-12-06T03:44:21.067693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport torchvision.transforms as tvf\nimport torchvision\nfrom torch.utils.data import DataLoader, Dataset\nimport pytorch_lightning as pl\nfrom pytorch_lightning import LightningModule\nfrom hydra.utils import instantiate\n\nimport glob\nimport os\nfrom joblib import Parallel, delayed\nfrom tqdm import tqdm\nimport pydicom\nimport cv2\nfrom pathlib import Path\nfrom PIL import Image","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:44:21.070639Z","iopub.execute_input":"2022-12-06T03:44:21.071546Z","iopub.status.idle":"2022-12-06T03:44:21.08018Z","shell.execute_reply.started":"2022-12-06T03:44:21.071508Z","shell.execute_reply":"2022-12-06T03:44:21.079212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class EfficientNetB3DSPlus(nn.Module):\n    def __init__(self, model_name, n_class=2, pretrained=False, **kwargs):\n        super().__init__()\n        backbone = timm.create_model(model_name, pretrained=pretrained, **kwargs)\n        try:\n            n_features = backbone.classifier.in_features\n        except Exception as ex:\n            print(\"exception\", ex)\n            n_features = backbone.fc.in_features\n        self.backbone = nn.Sequential(*backbone.children())[:-2]\n        self.pool = nn.AdaptiveAvgPool2d((1, 1))\n        self.dropout = nn.Dropout(0.5)\n        self.classifier = nn.Linear(n_features, n_class)\n\n    def forward_features(self, x):\n        x = self.backbone(x)\n        return x\n\n    def forward(self, x):\n        feats = self.forward_features(x)\n        x = self.pool(feats).view(x.size(0), -1)\n        x = self.dropout(x)\n        x = self.classifier(x)\n        return x","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:44:21.082447Z","iopub.execute_input":"2022-12-06T03:44:21.083279Z","iopub.status.idle":"2022-12-06T03:44:21.096499Z","shell.execute_reply.started":"2022-12-06T03:44:21.08324Z","shell.execute_reply":"2022-12-06T03:44:21.095417Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class TIMMModel(LightningModule):\n    def __init__(self, config, weight):\n        super().__init__()\n        self.config = config\n        self.save_hyperparameters()\n        self.criterion = instantiate(self.config[\"loss\"], weight=weight)\n#         self.train_acc = torchmetrics.Accuracy()\n#         self.val_acc = torchmetrics.Accuracy()\n#         self.val_pf1 = PF1()\n        self.model = EfficientNetB3DSPlus(**self.config[\"arch\"])\n\n    def configure_optimizers(self):\n        optimizer = instantiate(self.config.optimizer, params=self.model.parameters())\n        scheduler = instantiate(self.config.lr_scheduler, optimizer=optimizer)\n        if \"ReduceLROnPlateau\" in self.config.lr_scheduler._target_:\n            return {\n                \"optimizer\": optimizer,\n                \"lr_scheduler\": scheduler,\n                \"monitor\": self.config.monitor,\n            }\n        # return [optimizer], [scheduler]\n        return {\n            \"optimizer\": optimizer,\n            \"lr_scheduler\": {\n                \"scheduler\": scheduler,\n                \"interval\": \"epoch\",\n                \"monitor\": self.config.monitor,\n            },\n        }\n\n    def forward(self, x):\n        x = self.model(x)\n        return x\n\n    def step(self, batch):\n        x, y = batch\n        logits = self.forward(x)\n        loss = self.criterion(logits, y)\n        preds = torch.argmax(logits, dim=1)\n        return loss, logits, preds, y\n\n    def training_step(self, batch, batch_idx) -> None:\n        loss, logits, preds, targets = self.step(batch)\n        acc = self.train_acc(preds, targets)\n\n        self.log(\n            \"train/loss\",\n            loss,\n            on_step=False,\n            on_epoch=True,\n            prog_bar=True,\n            sync_dist=self.config.sync_dist,\n        )\n        self.log(\n            \"train/acc\",\n            acc,\n            on_step=False,\n            on_epoch=True,\n            prog_bar=True,\n            sync_dist=self.config.sync_dist,\n        )\n        return {\"loss\": loss}\n\n    def validation_step(self, batch, batch_idx) -> None:\n        val_loss, val_logits, val_preds, val_targets = self.step(batch)\n        val_acc = self.val_acc(val_preds, val_targets)\n        val_logits = F.softmax(val_logits, dim=-1)\n        self.val_pf1.update(val_logits[:, 1], val_targets)\n        val_pf1 = self.val_pf1.compute()\n        self.log(\n            \"val/loss\",\n            val_loss,\n            on_step=False,\n            on_epoch=True,\n            prog_bar=True,\n            sync_dist=self.config.sync_dist,\n        )\n        self.log(\n            \"val/acc\",\n            val_acc,\n            on_step=False,\n            on_epoch=True,\n            prog_bar=True,\n            sync_dist=self.config.sync_dist,\n        )\n        self.log(\n            \"val/pf1\",\n            val_pf1,\n            on_step=False,\n            on_epoch=True,\n            prog_bar=True,\n            sync_dist=self.config.sync_dist,\n        )\n        return {\"val_loss\": val_loss}\n\n    def test_step(self, batch, batch_idx) -> None:\n        raise NotImplementedError\n\n    def on_epoch_end(self):\n        self.train_acc.reset()\n        self.val_acc.reset()\n        self.val_pf1.reset()","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:44:21.102549Z","iopub.execute_input":"2022-12-06T03:44:21.103544Z","iopub.status.idle":"2022-12-06T03:44:21.124936Z","shell.execute_reply.started":"2022-12-06T03:44:21.103501Z","shell.execute_reply":"2022-12-06T03:44:21.123819Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"MODEL_CONFIG = {\n    \"arch\": {\n        \"n_class\": 2,\n        \"model_name\": \"tf_efficientnet_b0_ns\"\n    },\n    \"loss\": {\"_target_\": \"torch.nn.CrossEntropyLoss\"}\n    \n}\nINFER_CONFIG = {\n    \"crop_size\": 512,\n}\nINPUT_DIR = '/kaggle/input/rsna-breast-cancer-detection'\nCHECKPOINT_PATH = '/kaggle/input/eff-b0-checkpoint-f1-0107/checkpoint-epoch16-step23222-val_pf10.107-val_acc0.960-val_loss1.019.ckpt'\nweight = torch.tensor([0.5, 0.5], dtype=torch.float32)","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:44:21.126836Z","iopub.execute_input":"2022-12-06T03:44:21.127677Z","iopub.status.idle":"2022-12-06T03:44:21.140276Z","shell.execute_reply.started":"2022-12-06T03:44:21.127641Z","shell.execute_reply":"2022-12-06T03:44:21.13937Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = TIMMModel(MODEL_CONFIG, weight)","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:44:21.142061Z","iopub.execute_input":"2022-12-06T03:44:21.14252Z","iopub.status.idle":"2022-12-06T03:44:21.27322Z","shell.execute_reply.started":"2022-12-06T03:44:21.142485Z","shell.execute_reply":"2022-12-06T03:44:21.272244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ckpt = torch.load(CHECKPOINT_PATH)","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:44:21.275109Z","iopub.execute_input":"2022-12-06T03:44:21.275871Z","iopub.status.idle":"2022-12-06T03:44:21.47501Z","shell.execute_reply.started":"2022-12-06T03:44:21.27582Z","shell.execute_reply":"2022-12-06T03:44:21.474013Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.load_state_dict(ckpt[\"state_dict\"])","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:44:21.477411Z","iopub.execute_input":"2022-12-06T03:44:21.477798Z","iopub.status.idle":"2022-12-06T03:44:21.527484Z","shell.execute_reply.started":"2022-12-06T03:44:21.477761Z","shell.execute_reply":"2022-12-06T03:44:21.52545Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"device = \"cuda\" if torch.cuda.is_available() else \"cpu\"","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:44:21.528849Z","iopub.execute_input":"2022-12-06T03:44:21.529804Z","iopub.status.idle":"2022-12-06T03:44:21.534961Z","shell.execute_reply.started":"2022-12-06T03:44:21.529767Z","shell.execute_reply":"2022-12-06T03:44:21.534038Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.eval().to(device)","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:44:21.536498Z","iopub.execute_input":"2022-12-06T03:44:21.5374Z","iopub.status.idle":"2022-12-06T03:44:21.574645Z","shell.execute_reply.started":"2022-12-06T03:44:21.537339Z","shell.execute_reply":"2022-12-06T03:44:21.573733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_image_transforms(input_size, augment, augment_config=None):\n    transforms = []\n    if augment and augment_config:\n        transforms += [tvf.Resize([input_size, input_size])]\n        for aug in augment_config:\n            transforms += [hydra.utils.instantiate(augment_config[aug])]\n        transforms += [\n            tvf.ToTensor(),\n        ]\n    else:\n        transforms += [\n            tvf.Resize([input_size, input_size]),\n            tvf.ToTensor(),\n        ]\n    transforms = tvf.Compose(transforms)\n    return transforms","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:44:21.576198Z","iopub.execute_input":"2022-12-06T03:44:21.576841Z","iopub.status.idle":"2022-12-06T03:44:21.584484Z","shell.execute_reply.started":"2022-12-06T03:44:21.576806Z","shell.execute_reply":"2022-12-06T03:44:21.583327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transforms = get_image_transforms(INFER_CONFIG[\"crop_size\"], False, None)","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:44:21.586131Z","iopub.execute_input":"2022-12-06T03:44:21.586797Z","iopub.status.idle":"2022-12-06T03:44:21.600134Z","shell.execute_reply.started":"2022-12-06T03:44:21.586762Z","shell.execute_reply":"2022-12-06T03:44:21.599114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_images = glob.glob(\"/kaggle/input/rsna-breast-cancer-detection/test_images/*/*.dcm\")\nprint(\"Number of images :\", len(test_images))","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:44:21.601826Z","iopub.execute_input":"2022-12-06T03:44:21.602301Z","iopub.status.idle":"2022-12-06T03:44:21.617567Z","shell.execute_reply.started":"2022-12-06T03:44:21.602262Z","shell.execute_reply":"2022-12-06T03:44:21.61594Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"SAVE_FOLDER = \"/kaggle/tmp/output/\"\nSIZE = 512\nEXTENSION = \"png\"\n\nos.makedirs(SAVE_FOLDER, exist_ok=True)","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:44:21.619538Z","iopub.execute_input":"2022-12-06T03:44:21.620909Z","iopub.status.idle":"2022-12-06T03:44:21.628121Z","shell.execute_reply.started":"2022-12-06T03:44:21.620859Z","shell.execute_reply":"2022-12-06T03:44:21.626976Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def process(f, size=512, save_folder=\"\", extension=\"png\"):\n    patient = f.split('/')[-2]\n    image = f.split('/')[-1][:-4]\n\n    dicom = pydicom.dcmread(f)\n    img = dicom.pixel_array\n\n    img = (img - img.min()) / (img.max() - img.min())\n\n    if dicom.PhotometricInterpretation == \"MONOCHROME1\":\n        img = 1 - img\n\n    img = cv2.resize(img, (size, size))\n\n    cv2.imwrite(save_folder + f\"{patient}_{image}.{extension}\", (img * 255).astype(np.uint8))","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:44:21.629808Z","iopub.execute_input":"2022-12-06T03:44:21.630545Z","iopub.status.idle":"2022-12-06T03:44:21.64304Z","shell.execute_reply.started":"2022-12-06T03:44:21.63051Z","shell.execute_reply":"2022-12-06T03:44:21.641966Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"_ = Parallel(n_jobs=4)(\n    delayed(process)(uid, size=SIZE, save_folder=SAVE_FOLDER, extension=EXTENSION)\n    for uid in tqdm(test_images)\n)","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:44:21.64472Z","iopub.execute_input":"2022-12-06T03:44:21.645493Z","iopub.status.idle":"2022-12-06T03:44:23.718336Z","shell.execute_reply.started":"2022-12-06T03:44:21.645457Z","shell.execute_reply":"2022-12-06T03:44:23.717403Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv(\"/kaggle/input/rsna-breast-cancer-detection/test.csv\")\ndf['path'] = df[\"patient_id\"].astype(str) + \"_\" + df[\"image_id\"].astype(str) + \".png\"\ndf['cancer'] = 0","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:44:45.534737Z","iopub.execute_input":"2022-12-06T03:44:45.535659Z","iopub.status.idle":"2022-12-06T03:44:45.553903Z","shell.execute_reply.started":"2022-12-06T03:44:45.535623Z","shell.execute_reply":"2022-12-06T03:44:45.553046Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:44:46.500929Z","iopub.execute_input":"2022-12-06T03:44:46.501323Z","iopub.status.idle":"2022-12-06T03:44:46.516741Z","shell.execute_reply.started":"2022-12-06T03:44:46.501286Z","shell.execute_reply":"2022-12-06T03:44:46.515598Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class LivenessDataset(Dataset):\n    def __init__(\n        self, df, data_dir, transforms=None, crop_size=256\n    ) -> None:\n        super().__init__()\n        self.data_dir = Path(data_dir)\n        self.paths = df['path']\n        self.labels = list(map(str, df['cancer']))\n\n        self.input_size = crop_size\n        self.transforms = transforms\n\n    def __getitem__(self, index):\n        img_path = os.path.join(self.data_dir, self.paths[index])\n        image = Image.open(img_path).convert('RGB')\n        if self.transforms is not None:\n            image = self.transforms(image)\n\n        label = torch.tensor(int(self.labels[index]))\n        return image, label\n\n    def __len__(self):\n        return len(self.labels)","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:44:47.456948Z","iopub.execute_input":"2022-12-06T03:44:47.457324Z","iopub.status.idle":"2022-12-06T03:44:57.490149Z","shell.execute_reply.started":"2022-12-06T03:44:47.457291Z","shell.execute_reply":"2022-12-06T03:44:57.488909Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset = LivenessDataset(\n            df=df,\n            data_dir=SAVE_FOLDER,\n            crop_size=INFER_CONFIG[\"crop_size\"],\n            transforms=transforms\n        )","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:44:57.492587Z","iopub.execute_input":"2022-12-06T03:44:57.493647Z","iopub.status.idle":"2022-12-06T03:44:57.511525Z","shell.execute_reply.started":"2022-12-06T03:44:57.4936Z","shell.execute_reply":"2022-12-06T03:44:57.510396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataloader = DataLoader(\n            dataset,\n            batch_size=16,\n            shuffle=False,\n            num_workers=2,\n            pin_memory=True,\n            drop_last=False,\n        )","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:45:10.803536Z","iopub.execute_input":"2022-12-06T03:45:10.804042Z","iopub.status.idle":"2022-12-06T03:45:10.809082Z","shell.execute_reply.started":"2022-12-06T03:45:10.804008Z","shell.execute_reply":"2022-12-06T03:45:10.808138Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds_list = []\nfor batch in dataloader:\n    image = batch[0].to(device)\n    logits = model(image)\n    logits = F.softmax(logits, dim=-1)\n    preds = logits[:, 1].tolist()\n    preds_list.extend(preds)\n\n","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:45:11.899118Z","iopub.execute_input":"2022-12-06T03:45:11.90002Z","iopub.status.idle":"2022-12-06T03:45:12.243136Z","shell.execute_reply.started":"2022-12-06T03:45:11.899978Z","shell.execute_reply":"2022-12-06T03:45:12.236414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(preds_list)","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:45:13.964773Z","iopub.execute_input":"2022-12-06T03:45:13.965374Z","iopub.status.idle":"2022-12-06T03:45:13.971844Z","shell.execute_reply.started":"2022-12-06T03:45:13.965325Z","shell.execute_reply":"2022-12-06T03:45:13.970814Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['cancer'] = preds_list","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:45:16.168801Z","iopub.execute_input":"2022-12-06T03:45:16.169788Z","iopub.status.idle":"2022-12-06T03:45:16.175594Z","shell.execute_reply.started":"2022-12-06T03:45:16.169751Z","shell.execute_reply":"2022-12-06T03:45:16.174415Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub = df[['prediction_id', 'cancer']].groupby(\"prediction_id\").mean().reset_index()\nsub.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:45:16.902737Z","iopub.execute_input":"2022-12-06T03:45:16.90308Z","iopub.status.idle":"2022-12-06T03:45:16.922918Z","shell.execute_reply.started":"2022-12-06T03:45:16.90305Z","shell.execute_reply":"2022-12-06T03:45:16.922021Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-06T03:45:18.401908Z","iopub.execute_input":"2022-12-06T03:45:18.402285Z","iopub.status.idle":"2022-12-06T03:45:18.413064Z","shell.execute_reply.started":"2022-12-06T03:45:18.402253Z","shell.execute_reply":"2022-12-06T03:45:18.412032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}