{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Cassava Leaf Disease Classification - Exploratory Data Analysis\n\nQuick Exploratory Data Analysis for [Cassava Leaf Disease Classification](https://www.kaggle.com/c/cassava-leaf-disease-classification) challenge    \n\nThis competition will challenge you to distinguish between several diseases that cause material harm to the food supply of many African countries. In some cases the main remedy is to burn the infected plants to prevent further spread, which can make a rapid automated turnaround quite useful to the farmers.","metadata":{}},{"cell_type":"markdown","source":"![](https://storage.googleapis.com/kaggle-competitions/kaggle/13836/logos/header.png)","metadata":{}},{"cell_type":"markdown","source":"<a id=\"top\"></a>\n\n<div class=\"list-group\" id=\"list-tab\" role=\"tablist\">\n<h3 class=\"list-group-item list-group-item-action active\" data-toggle=\"list\" style='color:black; background:#5BEB9C; border:0' role=\"tab\" aria-controls=\"home\"><center>Quick Navigation</center></h3>\n\n* [Overview](#1)\n    \n    \n* [General Visualization](#2)\n* [0 - CBB - Cassava Bacterial Blight](#3)\n* [1 - CBSD - Cassava Brown Streak Disease](#4)\n* [2 - CGM - Cassava Green Mottle](#5)\n* [3 - CMD - Cassava Mosaic Disease](#6)\n* [4 - Healthy](#7)\n    \n    \n* [Augmentation Examples](#50)\n    \n    \n* [Submission Example](#100)","metadata":{}},{"cell_type":"markdown","source":"<a id=\"1\"></a>\n<h2 style='background:#5BEB9C; border:0; color:black'><center>Overview<center><h2>","metadata":{}},{"cell_type":"code","source":"import os\nimport json\n\nimport numpy as np\nimport pandas as pd\nimport seaborn as sn\nimport matplotlib.pyplot as plt\nimport cv2\nimport albumentations as A\nfrom sklearn import metrics as sk_metrics","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-12-14T05:37:54.383421Z","iopub.execute_input":"2022-12-14T05:37:54.383789Z","iopub.status.idle":"2022-12-14T05:37:54.389865Z","shell.execute_reply.started":"2022-12-14T05:37:54.383758Z","shell.execute_reply":"2022-12-14T05:37:54.388606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BASE_DIR = \"../input/cassava-leaf-disease-classification/\"","metadata":{"execution":{"iopub.status.busy":"2022-12-14T05:37:56.567929Z","iopub.execute_input":"2022-12-14T05:37:56.568747Z","iopub.status.idle":"2022-12-14T05:37:56.573906Z","shell.execute_reply.started":"2022-12-14T05:37:56.568697Z","shell.execute_reply":"2022-12-14T05:37:56.572801Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"In this competition we have 5 classes: **4 diseases** and **1 healthy**   \nWe can find the mapping between the class number and its name in the file label_num_to_disease_map.json","metadata":{}},{"cell_type":"code","source":"with open(os.path.join(BASE_DIR, \"label_num_to_disease_map.json\")) as file:\n    map_classes = json.loads(file.read())\n    map_classes = {int(k) : v for k, v in map_classes.items()}\n    \nprint(json.dumps(map_classes, indent=4))","metadata":{"execution":{"iopub.status.busy":"2022-12-14T05:38:00.054262Z","iopub.execute_input":"2022-12-14T05:38:00.054673Z","iopub.status.idle":"2022-12-14T05:38:00.068082Z","shell.execute_reply.started":"2022-12-14T05:38:00.054639Z","shell.execute_reply":"2022-12-14T05:38:00.066654Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"input_files = os.listdir(os.path.join(BASE_DIR, \"train_images\"))\nprint(f\"Number of train images: {len(input_files)}\")","metadata":{"execution":{"iopub.status.busy":"2022-12-14T05:38:02.099336Z","iopub.execute_input":"2022-12-14T05:38:02.099738Z","iopub.status.idle":"2022-12-14T05:38:02.496924Z","shell.execute_reply.started":"2022-12-14T05:38:02.099702Z","shell.execute_reply":"2022-12-14T05:38:02.495817Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's take a look at the dimensions of the first 300 images   \nAs you can see below, all images are the same size (600, 800, 3)","metadata":{}},{"cell_type":"code","source":"img_shapes = {}\nfor image_name in os.listdir(os.path.join(BASE_DIR, \"train_images\"))[:300]:\n    image = cv2.imread(os.path.join(BASE_DIR, \"train_images\", image_name))\n    img_shapes[image.shape] = img_shapes.get(image.shape, 0) + 1\n\nprint(img_shapes)","metadata":{"execution":{"iopub.status.busy":"2022-12-14T05:38:04.665670Z","iopub.execute_input":"2022-12-14T05:38:04.666041Z","iopub.status.idle":"2022-12-14T05:38:09.161663Z","shell.execute_reply.started":"2022-12-14T05:38:04.666008Z","shell.execute_reply":"2022-12-14T05:38:09.160536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's load the training dataframe and add a column with the real class name to it.","metadata":{}},{"cell_type":"code","source":"df_train = pd.read_csv(os.path.join(BASE_DIR, \"train.csv\"))\n\ndf_train[\"class_name\"] = df_train[\"label\"].map(map_classes)\n\ndf_train","metadata":{"execution":{"iopub.status.busy":"2022-12-14T05:38:19.028932Z","iopub.execute_input":"2022-12-14T05:38:19.029561Z","iopub.status.idle":"2022-12-14T05:38:19.091511Z","shell.execute_reply.started":"2022-12-14T05:38:19.029497Z","shell.execute_reply":"2022-12-14T05:38:19.090203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's look at the number of pictures in each class.","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(8, 4))\nsn.countplot(y=\"class_name\", data=df_train);","metadata":{"execution":{"iopub.status.busy":"2022-12-14T05:38:23.221030Z","iopub.execute_input":"2022-12-14T05:38:23.221498Z","iopub.status.idle":"2022-12-14T05:38:23.396260Z","shell.execute_reply.started":"2022-12-14T05:38:23.221434Z","shell.execute_reply":"2022-12-14T05:38:23.395093Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"As we can see, the dataset has a fairly large imbalance.","metadata":{}},{"cell_type":"markdown","source":"<a id=\"2\"></a>\n<h2 style='background:#5BEB9C; border:0; color:black'><center>General Visualization<center><h2>","metadata":{}},{"cell_type":"code","source":"def visualize_batch(image_ids, labels):\n    plt.figure(figsize=(16, 12))\n    \n    for ind, (image_id, label) in enumerate(zip(image_ids, labels)):\n        plt.subplot(3, 3, ind + 1)\n        image = cv2.imread(os.path.join(BASE_DIR, \"train_images\", image_id))\n        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n\n        plt.imshow(image)\n        plt.title(f\"Class: {label}\", fontsize=12)\n        plt.axis(\"off\")\n    \n    plt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-12-14T05:38:27.853835Z","iopub.execute_input":"2022-12-14T05:38:27.854625Z","iopub.status.idle":"2022-12-14T05:38:27.864226Z","shell.execute_reply.started":"2022-12-14T05:38:27.854577Z","shell.execute_reply":"2022-12-14T05:38:27.863110Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tmp_df = df_train.sample(9)\nimage_ids = tmp_df[\"image_id\"].values\nlabels = tmp_df[\"class_name\"].values\n\nvisualize_batch(image_ids, labels)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-12-14T05:38:35.476561Z","iopub.execute_input":"2022-12-14T05:38:35.477226Z","iopub.status.idle":"2022-12-14T05:38:36.778435Z","shell.execute_reply.started":"2022-12-14T05:38:35.477188Z","shell.execute_reply":"2022-12-14T05:38:36.777501Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"3\"></a>\n<h2 style='background:#5BEB9C; border:0; color:black'><center>0 - CBB - Cassava Bacterial Blight<center><h2>","metadata":{}},{"cell_type":"markdown","source":"<img style=\"height:300px\" src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1865449%2Fbe9cdd94efb9b1660066ad10b55c8626%2Fbact_bright.jpeg?generation=1605827469211692&alt=media\">\n<cite>The image from discussion: <a href=\"https://www.kaggle.com/c/cassava-leaf-disease-classification/discussion/198143\">Cassava Lead Diseases: Overview</a></cite>","metadata":{}},{"cell_type":"code","source":"tmp_df = df_train[df_train[\"label\"] == 0]\nprint(f\"Total train images for class 0: {tmp_df.shape[0]}\")\n\ntmp_df = tmp_df.sample(9)\nimage_ids = tmp_df[\"image_id\"].values\nlabels = tmp_df[\"label\"].values\n\nvisualize_batch(image_ids, labels)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-12-14T05:38:57.185775Z","iopub.execute_input":"2022-12-14T05:38:57.186185Z","iopub.status.idle":"2022-12-14T05:38:58.657258Z","shell.execute_reply.started":"2022-12-14T05:38:57.186141Z","shell.execute_reply":"2022-12-14T05:38:58.655698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"4\"></a>\n<h2 style='background:#5BEB9C; border:0; color:black'><center>1 - CBSD - Cassava Brown Streak Disease<center><h2>","metadata":{}},{"cell_type":"markdown","source":"<img style=\"height:300px\" src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1865449%2Ffeba3dafc914d04517659650d137b77a%2Fbrown_st.jpeg?generation=1605830407530983&alt=media\">\n<cite>The image from discussion: <a href=\"https://www.kaggle.com/c/cassava-leaf-disease-classification/discussion/198143\">Cassava Lead Diseases: Overview</a></cite>","metadata":{}},{"cell_type":"code","source":"tmp_df = df_train[df_train[\"label\"] == 1]\nprint(f\"Total train images for class 1: {tmp_df.shape[0]}\")\n\ntmp_df = tmp_df.sample(9)\nimage_ids = tmp_df[\"image_id\"].values\nlabels = tmp_df[\"label\"].values\n\nvisualize_batch(image_ids, labels)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-12-14T05:39:05.560956Z","iopub.execute_input":"2022-12-14T05:39:05.561338Z","iopub.status.idle":"2022-12-14T05:39:06.859678Z","shell.execute_reply.started":"2022-12-14T05:39:05.561306Z","shell.execute_reply":"2022-12-14T05:39:06.858302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"5\"></a>\n<h2 style='background:#5BEB9C; border:0; color:black'><center>2 - CGM - Cassava Green Mottle<center><h2>","metadata":{}},{"cell_type":"markdown","source":"<img style=\"height:300px\" src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1865449%2F4f2975866feb2a1d4ef4111c2d57db29%2Fgreen_mottle.jpeg?generation=1605829101431013&alt=media\">\n<cite>The image from discussion: <a href=\"https://www.kaggle.com/c/cassava-leaf-disease-classification/discussion/198143\">Cassava Lead Diseases: Overview</a></cite>","metadata":{}},{"cell_type":"code","source":"tmp_df = df_train[df_train[\"label\"] == 2]\nprint(f\"Total train images for class 2: {tmp_df.shape[0]}\")\n\ntmp_df = tmp_df.sample(9)\nimage_ids = tmp_df[\"image_id\"].values\nlabels = tmp_df[\"label\"].values\n\nvisualize_batch(image_ids, labels)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-12-14T05:39:10.574443Z","iopub.execute_input":"2022-12-14T05:39:10.574863Z","iopub.status.idle":"2022-12-14T05:39:11.830327Z","shell.execute_reply.started":"2022-12-14T05:39:10.574823Z","shell.execute_reply":"2022-12-14T05:39:11.829515Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"6\"></a>\n<h2 style='background:#5BEB9C; border:0; color:black'><center>3 - CMD - Cassava Mosaic Disease<center><h2>","metadata":{}},{"cell_type":"markdown","source":"<img style=\"height:300px\" src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1865449%2F36990f77ded6667e5c30d19b5405d4d3%2Fmosaic_disease.jpeg?generation=1605829705010773&alt=media\">\n<cite>The image from discussion: <a href=\"https://www.kaggle.com/c/cassava-leaf-disease-classification/discussion/198143\">Cassava Lead Diseases: Overview</a></cite>","metadata":{}},{"cell_type":"code","source":"tmp_df = df_train[df_train[\"label\"] == 3]\nprint(f\"Total train images for class 3: {tmp_df.shape[0]}\")\n\ntmp_df = tmp_df.sample(9)\nimage_ids = tmp_df[\"image_id\"].values\nlabels = tmp_df[\"label\"].values\n\nvisualize_batch(image_ids, labels)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-12-14T05:39:17.117788Z","iopub.execute_input":"2022-12-14T05:39:17.118396Z","iopub.status.idle":"2022-12-14T05:39:18.565829Z","shell.execute_reply.started":"2022-12-14T05:39:17.118356Z","shell.execute_reply":"2022-12-14T05:39:18.564917Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"7\"></a>\n<h2 style='background:#5BEB9C; border:0; color:black'><center>4 - Healthy<center><h2>","metadata":{}},{"cell_type":"code","source":"tmp_df = df_train[df_train[\"label\"] == 4]\nprint(f\"Total train images for class 4: {tmp_df.shape[0]}\")\n\ntmp_df = tmp_df.sample(9)\nimage_ids = tmp_df[\"image_id\"].values\nlabels = tmp_df[\"label\"].values\n\nvisualize_batch(image_ids, labels)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-12-14T05:39:21.767544Z","iopub.execute_input":"2022-12-14T05:39:21.767894Z","iopub.status.idle":"2022-12-14T05:39:23.025552Z","shell.execute_reply.started":"2022-12-14T05:39:21.767864Z","shell.execute_reply":"2022-12-14T05:39:23.024637Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"50\"></a>\n<h2 style='background:#5BEB9C; border:0; color:black'><center>Augmentation Examples<center><h2>","metadata":{}},{"cell_type":"markdown","source":"Image augmentation is a process of creating new training examples from the existing ones. To make a new sample, you slightly change the original image. For instance, you could make a new image a little brighter; you could cut a piece from the original image; you could make a new image by mirroring the original one, etc. [[source]](https://albumentations.ai/docs/introduction/image_augmentation/)","metadata":{}},{"cell_type":"markdown","source":"<img style=\"height:500px\" src=\"https://albumentations.ai/docs/images/introduction/image_augmentation/augmentation.jpg\">\n<cite>The image from the <a href=\"https://albumentations.ai/docs/introduction/image_augmentation/\">Albumentations Documentation</a></cite>","metadata":{}},{"cell_type":"code","source":"def plot_augmentation(image_id, transform):\n    plt.figure(figsize=(16, 4))\n    img = cv2.imread(os.path.join(BASE_DIR, \"train_images\", image_id))\n    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n\n    plt.subplot(1, 3, 1)\n    plt.imshow(img)\n    plt.axis(\"off\")\n\n    plt.subplot(1, 3, 2)\n    x = transform(image=img)[\"image\"]\n    plt.imshow(x)\n    plt.axis(\"off\")\n\n    plt.subplot(1, 3, 3)\n    x = transform(image=img)[\"image\"]\n    plt.imshow(x)\n    plt.axis(\"off\")\n    \n    plt.show()","metadata":{"_kg_hide-input":true,"_kg_hide-output":false,"execution":{"iopub.status.busy":"2022-12-14T05:39:42.044206Z","iopub.execute_input":"2022-12-14T05:39:42.044909Z","iopub.status.idle":"2022-12-14T05:39:42.052738Z","shell.execute_reply.started":"2022-12-14T05:39:42.044866Z","shell.execute_reply":"2022-12-14T05:39:42.051624Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Since we have a fairly limited number of some classes, we can use augmentation    \nThis section shows examples of augmentation using the [albumentations](https://albumentations.ai/) library","metadata":{}},{"cell_type":"markdown","source":"The example below uses rotate-shift-scale augmentation with specular edge complementation. For this kind of pictures, this augmentation looks quite natural.","metadata":{}},{"cell_type":"code","source":"transform_shift_scale_rotate = A.ShiftScaleRotate(\n    p=1.0, \n    shift_limit=(-0.3, 0.3), \n    scale_limit=(-0.1, 0.1), \n    rotate_limit=(-180, 180), \n    interpolation=0, \n    border_mode=4, \n)\n\nplot_augmentation(\"1003442061.jpg\", transform_shift_scale_rotate)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-12-14T05:39:44.225390Z","iopub.execute_input":"2022-12-14T05:39:44.225771Z","iopub.status.idle":"2022-12-14T05:39:44.618355Z","shell.execute_reply.started":"2022-12-14T05:39:44.225733Z","shell.execute_reply":"2022-12-14T05:39:44.617354Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Another useful augmentation could be CoarseDropout. Thanks to this augmentation, you can complicate the life of the model so that she does not look too closely at some of the details of the image.   \nLet's look at the example below:","metadata":{}},{"cell_type":"code","source":"transform_coarse_dropout = A.CoarseDropout(\n    p=1.0, \n    max_holes=100, \n    max_height=50, \n    max_width=50, \n    min_holes=30, \n    min_height=20, \n    min_width=20,\n)\n\nplot_augmentation(\"1003442061.jpg\", transform_coarse_dropout)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-12-14T05:39:49.588264Z","iopub.execute_input":"2022-12-14T05:39:49.588802Z","iopub.status.idle":"2022-12-14T05:39:49.920815Z","shell.execute_reply.started":"2022-12-14T05:39:49.588768Z","shell.execute_reply":"2022-12-14T05:39:49.919860Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We can compose two or more augmentations into one process.    \nFor example, let's use shift-scale-rotate and CoarseDropout consistently:","metadata":{}},{"cell_type":"code","source":"transform = A.Compose(\n    transforms=[\n        transform_shift_scale_rotate,\n        transform_coarse_dropout,\n    ],\n    p=1.0,\n)\n\nplot_augmentation(\"1003442061.jpg\", transform)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-12-14T05:39:52.169505Z","iopub.execute_input":"2022-12-14T05:39:52.170157Z","iopub.status.idle":"2022-12-14T05:39:52.552259Z","shell.execute_reply.started":"2022-12-14T05:39:52.170115Z","shell.execute_reply":"2022-12-14T05:39:52.551367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"100\"></a>\n<h2 style='background:#5BEB9C; border:0; color:black'><center>Submission Example<center><h2>","metadata":{}},{"cell_type":"markdown","source":"Load the submission template","metadata":{}},{"cell_type":"code","source":"df_sub = pd.read_csv(\"../input/cassava-leaf-disease-classification/sample_submission.csv\", index_col=0)\ndf_sub","metadata":{"execution":{"iopub.status.busy":"2022-12-14T05:39:56.922268Z","iopub.execute_input":"2022-12-14T05:39:56.922687Z","iopub.status.idle":"2022-12-14T05:39:56.937627Z","shell.execute_reply.started":"2022-12-14T05:39:56.922648Z","shell.execute_reply":"2022-12-14T05:39:56.936562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"As we can see only one file in the submission file","metadata":{}},{"cell_type":"code","source":"os.listdir(os.path.join(BASE_DIR, \"test_images\"))","metadata":{"execution":{"iopub.status.busy":"2022-12-14T05:39:59.093328Z","iopub.execute_input":"2022-12-14T05:39:59.093762Z","iopub.status.idle":"2022-12-14T05:39:59.105176Z","shell.execute_reply.started":"2022-12-14T05:39:59.093722Z","shell.execute_reply":"2022-12-14T05:39:59.103983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"This is because [it is a Code Competition](https://www.kaggle.com/c/cassava-leaf-disease-classification/overview/code-requirements), and the test data is hidden   \nYour notebook should correct working with unseen test dataset\n\nThe full set of test images will only be available to your notebook when it is submitted for scoring.    \nExpect to see roughly 15,000 images in the test set.    ","metadata":{}},{"cell_type":"markdown","source":"The metric of this competition is **Accuracy**.    \nAccuracy - the ratio of the number of samples predicted correctly to the total number of samples","metadata":{}},{"cell_type":"markdown","source":"$$Accuracy\\ Score = \\frac{The\\ number\\ of\\ samples\\ predicted\\ correctly}{Total\\ number\\ of\\ samples}$$","metadata":{}},{"cell_type":"markdown","source":"Let's calculate the accuracy on a training set if we select only one class for all examples.","metadata":{}},{"cell_type":"code","source":"for pred_class in range(0, 5):\n    y_true = df_train[\"label\"].values\n    y_pred = np.full_like(y_true, pred_class)\n    print(f\"accuracy score (predict {pred_class}): {sk_metrics.accuracy_score(y_true, y_pred):.3f}\")","metadata":{"execution":{"iopub.status.busy":"2022-12-14T05:40:01.443445Z","iopub.execute_input":"2022-12-14T05:40:01.444187Z","iopub.status.idle":"2022-12-14T05:40:01.459746Z","shell.execute_reply.started":"2022-12-14T05:40:01.444137Z","shell.execute_reply":"2022-12-14T05:40:01.458508Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Since we have a large imbalance of classes, if we predict the most frequent class, then our accuracy is greater in this case","metadata":{}},{"cell_type":"markdown","source":"Let's choose the most popular class of training set as the label for all images in test set","metadata":{}},{"cell_type":"code","source":"df_sub[\"label\"] = 3","metadata":{"execution":{"iopub.status.busy":"2022-12-14T05:40:03.073495Z","iopub.execute_input":"2022-12-14T05:40:03.073857Z","iopub.status.idle":"2022-12-14T05:40:03.079047Z","shell.execute_reply.started":"2022-12-14T05:40:03.073825Z","shell.execute_reply":"2022-12-14T05:40:03.077973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"And then write result to the submission file","metadata":{}},{"cell_type":"code","source":"df_sub.to_csv(\"submission.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-12-14T05:40:05.438827Z","iopub.execute_input":"2022-12-14T05:40:05.439189Z","iopub.status.idle":"2022-12-14T05:40:06.092943Z","shell.execute_reply.started":"2022-12-14T05:40:05.439159Z","shell.execute_reply":"2022-12-14T05:40:06.092196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"If you submit the result for evaluation, you will get an accuracy of 0.614 on a public liderboard (on the train it is 0.615). This may indicate that there is also an imbalance of classes on the public test distribution.","metadata":{}},{"cell_type":"markdown","source":"# WORK IN PROGRESS...","metadata":{}}]}