{"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":14774,"databundleVersionId":875431,"sourceType":"competition"}],"dockerImageVersionId":30665,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import shutil\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport os\nimport math\nimport random\nfrom time import perf_counter\nfrom IPython.display import Image, display\n\nimport tensorflow_datasets as tfds\nimport tensorflow as tf  # For tf.data\nimport keras\nfrom keras import layers\nfrom keras.applications import EfficientNetB6","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-03-19T13:07:39.819181Z","iopub.execute_input":"2024-03-19T13:07:39.819536Z","iopub.status.idle":"2024-03-19T13:07:52.803325Z","shell.execute_reply.started":"2024-03-19T13:07:39.819502Z","shell.execute_reply":"2024-03-19T13:07:52.802454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv(\"/kaggle/input/aptos2019-blindness-detection/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-03-19T13:07:52.804814Z","iopub.execute_input":"2024-03-19T13:07:52.805339Z","iopub.status.idle":"2024-03-19T13:07:52.829597Z","shell.execute_reply.started":"2024-03-19T13:07:52.805312Z","shell.execute_reply":"2024-03-19T13:07:52.828849Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.hist()","metadata":{"execution":{"iopub.status.busy":"2024-03-19T13:07:52.830675Z","iopub.execute_input":"2024-03-19T13:07:52.830969Z","iopub.status.idle":"2024-03-19T13:07:53.262157Z","shell.execute_reply.started":"2024-03-19T13:07:52.830944Z","shell.execute_reply":"2024-03-19T13:07:53.261210Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2024-03-19T13:07:53.264431Z","iopub.execute_input":"2024-03-19T13:07:53.264703Z","iopub.status.idle":"2024-03-19T13:07:53.277963Z","shell.execute_reply.started":"2024-03-19T13:07:53.264679Z","shell.execute_reply":"2024-03-19T13:07:53.277005Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train_df)","metadata":{"execution":{"iopub.status.busy":"2024-03-19T13:07:53.279019Z","iopub.execute_input":"2024-03-19T13:07:53.279317Z","iopub.status.idle":"2024-03-19T13:07:53.285378Z","shell.execute_reply.started":"2024-03-19T13:07:53.279293Z","shell.execute_reply":"2024-03-19T13:07:53.284420Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"first_image = \"/kaggle/input/aptos2019-blindness-detection/train_images/\" + train_df.iloc[0][\"id_code\"] + \".png\"\nfirst_image","metadata":{"execution":{"iopub.status.busy":"2024-03-19T13:07:53.286650Z","iopub.execute_input":"2024-03-19T13:07:53.286957Z","iopub.status.idle":"2024-03-19T13:07:53.297376Z","shell.execute_reply.started":"2024-03-19T13:07:53.286924Z","shell.execute_reply":"2024-03-19T13:07:53.296442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display(Image(filename=first_image))","metadata":{"execution":{"iopub.status.busy":"2024-03-19T13:07:53.298799Z","iopub.execute_input":"2024-03-19T13:07:53.299170Z","iopub.status.idle":"2024-03-19T13:07:53.490520Z","shell.execute_reply.started":"2024-03-19T13:07:53.299136Z","shell.execute_reply":"2024-03-19T13:07:53.487823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! mkdir dataset\n! mkdir dataset/no_dr\n! mkdir dataset/mild\n! mkdir dataset/moderate\n! mkdir dataset/severe\n! mkdir dataset/proliferative_dr","metadata":{"execution":{"iopub.status.busy":"2024-03-19T13:07:53.492196Z","iopub.execute_input":"2024-03-19T13:07:53.492489Z","iopub.status.idle":"2024-03-19T13:07:59.377178Z","shell.execute_reply.started":"2024-03-19T13:07:53.492463Z","shell.execute_reply":"2024-03-19T13:07:59.376116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"PATH = \"/kaggle/working/dataset/\"","metadata":{"execution":{"iopub.status.busy":"2024-03-19T13:07:59.378606Z","iopub.execute_input":"2024-03-19T13:07:59.378909Z","iopub.status.idle":"2024-03-19T13:07:59.383317Z","shell.execute_reply.started":"2024-03-19T13:07:59.378880Z","shell.execute_reply":"2024-03-19T13:07:59.382373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def splitDataByLabel(base_directory_path, df):\n  base_dataset_directory = base_directory_path # Ex: \"/content/dataset/train/\"\n  for i in range(len(df)):\n    dest_label = \"\"\n    filename = df.iloc[i][0] + \".png\"\n\n    if(df.iloc[i][\"diagnosis\"] == 0):\n      dest_label = \"no_dr/\"\n    if(df.iloc[i][\"diagnosis\"] == 1):\n      dest_label = \"mild/\"\n    if(df.iloc[i][\"diagnosis\"] == 2):\n      dest_label = \"moderate/\"\n    if(df.iloc[i][\"diagnosis\"] == 3):\n      dest_label = \"severe/\"\n    if(df.iloc[i][\"diagnosis\"] == 4):\n      dest_label = \"proliferative_dr/\"\n\n    src = base_dataset_directory + filename\n    dst = PATH + dest_label + filename\n\n    shutil.copy(src, dst)","metadata":{"execution":{"iopub.status.busy":"2024-03-19T13:07:59.387502Z","iopub.execute_input":"2024-03-19T13:07:59.387742Z","iopub.status.idle":"2024-03-19T13:07:59.396559Z","shell.execute_reply.started":"2024-03-19T13:07:59.387721Z","shell.execute_reply":"2024-03-19T13:07:59.395675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"splitDataByLabel('/kaggle/input/aptos2019-blindness-detection/train_images/', train_df)","metadata":{"execution":{"iopub.status.busy":"2024-03-19T13:07:59.397647Z","iopub.execute_input":"2024-03-19T13:07:59.397943Z","iopub.status.idle":"2024-03-19T13:10:36.257971Z","shell.execute_reply.started":"2024-03-19T13:07:59.397914Z","shell.execute_reply":"2024-03-19T13:10:36.257148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"numberOfNoDr = len(os.listdir(PATH + \"no_dr\"))\nnumberOfMild = len(os.listdir(PATH + \"mild\"))\nnumberOfModerate = len(os.listdir(PATH + \"moderate\"))\nnumberOfSevere = len(os.listdir(PATH + \"severe\"))\nnumberOfProliferative = len(os.listdir(PATH + \"proliferative_dr\"))\nnumberOfTotalData = numberOfNoDr + numberOfMild + numberOfModerate + numberOfSevere + numberOfProliferative\n\nprint(f\"Number of No DR (Level 0): {numberOfNoDr}\")\nprint(f\"Number of Mild (Level 1): {numberOfMild}\")\nprint(f\"Number of Moderate  (Level 2): {numberOfModerate}\")\nprint(f\"Number of Severe (Level 3): {numberOfSevere}\")\nprint(f\"Number of Proliferative DR (Level 4): {numberOfProliferative}\")\nprint(f\"Total data: {numberOfTotalData}\")","metadata":{"execution":{"iopub.status.busy":"2024-03-19T13:10:36.259152Z","iopub.execute_input":"2024-03-19T13:10:36.259451Z","iopub.status.idle":"2024-03-19T13:10:36.269993Z","shell.execute_reply.started":"2024-03-19T13:10:36.259426Z","shell.execute_reply":"2024-03-19T13:10:36.269179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"names = [\"no_dr\", \"mild\", \"moderate\", \"severe\", \"proliferative_dr\"]\n\ntf.random.set_seed(1)","metadata":{"execution":{"iopub.status.busy":"2024-03-19T13:10:36.271200Z","iopub.execute_input":"2024-03-19T13:10:36.271952Z","iopub.status.idle":"2024-03-19T13:10:36.278877Z","shell.execute_reply.started":"2024-03-19T13:10:36.271926Z","shell.execute_reply":"2024-03-19T13:10:36.278071Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"if not os.path.isdir(PATH + 'train/'):\n    for name in names:\n        os.makedirs(PATH + 'train/' + name)\n        os.makedirs(PATH + 'test/' + name)","metadata":{"execution":{"iopub.status.busy":"2024-03-19T13:10:36.280004Z","iopub.execute_input":"2024-03-19T13:10:36.280292Z","iopub.status.idle":"2024-03-19T13:10:36.288829Z","shell.execute_reply.started":"2024-03-19T13:10:36.280271Z","shell.execute_reply":"2024-03-19T13:10:36.288074Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"orig_folders = [\"no_dr/\", \"mild/\", \"moderate/\", \"severe/\", \"proliferative_dr/\"]\nfor folder_idx, folder in enumerate(orig_folders):\n    files = os.listdir(PATH + folder)\n    number_of_images = len([name for name in files])\n    n_train = int((number_of_images * 0.8) + 0.5)\n    n_test = number_of_images - n_train\n    print(number_of_images, n_train, n_test)\n    for idx, file in enumerate(files):\n        file_name = PATH + folder + file\n        if idx < n_train:\n            shutil.move(file_name, PATH + \"train/\" + names[folder_idx])\n        else:\n            shutil.move(file_name, PATH + \"test/\" + names[folder_idx])","metadata":{"execution":{"iopub.status.busy":"2024-03-19T13:10:36.289876Z","iopub.execute_input":"2024-03-19T13:10:36.290144Z","iopub.status.idle":"2024-03-19T13:10:36.463996Z","shell.execute_reply.started":"2024-03-19T13:10:36.290123Z","shell.execute_reply":"2024-03-19T13:10:36.463113Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# IMG_SIZE is determined by EfficientNet model choice\nIMG_SIZE = (528, 528)\nBATCH_SIZE = 16","metadata":{"execution":{"iopub.status.busy":"2024-03-19T13:10:36.465132Z","iopub.execute_input":"2024-03-19T13:10:36.465456Z","iopub.status.idle":"2024-03-19T13:10:36.469902Z","shell.execute_reply.started":"2024-03-19T13:10:36.465432Z","shell.execute_reply":"2024-03-19T13:10:36.468975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_dir = '/kaggle/working/dataset/train'\ntest_dir = '/kaggle/working/dataset/test'","metadata":{"execution":{"iopub.status.busy":"2024-03-19T13:10:36.470917Z","iopub.execute_input":"2024-03-19T13:10:36.471195Z","iopub.status.idle":"2024-03-19T13:10:36.477819Z","shell.execute_reply.started":"2024-03-19T13:10:36.471172Z","shell.execute_reply":"2024-03-19T13:10:36.477106Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_dataset = tf.keras.utils.image_dataset_from_directory(train_dir,\n                                                            shuffle=True,\n                                                            batch_size=BATCH_SIZE,\n                                                            image_size=IMG_SIZE)\n\ntest_dataset = tf.keras.utils.image_dataset_from_directory(test_dir,\n                                                           shuffle=True,\n                                                           batch_size=BATCH_SIZE,\n                                                           image_size=IMG_SIZE)","metadata":{"execution":{"iopub.status.busy":"2024-03-19T15:39:58.077774Z","iopub.execute_input":"2024-03-19T15:39:58.078150Z","iopub.status.idle":"2024-03-19T15:39:58.364424Z","shell.execute_reply.started":"2024-03-19T15:39:58.078124Z","shell.execute_reply":"2024-03-19T15:39:58.363637Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class_names = train_dataset.class_names\n\nplt.figure(figsize=(10, 10))\nfor images, labels in train_dataset.take(1):\n  for i in range(6):\n    ax = plt.subplot(3, 3, i + 1)\n    plt.imshow(images[i].numpy().astype(\"uint8\"))\n    plt.title(class_names[labels[i]])\n    plt.axis(\"off\")","metadata":{"execution":{"iopub.status.busy":"2024-03-19T15:39:59.164909Z","iopub.execute_input":"2024-03-19T15:39:59.165285Z","iopub.status.idle":"2024-03-19T15:40:06.244538Z","shell.execute_reply.started":"2024-03-19T15:39:59.165255Z","shell.execute_reply":"2024-03-19T15:40:06.243585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"NUM_CLASSES = 5\nimg_augmentation_layers = [\n    layers.RandomFlip(mode='horizontal'),\n    layers.RandomContrast(factor=0.1),\n    layers.RandomBrightness(factor=0.1),\n    layers.RandomRotation(factor=0.15),\n    layers.RandomTranslation(height_factor=0.1, width_factor=0.1, fill_mode='constant')\n]\n\n\ndef img_augmentation(images):\n    for layer in img_augmentation_layers:\n        images = layer(images)\n    return images\n\n# One-hot / categorical encoding\ndef input_preprocess_train(image, label):\n    #image = img_augmentation(image)\n    label = tf.one_hot(label, NUM_CLASSES)\n    return image, label\n\n\ndef input_preprocess_test(image, label):\n    label = tf.one_hot(label, NUM_CLASSES)\n    return image, label\n\n\ntrain_dataset = train_dataset.map(input_preprocess_train, num_parallel_calls=tf.data.AUTOTUNE)\n\ntest_dataset = test_dataset.map(input_preprocess_test, num_parallel_calls=tf.data.AUTOTUNE)","metadata":{"execution":{"iopub.status.busy":"2024-03-19T15:40:21.133721Z","iopub.execute_input":"2024-03-19T15:40:21.134764Z","iopub.status.idle":"2024-03-19T15:40:21.239918Z","shell.execute_reply.started":"2024-03-19T15:40:21.134729Z","shell.execute_reply":"2024-03-19T15:40:21.238936Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"AUTOTUNE = tf.data.AUTOTUNE\n\ntrain_dataset = train_dataset.prefetch(buffer_size=AUTOTUNE)\ntest_dataset = test_dataset.prefetch(buffer_size=AUTOTUNE)","metadata":{"execution":{"iopub.status.busy":"2024-03-19T15:40:32.148567Z","iopub.execute_input":"2024-03-19T15:40:32.148955Z","iopub.status.idle":"2024-03-19T15:40:32.156684Z","shell.execute_reply.started":"2024-03-19T15:40:32.148924Z","shell.execute_reply":"2024-03-19T15:40:32.155679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"IMG_SHAPE = IMG_SIZE + (3,)\nprint(IMG_SHAPE)","metadata":{"execution":{"iopub.status.busy":"2024-03-19T15:40:33.160489Z","iopub.execute_input":"2024-03-19T15:40:33.161357Z","iopub.status.idle":"2024-03-19T15:40:33.166011Z","shell.execute_reply.started":"2024-03-19T15:40:33.161323Z","shell.execute_reply":"2024-03-19T15:40:33.165001Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def build_model(num_classes):\n    inputs = layers.Input(shape=IMG_SHAPE)\n    model = EfficientNetB6(include_top=False, input_tensor=inputs, weights=\"imagenet\")\n\n    # Freeze the pretrained weights\n    model.trainable = False\n\n    # Rebuild top\n    x = layers.GlobalAveragePooling2D(name=\"avg_pool\")(model.output)\n    x = layers.Dropout(rate=0.4)(x)\n    \n    x = layers.Dense(256, activation='relu')(x)\n    x = layers.Dense(256, activation='relu')(x)\n    x = layers.Dropout(rate=0.4)(x)\n    \n    x = layers.Dense(128, activation='relu')(x)\n    x = layers.Dense(128, activation='relu')(x)\n    x = layers.Dropout(rate=0.4)(x)\n    \n    x = layers.Dense(64, activation='relu')(x)\n    x = layers.Dense(64, activation='relu')(x)\n    x = layers.Dropout(rate=0.4)(x)\n\n    #x = layers.BatchNormalization()(x)\n\n    #x = layers.Dense(64, activation='relu')(x)\n    #x = layers.Dropout(rate=0.396098832448106)(x)\n\n    #x = layers.Dense(128, activation='swish')(x)\n    #x = layers.Dropout(rate=0.527870247076625, name=\"top_dropout\")(x)\n\n    #top_dropout_rate = 0.2\n    #x = layers.Dropout(top_dropout_rate, name=\"top_dropout\") (x)\n    outputs = layers.Dense(num_classes, activation=\"softmax\", name=\"pred\")(x)\n\n    # Compile\n    model = keras.Model(inputs, outputs, name=\"EfficientNet\")\n    optimizer = keras.optimizers.Adam(learning_rate=1e-5)\n    model.compile(\n        optimizer=optimizer, loss=\"categorical_crossentropy\", metrics=[\"accuracy\"]\n    )\n    return model","metadata":{"execution":{"iopub.status.busy":"2024-03-19T15:41:01.499801Z","iopub.execute_input":"2024-03-19T15:41:01.500276Z","iopub.status.idle":"2024-03-19T15:41:01.510696Z","shell.execute_reply.started":"2024-03-19T15:41:01.500244Z","shell.execute_reply":"2024-03-19T15:41:01.509685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = build_model(num_classes=5)","metadata":{"execution":{"iopub.status.busy":"2024-03-19T15:41:02.479466Z","iopub.execute_input":"2024-03-19T15:41:02.479900Z","iopub.status.idle":"2024-03-19T15:41:06.387853Z","shell.execute_reply.started":"2024-03-19T15:41:02.479866Z","shell.execute_reply":"2024-03-19T15:41:06.386487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"epochs = 150  # @param {type: \"slider\", min:10, max:200}\nhist = model.fit(train_dataset, epochs=epochs, validation_data = test_dataset)","metadata":{"execution":{"iopub.status.busy":"2024-03-19T15:41:27.947725Z","iopub.execute_input":"2024-03-19T15:41:27.948407Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.evaluate(test_dataset)","metadata":{"execution":{"iopub.status.busy":"2024-03-19T11:32:08.839557Z","iopub.execute_input":"2024-03-19T11:32:08.839955Z","iopub.status.idle":"2024-03-19T11:32:39.739171Z","shell.execute_reply.started":"2024-03-19T11:32:08.839925Z","shell.execute_reply":"2024-03-19T11:32:39.738129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = []  # store predicted labels\ny_true = []  # store true labels\n\n# iterate over the dataset\nfor image_batch, label_batch in test_dataset:   # use dataset.unbatch() with repeat\n   # append true labels\n   y_true.append(label_batch)\n   # compute predictions\n   preds = model.predict(image_batch)\n   # append predicted labels\n   y_pred.append(np.argmax(preds, axis = - 1))\n\n# convert the true and predicted labels into tensors\ncorrect_labels = tf.concat([item for item in y_true], axis = 0)\npredicted_labels = tf.concat([item for item in y_pred], axis = 0)","metadata":{"execution":{"iopub.status.busy":"2024-03-19T15:30:25.445602Z","iopub.execute_input":"2024-03-19T15:30:25.446545Z","iopub.status.idle":"2024-03-19T15:31:28.870990Z","shell.execute_reply.started":"2024-03-19T15:30:25.446512Z","shell.execute_reply":"2024-03-19T15:31:28.869941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"correct_labels = correct_labels.numpy()\ncorrect_labels","metadata":{"execution":{"iopub.status.busy":"2024-03-19T15:36:33.938995Z","iopub.execute_input":"2024-03-19T15:36:33.939409Z","iopub.status.idle":"2024-03-19T15:36:33.947315Z","shell.execute_reply.started":"2024-03-19T15:36:33.939379Z","shell.execute_reply":"2024-03-19T15:36:33.946504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"correct_new = []\nfor i in range(len(correct_labels)):\n  correct_new.append(correct_labels[i].argmax())","metadata":{"execution":{"iopub.status.busy":"2024-03-19T15:36:43.447537Z","iopub.execute_input":"2024-03-19T15:36:43.447907Z","iopub.status.idle":"2024-03-19T15:36:43.454598Z","shell.execute_reply.started":"2024-03-19T15:36:43.447878Z","shell.execute_reply":"2024-03-19T15:36:43.453658Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.array(correct_new)","metadata":{"execution":{"iopub.status.busy":"2024-03-19T15:36:45.725723Z","iopub.execute_input":"2024-03-19T15:36:45.726664Z","iopub.status.idle":"2024-03-19T15:36:45.735177Z","shell.execute_reply.started":"2024-03-19T15:36:45.726631Z","shell.execute_reply":"2024-03-19T15:36:45.734215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.histogram(np.array(correct_new))","metadata":{"execution":{"iopub.status.busy":"2024-03-19T15:36:48.796856Z","iopub.execute_input":"2024-03-19T15:36:48.797615Z","iopub.status.idle":"2024-03-19T15:36:48.804910Z","shell.execute_reply.started":"2024-03-19T15:36:48.797581Z","shell.execute_reply":"2024-03-19T15:36:48.803942Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted_labels = predicted_labels.numpy()\npredicted_labels","metadata":{"execution":{"iopub.status.busy":"2024-03-19T15:36:52.362886Z","iopub.execute_input":"2024-03-19T15:36:52.363298Z","iopub.status.idle":"2024-03-19T15:36:52.372544Z","shell.execute_reply.started":"2024-03-19T15:36:52.363268Z","shell.execute_reply":"2024-03-19T15:36:52.371433Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import classification_report\ntarget_names = ['no_dr', 'mild', 'moderate', 'severe', 'proliferative_dr']\nprint(classification_report(correct_new, predicted_labels, target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2024-03-19T15:36:54.763192Z","iopub.execute_input":"2024-03-19T15:36:54.763528Z","iopub.status.idle":"2024-03-19T15:36:55.413016Z","shell.execute_reply.started":"2024-03-19T15:36:54.763503Z","shell.execute_reply":"2024-03-19T15:36:55.411913Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn import metrics\n\nactual = correct_new\npredicted = predicted_labels\n\nconfusion_matrix = metrics.confusion_matrix(actual, predicted)\n\ncm_display = metrics.ConfusionMatrixDisplay(confusion_matrix = confusion_matrix, display_labels = target_names)\n\ncm_display.plot()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-19T15:37:05.377348Z","iopub.execute_input":"2024-03-19T15:37:05.378659Z","iopub.status.idle":"2024-03-19T15:37:05.710714Z","shell.execute_reply.started":"2024-03-19T15:37:05.378625Z","shell.execute_reply":"2024-03-19T15:37:05.709809Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}