{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.11","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":13836,"databundleVersionId":1718836,"sourceType":"competition"}],"dockerImageVersionId":31041,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Import Toolkits","metadata":{}},{"cell_type":"code","source":"import os\nimport random\nfrom shutil import copy2\nfrom collections import Counter\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd\nimport PIL\nimport torch\nimport torchvision\nfrom torch.utils.data import DataLoader, random_split\nfrom torchvision import datasets , transforms\nfrom tqdm.notebook import tqdm","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-06-23T12:15:41.828154Z","iopub.execute_input":"2025-06-23T12:15:41.828938Z","iopub.status.idle":"2025-06-23T12:15:41.833332Z","shell.execute_reply.started":"2025-06-23T12:15:41.828911Z","shell.execute_reply":"2025-06-23T12:15:41.832591Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"torch version : \", torch.__version__)\nprint(\"torchvision version : \", torchvision.__version__)\nprint(\"numpy version : \", np.__version__)\n\n!python --version","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T11:45:51.391542Z","iopub.execute_input":"2025-06-23T11:45:51.391723Z","iopub.status.idle":"2025-06-23T11:45:51.539366Z","shell.execute_reply.started":"2025-06-23T11:45:51.391708Z","shell.execute_reply":"2025-06-23T11:45:51.538718Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Exploring our data","metadata":{}},{"cell_type":"code","source":"df = pd.read_csv(\"/kaggle/input/cassava-leaf-disease-classification/train.csv\")\ndf.sample(10)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T11:45:53.384157Z","iopub.execute_input":"2025-06-23T11:45:53.384675Z","iopub.status.idle":"2025-06-23T11:45:53.417839Z","shell.execute_reply.started":"2025-06-23T11:45:53.384639Z","shell.execute_reply":"2025-06-23T11:45:53.417282Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"label_map = {\n    0: \"Cassava Bacterial Blight (CBB)\",\n    1: \"Cassava Brown Streak Disease (CBSD)\",\n    2: \"Cassava Green Mottle (CGM)\",\n    3: \"Cassava Mosaic Disease (CMD)\",\n    4: \"Healthy\"\n}","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T11:45:55.219301Z","iopub.execute_input":"2025-06-23T11:45:55.219910Z","iopub.status.idle":"2025-06-23T11:45:55.223559Z","shell.execute_reply.started":"2025-06-23T11:45:55.219883Z","shell.execute_reply":"2025-06-23T11:45:55.222924Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data_dir = \"/kaggle/input/cassava-leaf-disease-classification\"","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T11:45:55.630369Z","iopub.execute_input":"2025-06-23T11:45:55.630700Z","iopub.status.idle":"2025-06-23T11:45:55.634110Z","shell.execute_reply.started":"2025-06-23T11:45:55.630676Z","shell.execute_reply":"2025-06-23T11:45:55.633573Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_dir = os.path.join(data_dir , \"train_images\")\ntrain_dir","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T11:45:56.204985Z","iopub.execute_input":"2025-06-23T11:45:56.205204Z","iopub.status.idle":"2025-06-23T11:45:56.210040Z","shell.execute_reply.started":"2025-06-23T11:45:56.205186Z","shell.execute_reply":"2025-06-23T11:45:56.209406Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"output_path = os.path.join(\"/kaggle/working/\" , \"train\")\nfor label in df['label'].unique():\n    class_name = label_map[label]\n    class_dir = os.path.join(output_path , class_name)\n    os.makedirs(class_dir , exist_ok = True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T11:45:58.224592Z","iopub.execute_input":"2025-06-23T11:45:58.225141Z","iopub.status.idle":"2025-06-23T11:45:58.229861Z","shell.execute_reply.started":"2025-06-23T11:45:58.225118Z","shell.execute_reply":"2025-06-23T11:45:58.229182Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for _ , row in df.iterrows():\n    filename = row['image_id']\n    label = row['label']\n    class_name = label_map[label]\n\n    src_path = os.path.join(train_dir , filename)\n    dst_path = os.path.join(output_path , class_name , filename)\n\n    shutil.copy(src_path , dst_path)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T11:45:58.848993Z","iopub.execute_input":"2025-06-23T11:45:58.849699Z","iopub.status.idle":"2025-06-23T11:46:48.583094Z","shell.execute_reply.started":"2025-06-23T11:45:58.849677Z","shell.execute_reply":"2025-06-23T11:46:48.582481Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"classes = os.listdir(output_path)\nclasses","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T11:46:48.584128Z","iopub.execute_input":"2025-06-23T11:46:48.584338Z","iopub.status.idle":"2025-06-23T11:46:48.589081Z","shell.execute_reply.started":"2025-06-23T11:46:48.584321Z","shell.execute_reply":"2025-06-23T11:46:48.588564Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Let's look at a few examples of each class","metadata":{}},{"cell_type":"code","source":"def sample_images(data_path , class_name):\n\n    class_dir = os.path.join(data_path , class_name)\n    \n    if not os.path.exists(class_dir):\n        return \"Invalid directory\"\n        \n    images_list = os.listdir(class_dir)\n\n    random_imgs = random.sample(images_list , 4)\n\n    #plot\n    plt.figure(figsize = (20,20))\n    \n    for i in range(4):\n        \n        img_loc = os.path.join(class_dir , random_imgs[i])\n        img = PIL.Image.open(img_loc)\n        plt.subplot(1,4,i + 1)\n        plt.imshow(img)\n        plt.axis(\"off\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T11:46:48.589707Z","iopub.execute_input":"2025-06-23T11:46:48.589904Z","iopub.status.idle":"2025-06-23T11:46:48.604210Z","shell.execute_reply.started":"2025-06-23T11:46:48.589888Z","shell.execute_reply":"2025-06-23T11:46:48.603558Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"First, let's look at some healthy plants.","metadata":{}},{"cell_type":"code","source":"classes","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T11:46:48.605783Z","iopub.execute_input":"2025-06-23T11:46:48.605980Z","iopub.status.idle":"2025-06-23T11:46:48.619467Z","shell.execute_reply.started":"2025-06-23T11:46:48.605965Z","shell.execute_reply":"2025-06-23T11:46:48.618881Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sample_images(output_path , classes[0])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T11:46:48.620040Z","iopub.execute_input":"2025-06-23T11:46:48.620237Z","iopub.status.idle":"2025-06-23T11:46:49.207928Z","shell.execute_reply.started":"2025-06-23T11:46:48.620222Z","shell.execute_reply":"2025-06-23T11:46:49.206897Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"let`s look at examples of the first disease class (green mottle virus).","metadata":{}},{"cell_type":"code","source":"sample_images(output_path , classes[4])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T11:46:49.208931Z","iopub.execute_input":"2025-06-23T11:46:49.209218Z","iopub.status.idle":"2025-06-23T11:46:49.800969Z","shell.execute_reply.started":"2025-06-23T11:46:49.209199Z","shell.execute_reply":"2025-06-23T11:46:49.800104Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"let`s look at examples of the second disease class (bacterial blight).","metadata":{}},{"cell_type":"code","source":"sample_images(output_path , classes[2])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T11:46:49.801673Z","iopub.execute_input":"2025-06-23T11:46:49.801915Z","iopub.status.idle":"2025-06-23T11:46:50.373780Z","shell.execute_reply.started":"2025-06-23T11:46:49.801891Z","shell.execute_reply":"2025-06-23T11:46:50.373041Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"let`s look at examples of the third disease class (brown streak disease).","metadata":{}},{"cell_type":"code","source":"sample_images(output_path , classes[1])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T11:46:50.374729Z","iopub.execute_input":"2025-06-23T11:46:50.374984Z","iopub.status.idle":"2025-06-23T11:46:50.933164Z","shell.execute_reply.started":"2025-06-23T11:46:50.374965Z","shell.execute_reply":"2025-06-23T11:46:50.932325Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"let`s look at examples of the fourth disease class (mosaic disease).","metadata":{}},{"cell_type":"code","source":"sample_images(output_path , classes[3])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T11:46:50.934008Z","iopub.execute_input":"2025-06-23T11:46:50.934228Z","iopub.status.idle":"2025-06-23T11:46:51.484706Z","shell.execute_reply.started":"2025-06-23T11:46:50.934210Z","shell.execute_reply":"2025-06-23T11:46:51.483843Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Preparing Our Data","metadata":{}},{"cell_type":"code","source":"class ConvertToRGB(object):\n    def __call__(self , img):\n        if img.mode != \"RGB\":\n            img =img.convert(\"RGB\")\n        return img","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T11:47:30.046088Z","iopub.execute_input":"2025-06-23T11:47:30.046810Z","iopub.status.idle":"2025-06-23T11:47:30.050581Z","shell.execute_reply.started":"2025-06-23T11:47:30.046786Z","shell.execute_reply":"2025-06-23T11:47:30.049817Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"transform_basic = transforms.Compose(\n    [\n        ConvertToRGB(),\n        transforms.Resize((224,224)),\n        transforms.ToTensor()\n    ]\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T11:47:30.829710Z","iopub.execute_input":"2025-06-23T11:47:30.829952Z","iopub.status.idle":"2025-06-23T11:47:30.834032Z","shell.execute_reply.started":"2025-06-23T11:47:30.829935Z","shell.execute_reply":"2025-06-23T11:47:30.833321Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"batch_size = 32\ndataset = datasets.ImageFolder(root = output_path , transform = transform_basic)\ndataset_loader = DataLoader(dataset = dataset , batch_size = batch_size)\nbatch_shape = next(iter(dataset_loader))[0].shape\nprint(\"Getting batches of shape:\", batch_shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T11:47:32.453649Z","iopub.execute_input":"2025-06-23T11:47:32.453910Z","iopub.status.idle":"2025-06-23T11:47:32.718726Z","shell.execute_reply.started":"2025-06-23T11:47:32.453893Z","shell.execute_reply":"2025-06-23T11:47:32.717972Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Normalized Data","metadata":{}},{"cell_type":"code","source":"def get_mean_std(loader):\n    \"\"\"Computes the mean and standard deviation of image data.\n\n    Input: a `DataLoader` producing tensors of shape [batch_size, channels, pixels_x, pixels_y]\n    Output: the mean of each channel as a tensor, the standard deviation of each channel as a tensor\n            formatted as a tuple (means[channels], std[channels])\"\"\"\n\n    channels_sum , channels_squared_sum , num_batches = 0 , 0 , 0\n    \n    for data , _ in tqdm(loader , desc = \"Computing mean and std\" , leave = True):\n        channels_sum += torch.mean(data , dim=[0,2,3])\n        channels_squared_sum += torch.mean(data**2 , dim= [0,2,3])\n        num_batches += 1\n\n    mean = channels_sum / num_batches\n    std = (channels_squared_sum / num_batches - mean**2) ** 0.5\n\n    return mean , std","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T11:47:40.388435Z","iopub.execute_input":"2025-06-23T11:47:40.388726Z","iopub.status.idle":"2025-06-23T11:47:40.393745Z","shell.execute_reply.started":"2025-06-23T11:47:40.388705Z","shell.execute_reply":"2025-06-23T11:47:40.392902Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"mean , std = get_mean_std(dataset_loader)\nprint(f\"Mean = {mean}\")\nprint(f\"Standard deviation = {std}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T11:47:42.884844Z","iopub.execute_input":"2025-06-23T11:47:42.885104Z","iopub.status.idle":"2025-06-23T11:50:01.583377Z","shell.execute_reply.started":"2025-06-23T11:47:42.885086Z","shell.execute_reply":"2025-06-23T11:50:01.582508Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"transform_norm = transforms.Compose(\n    [\n        ConvertToRGB(),\n        transforms.Resize((224,224)),\n        transforms.ToTensor(),\n        transforms.Normalize(mean = mean , std = std)\n    ]\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T11:54:40.747931Z","iopub.execute_input":"2025-06-23T11:54:40.748678Z","iopub.status.idle":"2025-06-23T11:54:40.752971Z","shell.execute_reply.started":"2025-06-23T11:54:40.748651Z","shell.execute_reply":"2025-06-23T11:54:40.752259Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"norm_dataset = datasets.ImageFolder(root = output_path , transform = transform_norm)\nnorm_loader = DataLoader(dataset = norm_dataset , batch_size = batch_size)\nbatch_shape = next(iter(norm_loader))[0].shape\nprint(\"Getting batches of shape\", batch_shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T11:56:26.166204Z","iopub.execute_input":"2025-06-23T11:56:26.166514Z","iopub.status.idle":"2025-06-23T11:56:26.428441Z","shell.execute_reply.started":"2025-06-23T11:56:26.166493Z","shell.execute_reply":"2025-06-23T11:56:26.427761Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"norm_mean , norm_std = get_mean_std(norm_loader)\nprint(f\"Mean = {norm_mean}\")\nprint(f\"Standard deviation = {norm_std}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T11:57:24.371600Z","iopub.execute_input":"2025-06-23T11:57:24.372189Z","iopub.status.idle":"2025-06-23T11:59:49.373845Z","shell.execute_reply.started":"2025-06-23T11:57:24.372166Z","shell.execute_reply":"2025-06-23T11:59:49.373002Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Train-Validation Split","metadata":{}},{"cell_type":"code","source":"train_dataset , val_dataset = random_split(norm_dataset , [0.8,0.2])\n\nlength_train = len(train_dataset)\nlength_val = len(val_dataset)\nlength_dataset = len(norm_dataset)\n\npercent_train = np.round(length_train * 100 / length_dataset , 2)\npercent_val = np.round(length_val * 100 / length_dataset , 2)\n\nprint(f\"Train data is {percent_train}% of full data\")\nprint(f\"Validation data is {percent_val}% of full data\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T12:02:48.533157Z","iopub.execute_input":"2025-06-23T12:02:48.533486Z","iopub.status.idle":"2025-06-23T12:02:48.539981Z","shell.execute_reply.started":"2025-06-23T12:02:48.533463Z","shell.execute_reply":"2025-06-23T12:02:48.539136Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def class_count(dataset):\n    c = Counter(x[1] for x in tqdm(dataset))\n    try:\n        class_to_index = dataset.class_to_idx\n    except AttributeError:\n        class_to_index = dataset.dataset.class_to_idx\n\n    return pd.Series({cat: c[idx] for cat , idx in class_to_index.items()})","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T12:42:01.856788Z","iopub.execute_input":"2025-06-23T12:42:01.857111Z","iopub.status.idle":"2025-06-23T12:42:01.861886Z","shell.execute_reply.started":"2025-06-23T12:42:01.857089Z","shell.execute_reply":"2025-06-23T12:42:01.861092Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_counts = class_count(train_dataset)\ntrain_counts","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T12:10:29.487059Z","iopub.execute_input":"2025-06-23T12:10:29.487768Z","iopub.status.idle":"2025-06-23T12:12:19.267969Z","shell.execute_reply.started":"2025-06-23T12:10:29.487732Z","shell.execute_reply":"2025-06-23T12:12:19.266986Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_counts.plot(kind=\"bar\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T12:12:19.269264Z","iopub.execute_input":"2025-06-23T12:12:19.269479Z","iopub.status.idle":"2025-06-23T12:12:19.451673Z","shell.execute_reply.started":"2025-06-23T12:12:19.269462Z","shell.execute_reply":"2025-06-23T12:12:19.450993Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val_counts = class_count(val_dataset)\nval_counts","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T12:13:49.813390Z","iopub.execute_input":"2025-06-23T12:13:49.814251Z","iopub.status.idle":"2025-06-23T12:14:16.165946Z","shell.execute_reply.started":"2025-06-23T12:13:49.814221Z","shell.execute_reply":"2025-06-23T12:14:16.165158Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val_counts.plot(kind= \"bar\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T12:14:16.167221Z","iopub.execute_input":"2025-06-23T12:14:16.167439Z","iopub.status.idle":"2025-06-23T12:14:16.513652Z","shell.execute_reply.started":"2025-06-23T12:14:16.167421Z","shell.execute_reply":"2025-06-23T12:14:16.512984Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Unbalanced Classes","metadata":{}},{"cell_type":"code","source":"def undersample_dataset(dataset_dir, output_dir, target_count=None):\n    \"\"\"\n    Undersample the dataset to have a uniform distribution across classes.\n\n    Parameters:\n    - dataset_dir: Path to the directory containing the class folders.\n    - output_dir: Path to the directory where the undersampled dataset will be stored.\n    - target_count: Number of instances to keep in each class. If None, the class with the least instances will set the target.\n    \"\"\"\n    # Mapping each class to its files\n    classes_files = {}\n    for class_name in os.listdir(dataset_dir):\n        class_dir = os.path.join(dataset_dir, class_name)\n        if os.path.isdir(class_dir):\n            files = os.listdir(class_dir)\n            classes_files[class_name] = files\n\n    # Determine the minimum class size if target_count is not set\n    if target_count is None:\n        target_count = min(len(files) for files in classes_files.values())\n\n    # Creating the output directory if it doesn't exist\n    if not os.path.exists(output_dir):\n        os.makedirs(output_dir)\n\n    # Perform undersampling\n    for class_name, files in classes_files.items():\n        print(\"Copying images for class\", class_name)\n        class_output_dir = os.path.join(output_dir, class_name)\n        if not os.path.exists(class_output_dir):\n            os.makedirs(class_output_dir)\n\n        # Randomly select target_count images\n        selected_files = random.sample(files, min(len(files), target_count))\n\n        # Copy selected files to the output directory\n        for file_name in tqdm(selected_files):\n            src_path = os.path.join(dataset_dir, class_name, file_name)\n            dst_path = os.path.join(class_output_dir, file_name)\n            copy2(src_path, dst_path)\n\n    print(f\"Undersampling completed. Each class has up to {target_count} instances.\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T12:15:47.139992Z","iopub.execute_input":"2025-06-23T12:15:47.140485Z","iopub.status.idle":"2025-06-23T12:15:47.147103Z","shell.execute_reply.started":"2025-06-23T12:15:47.140461Z","shell.execute_reply":"2025-06-23T12:15:47.146344Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"output_sampled_dir = os.path.join(\"/kaggle/working/\" , \"data_undersampled\", \"train\")\nprint(\"Output directory:\", output_sampled_dir)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T12:16:59.843341Z","iopub.execute_input":"2025-06-23T12:16:59.843670Z","iopub.status.idle":"2025-06-23T12:16:59.847979Z","shell.execute_reply.started":"2025-06-23T12:16:59.843645Z","shell.execute_reply":"2025-06-23T12:16:59.847361Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"undersample_dataset(output_path, output_sampled_dir)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T12:17:46.955850Z","iopub.execute_input":"2025-06-23T12:17:46.956330Z","iopub.status.idle":"2025-06-23T12:17:48.056608Z","shell.execute_reply.started":"2025-06-23T12:17:46.956308Z","shell.execute_reply":"2025-06-23T12:17:48.055822Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"undersampled_dataset = datasets.ImageFolder(root = output_sampled_dir , transform= transform_norm)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T12:39:00.802280Z","iopub.execute_input":"2025-06-23T12:39:00.802928Z","iopub.status.idle":"2025-06-23T12:39:00.820142Z","shell.execute_reply.started":"2025-06-23T12:39:00.802903Z","shell.execute_reply":"2025-06-23T12:39:00.819574Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"undersampled_dataset.classes","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T12:37:06.346033Z","iopub.execute_input":"2025-06-23T12:37:06.346673Z","iopub.status.idle":"2025-06-23T12:37:06.351073Z","shell.execute_reply.started":"2025-06-23T12:37:06.346650Z","shell.execute_reply":"2025-06-23T12:37:06.350552Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"undersample_counts = class_count(undersampled_dataset)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T12:42:20.010643Z","iopub.execute_input":"2025-06-23T12:42:20.010926Z","iopub.status.idle":"2025-06-23T12:42:53.964343Z","shell.execute_reply.started":"2025-06-23T12:42:20.010907Z","shell.execute_reply":"2025-06-23T12:42:53.963591Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"fig , ax = plt.subplots(figsize = (10,7))\nprint(undersample_counts)\nundersample_counts.plot(kind = \"bar\" , ax=ax);","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-23T12:42:56.456714Z","iopub.execute_input":"2025-06-23T12:42:56.457303Z","iopub.status.idle":"2025-06-23T12:42:56.606227Z","shell.execute_reply.started":"2025-06-23T12:42:56.457282Z","shell.execute_reply":"2025-06-23T12:42:56.605572Z"}},"outputs":[],"execution_count":null}]}