{"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","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"},{"sourceId":187731,"sourceType":"datasetVersion","datasetId":80814},{"sourceId":2822109,"sourceType":"datasetVersion","datasetId":1725813}],"dockerImageVersionId":28772,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import json\nimport math\nimport os\n\nimport cv2\nimport shutil\nfrom PIL import Image\nimport numpy as np\nfrom keras import layers\nfrom keras.applications import DenseNet121\nfrom keras.callbacks import Callback, ModelCheckpoint\nfrom keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img\nfrom keras.models import Sequential\nfrom keras.optimizers import Adam\nimport matplotlib.pyplot as plt\nimport pandas as pd\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import cohen_kappa_score, accuracy_score\nimport scipy\nimport tensorflow as tf\nfrom tqdm import tqdm\n\n%matplotlib inline","metadata":{"_uuid":"5ec43a19-3ede-43ad-a41e-179fb336ae80","_cell_guid":"43173830-0098-4c67-9850-bf1bae4f63ee","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2024-05-06T21:56:01.326791Z","iopub.execute_input":"2024-05-06T21:56:01.327139Z","iopub.status.idle":"2024-05-06T21:56:01.340072Z","shell.execute_reply.started":"2024-05-06T21:56:01.327084Z","shell.execute_reply":"2024-05-06T21:56:01.339150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.random.seed(2019)\ntf.set_random_seed(2019)","metadata":{"execution":{"iopub.status.busy":"2024-05-06T21:56:04.368818Z","iopub.execute_input":"2024-05-06T21:56:04.369166Z","iopub.status.idle":"2024-05-06T21:56:04.397021Z","shell.execute_reply.started":"2024-05-06T21:56:04.369087Z","shell.execute_reply":"2024-05-06T21:56:04.396370Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.makedirs('/kaggle/working/ddr-equal/train_images')","metadata":{"execution":{"iopub.status.busy":"2024-05-06T21:56:13.038246Z","iopub.execute_input":"2024-05-06T21:56:13.038714Z","iopub.status.idle":"2024-05-06T21:56:13.042982Z","shell.execute_reply.started":"2024-05-06T21:56:13.038511Z","shell.execute_reply":"2024-05-06T21:56:13.042055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"file_path = f'/kaggle/input/ddrdataset/DR_grading.csv'\ndata = pd.read_csv(file_path)\n\ndict = {}\nLABEL_SIZE = 236\n\nfor i in data.index:\n    dict[data['id_code'][i]] = data['diagnosis'][i]\n\ncount = [0, 0, 0, 0, 0]\nrows = []\n\nfor i in data.index:\n    source_file_path = f'/kaggle/input/ddrdataset/DR_grading/DR_grading/'+data['id_code'][i]\n    destination_file_path = f'/kaggle/working/ddr-equal/train_images/'\n    if count[data['diagnosis'][i]]<LABEL_SIZE and os.path.exists(source_file_path):\n        rows.append([data['id_code'][i], data['diagnosis'][i]])\n        shutil.copy(source_file_path, destination_file_path)\n        count[data['diagnosis'][i]]+=1\n\ncolumns = ['id_code', 'diagnosis']\n\ndf = pd.DataFrame(rows, columns=columns)\n\nfile_path = f'/kaggle/working/ddr-equal/train.csv'\ndf.to_csv(file_path, index=False)","metadata":{"execution":{"iopub.status.busy":"2024-05-06T21:57:02.771858Z","iopub.execute_input":"2024-05-06T21:57:02.772301Z","iopub.status.idle":"2024-05-06T21:57:32.818330Z","shell.execute_reply.started":"2024-05-06T21:57:02.772217Z","shell.execute_reply":"2024-05-06T21:57:32.817555Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df1 = pd.read_csv(f'/kaggle/working/ddr-equal/train.csv')\ndf1.shape[0]","metadata":{"execution":{"iopub.status.busy":"2024-05-06T22:28:19.855593Z","iopub.execute_input":"2024-05-06T22:28:19.855906Z","iopub.status.idle":"2024-05-06T22:28:19.864839Z","shell.execute_reply.started":"2024-05-06T22:28:19.855861Z","shell.execute_reply":"2024-05-06T22:28:19.864064Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"datagen = ImageDataGenerator(\n        zoom_range=0.15, \n        fill_mode='constant',\n        cval=0.,  \n        horizontal_flip=True,  \n        vertical_flip=True,)","metadata":{"execution":{"iopub.status.busy":"2024-05-06T22:04:36.116735Z","iopub.execute_input":"2024-05-06T22:04:36.117044Z","iopub.status.idle":"2024-05-06T22:04:36.122012Z","shell.execute_reply.started":"2024-05-06T22:04:36.117001Z","shell.execute_reply":"2024-05-06T22:04:36.121232Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.makedirs('/kaggle/working/ddr-equal/aug_images')","metadata":{"execution":{"iopub.status.busy":"2024-05-06T22:18:34.379945Z","iopub.execute_input":"2024-05-06T22:18:34.380344Z","iopub.status.idle":"2024-05-06T22:18:34.384403Z","shell.execute_reply.started":"2024-05-06T22:18:34.380278Z","shell.execute_reply":"2024-05-06T22:18:34.383586Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for j in range(df1.shape[0]):\n    id_code = df1['id_code'][j]\n    diagnosis = str(df1['diagnosis'][j])\n    img = load_img(f'/kaggle/working/ddr-equal/train_images/{id_code}') \n    x = img_to_array(img)\n    x = x.reshape((1, ) + x.shape) \n    \n    i = 0\n    for batch in datagen.flow(x, batch_size = 1, save_to_dir ='/kaggle/working/ddr-equal/aug_images', save_prefix = diagnosis + '_', save_format ='jpg'):\n        i += 1\n        if i > 5:\n            break","metadata":{"execution":{"iopub.status.busy":"2024-05-06T22:28:26.299961Z","iopub.execute_input":"2024-05-06T22:28:26.300261Z","iopub.status.idle":"2024-05-06T23:05:21.550673Z","shell.execute_reply.started":"2024-05-06T22:28:26.300217Z","shell.execute_reply":"2024-05-06T23:05:21.549700Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"augmented_rows = []\naug_dir = '/kaggle/working/ddr-equal/aug_images'\n\nfor augmented_img_name in os.listdir(aug_dir):\n    augmented_rows.append([augmented_img_name, int(augmented_img_name[0])])\n\ncolumns = ['id_code', 'diagnosis']\ndf_augmented = pd.DataFrame(augmented_rows, columns=columns)\noutput_csv_path = '/kaggle/working/ddr-equal/aug.csv'\ndf_augmented.to_csv(output_csv_path, index=False)","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:09:51.143956Z","iopub.execute_input":"2024-05-06T23:09:51.144328Z","iopub.status.idle":"2024-05-06T23:09:51.295707Z","shell.execute_reply.started":"2024-05-06T23:09:51.144266Z","shell.execute_reply":"2024-05-06T23:09:51.294859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv('/kaggle/working/ddr-equal/aug.csv')\nprint(train_df.shape)\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:12:09.040892Z","iopub.execute_input":"2024-05-06T23:12:09.041228Z","iopub.status.idle":"2024-05-06T23:12:09.058277Z","shell.execute_reply.started":"2024-05-06T23:12:09.041176Z","shell.execute_reply":"2024-05-06T23:12:09.057537Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['diagnosis'].hist()\ntrain_df['diagnosis'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:12:32.657046Z","iopub.execute_input":"2024-05-06T23:12:32.657384Z","iopub.status.idle":"2024-05-06T23:12:32.898964Z","shell.execute_reply.started":"2024-05-06T23:12:32.657335Z","shell.execute_reply":"2024-05-06T23:12:32.898236Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def display_samples(df, columns=4, rows=3):\n    fig=plt.figure(figsize=(5*columns, 4*rows))\n\n    for i in range(columns*rows):\n        image_path = df.loc[i,'id_code']\n        image_id = df.loc[i,'diagnosis']\n        img = cv2.imread(f'/kaggle/working/ddr-equal/aug_images/{image_path}')\n        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n        \n        fig.add_subplot(rows, columns, i+1)\n        plt.title(image_id)\n        plt.imshow(img)\n    \n    plt.tight_layout()\n\ndisplay_samples(train_df)","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:12:48.397472Z","iopub.execute_input":"2024-05-06T23:12:48.397955Z","iopub.status.idle":"2024-05-06T23:12:51.911413Z","shell.execute_reply.started":"2024-05-06T23:12:48.397863Z","shell.execute_reply":"2024-05-06T23:12:51.910340Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_pad_width(im, new_shape, is_rgb=True):\n    pad_diff = new_shape - im.shape[0], new_shape - im.shape[1]\n    t, b = math.floor(pad_diff[0]/2), math.ceil(pad_diff[0]/2)\n    l, r = math.floor(pad_diff[1]/2), math.ceil(pad_diff[1]/2)\n    if is_rgb:\n        pad_width = ((t,b), (l,r), (0, 0))\n    else:\n        pad_width = ((t,b), (l,r))\n    return pad_width\n\ndef preprocess_image(image_path, desired_size=224):\n    im = Image.open(image_path)\n    im = im.resize((desired_size, )*2, resample=Image.LANCZOS)\n    \n    return im","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:17:39.804374Z","iopub.execute_input":"2024-05-06T23:17:39.804747Z","iopub.status.idle":"2024-05-06T23:17:39.814079Z","shell.execute_reply.started":"2024-05-06T23:17:39.804683Z","shell.execute_reply":"2024-05-06T23:17:39.813240Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"N = train_df.shape[0]\nx_train = np.empty((N, 224, 224, 3), dtype=np.uint8)\n\nfor i, image_id in enumerate(tqdm(train_df['id_code'])):\n    x_train[i, :, :, :] = preprocess_image(\n        f'/kaggle/working/ddr-equal/aug_images/{image_id}'\n    )","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:17:44.252315Z","iopub.execute_input":"2024-05-06T23:17:44.252635Z","iopub.status.idle":"2024-05-06T23:21:16.156640Z","shell.execute_reply.started":"2024-05-06T23:17:44.252589Z","shell.execute_reply":"2024-05-06T23:21:16.155807Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train = pd.get_dummies(train_df['diagnosis']).values\n\nprint(x_train.shape)\nprint(y_train.shape)","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:22:00.351530Z","iopub.execute_input":"2024-05-06T23:22:00.351877Z","iopub.status.idle":"2024-05-06T23:22:00.361197Z","shell.execute_reply.started":"2024-05-06T23:22:00.351832Z","shell.execute_reply":"2024-05-06T23:22:00.360279Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train_multi = np.empty(y_train.shape, dtype=y_train.dtype)\ny_train_multi[:, 4] = y_train[:, 4]\n\nfor i in range(3, -1, -1):\n    y_train_multi[:, i] = np.logical_or(y_train[:, i], y_train_multi[:, i+1])\n\nprint(\"Original y_train:\", y_train.sum(axis=0))\nprint(\"Multilabel version:\", y_train_multi.sum(axis=0))","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:22:18.233944Z","iopub.execute_input":"2024-05-06T23:22:18.234311Z","iopub.status.idle":"2024-05-06T23:22:18.244540Z","shell.execute_reply.started":"2024-05-06T23:22:18.234249Z","shell.execute_reply":"2024-05-06T23:22:18.243503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train_multi = y_train_multi[:x_train.shape[0]]\n\nx_train_full, x_test, y_train_full, y_test = train_test_split(\n    x_train, y_train_multi, \n    test_size=0.2,\n    random_state=2019\n)\n\nx_train_partial, x_val, y_train_partial, y_val = train_test_split(\n    x_train_full, y_train_full, \n    test_size=0.1, \n    random_state=2019\n)","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:22:24.658788Z","iopub.execute_input":"2024-05-06T23:22:24.659138Z","iopub.status.idle":"2024-05-06T23:22:25.865365Z","shell.execute_reply.started":"2024-05-06T23:22:24.659067Z","shell.execute_reply":"2024-05-06T23:22:25.864533Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BATCH_SIZE = 32\n\ndef create_datagen():\n    return ImageDataGenerator(\n        zoom_range=0.15, \n        fill_mode='constant',\n        cval=0.,  \n        horizontal_flip=True,  \n        vertical_flip=True,  \n    )\n\ndata_generator = create_datagen().flow(x_train_partial, y_train_partial, batch_size=BATCH_SIZE, seed=2019)","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:22:29.814056Z","iopub.execute_input":"2024-05-06T23:22:29.814415Z","iopub.status.idle":"2024-05-06T23:22:31.624214Z","shell.execute_reply.started":"2024-05-06T23:22:29.814363Z","shell.execute_reply":"2024-05-06T23:22:31.623289Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class Metrics(Callback):\n    def on_train_begin(self, logs={}):\n        self.val_kappas = []\n\n    def on_epoch_end(self, epoch, logs={}):\n        X_val, y_val = self.validation_data[:2]\n        y_val = y_val.sum(axis=1) - 1\n        \n        y_pred = self.model.predict(X_val) > 0.5\n        y_pred = y_pred.astype(int).sum(axis=1) - 1\n\n        _val_kappa = cohen_kappa_score(\n            y_val,\n            y_pred, \n            weights='quadratic'\n        )\n\n        self.val_kappas.append(_val_kappa)\n\n        print(f\"val_kappa: {_val_kappa:.4f}\")\n        \n        if _val_kappa == max(self.val_kappas):\n            print(\"Validation Kappa has improved. Saving model.\")\n            self.model.save('model.h5')\n\n        return","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:22:34.823921Z","iopub.execute_input":"2024-05-06T23:22:34.824305Z","iopub.status.idle":"2024-05-06T23:22:34.835018Z","shell.execute_reply.started":"2024-05-06T23:22:34.824247Z","shell.execute_reply":"2024-05-06T23:22:34.833768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"densenet = DenseNet121(\n    weights='../input/densenet-keras/DenseNet-BC-121-32-no-top.h5',\n    include_top=False,\n    input_shape=(224,224,3)\n)","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:22:38.509588Z","iopub.execute_input":"2024-05-06T23:22:38.509958Z","iopub.status.idle":"2024-05-06T23:23:04.456930Z","shell.execute_reply.started":"2024-05-06T23:22:38.509892Z","shell.execute_reply":"2024-05-06T23:23:04.455853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def build_model():\n    model = Sequential()\n    model.add(densenet)\n    model.add(layers.GlobalAveragePooling2D())\n    model.add(layers.Dropout(0.5))\n    model.add(layers.Dense(5, activation='sigmoid'))\n    \n    model.compile(\n        loss='binary_crossentropy',\n        optimizer=Adam(lr=0.00005),\n        metrics=['accuracy']\n    )\n    \n    return model","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:23:41.566806Z","iopub.execute_input":"2024-05-06T23:23:41.567189Z","iopub.status.idle":"2024-05-06T23:23:41.584165Z","shell.execute_reply.started":"2024-05-06T23:23:41.567108Z","shell.execute_reply":"2024-05-06T23:23:41.583052Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = build_model()\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:23:43.965622Z","iopub.execute_input":"2024-05-06T23:23:43.966014Z","iopub.status.idle":"2024-05-06T23:23:55.388092Z","shell.execute_reply.started":"2024-05-06T23:23:43.965942Z","shell.execute_reply":"2024-05-06T23:23:55.386957Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"kappa_metrics = Metrics()\n\nhistory = model.fit_generator(\n    data_generator,\n    steps_per_epoch=x_train.shape[0] / BATCH_SIZE,\n    epochs=10,\n    validation_data=(x_val, y_val),\n    callbacks=[kappa_metrics]\n)","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:23:58.805529Z","iopub.execute_input":"2024-05-06T23:23:58.805887Z","iopub.status.idle":"2024-05-06T23:37:04.028702Z","shell.execute_reply.started":"2024-05-06T23:23:58.805826Z","shell.execute_reply":"2024-05-06T23:37:04.027748Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.save('densenet.keras')","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:39:27.781685Z","iopub.execute_input":"2024-05-06T23:39:27.782061Z","iopub.status.idle":"2024-05-06T23:39:28.955695Z","shell.execute_reply.started":"2024-05-06T23:39:27.782016Z","shell.execute_reply":"2024-05-06T23:39:28.954693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = model.predict(x_test) > 0.5\ny_pred = y_pred.astype(int).sum(axis=1) - 1\ny_pred[0]","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:39:32.716777Z","iopub.execute_input":"2024-05-06T23:39:32.717158Z","iopub.status.idle":"2024-05-06T23:39:36.149952Z","shell.execute_reply.started":"2024-05-06T23:39:32.717077Z","shell.execute_reply":"2024-05-06T23:39:36.148998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_true = y_test.sum(axis=1) - 1\ny_true[0]","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:39:48.728048Z","iopub.execute_input":"2024-05-06T23:39:48.728449Z","iopub.status.idle":"2024-05-06T23:39:48.735475Z","shell.execute_reply.started":"2024-05-06T23:39:48.728383Z","shell.execute_reply":"2024-05-06T23:39:48.734234Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(y_pred.shape)\nprint(y_true.shape)","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:39:51.737934Z","iopub.execute_input":"2024-05-06T23:39:51.738329Z","iopub.status.idle":"2024-05-06T23:39:51.743654Z","shell.execute_reply.started":"2024-05-06T23:39:51.738261Z","shell.execute_reply":"2024-05-06T23:39:51.742553Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"with open('history.json', 'w') as f:\n    json.dump(history.history, f)\n\nhistory_df = pd.DataFrame(history.history)\nhistory_df[['loss', 'val_loss']].plot()\nhistory_df[['acc', 'val_acc']].plot()","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:39:54.590318Z","iopub.execute_input":"2024-05-06T23:39:54.590653Z","iopub.status.idle":"2024-05-06T23:39:54.990327Z","shell.execute_reply.started":"2024-05-06T23:39:54.590605Z","shell.execute_reply":"2024-05-06T23:39:54.989442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import confusion_matrix, precision_score, recall_score, f1_score, roc_curve, auc\nfrom mlxtend.plotting import plot_confusion_matrix\n\ncm = confusion_matrix(y_true, y_pred) \nprint('Confusion matrix:')\n \nfig, ax = plot_confusion_matrix(conf_mat=cm, figsize=(6, 6), cmap=plt.cm.Greens)\nplt.xlabel('Predictions', fontsize=18)\nplt.ylabel('Actuals', fontsize=18)\nplt.title('Confusion Matrix', fontsize=18)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:39:59.438669Z","iopub.execute_input":"2024-05-06T23:39:59.439065Z","iopub.status.idle":"2024-05-06T23:39:59.746209Z","shell.execute_reply.started":"2024-05-06T23:39:59.438996Z","shell.execute_reply":"2024-05-06T23:39:59.745050Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy = accuracy_score(y_true, y_pred) \nprint('\\nAccuracy : ', accuracy)","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:40:03.840490Z","iopub.execute_input":"2024-05-06T23:40:03.840835Z","iopub.status.idle":"2024-05-06T23:40:03.847051Z","shell.execute_reply.started":"2024-05-06T23:40:03.840791Z","shell.execute_reply":"2024-05-06T23:40:03.845973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"macro_precision = precision_score(y_true, y_pred, average = 'macro') \nmicro_precision = precision_score(y_true, y_pred, average = 'micro') \nweighted_precision = precision_score(y_true, y_pred, average = 'weighted') \n\nprint('Macro Precision : ', macro_precision)\nprint('Micro Precision : ', micro_precision)\nprint('Weighted Precision : ', weighted_precision)","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:40:13.052516Z","iopub.execute_input":"2024-05-06T23:40:13.052947Z","iopub.status.idle":"2024-05-06T23:40:13.069857Z","shell.execute_reply.started":"2024-05-06T23:40:13.052883Z","shell.execute_reply":"2024-05-06T23:40:13.068919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"macro_recall = recall_score(y_true, y_pred, average = 'macro') \nmicro_recall = recall_score(y_true, y_pred, average = 'micro') \nweighted_recall = recall_score(y_true, y_pred, average = 'weighted') \n\nprint('Macro recall : ', macro_recall)\nprint('Micro recall : ', micro_recall)\nprint('Weighted recall : ', weighted_recall)","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:40:15.395871Z","iopub.execute_input":"2024-05-06T23:40:15.396185Z","iopub.status.idle":"2024-05-06T23:40:15.407408Z","shell.execute_reply.started":"2024-05-06T23:40:15.396132Z","shell.execute_reply":"2024-05-06T23:40:15.406654Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"macro_f1 = f1_score(y_true, y_pred, average = 'macro') \nmicro_f1 = f1_score(y_true, y_pred, average = 'micro') \nweighted_f1 = f1_score(y_true, y_pred, average = 'weighted') \n\nprint('Macro f1 : ', macro_f1)\nprint('Micro f1 : ', micro_f1)\nprint('Weighted f1 : ', weighted_f1)","metadata":{"execution":{"iopub.status.busy":"2024-05-06T23:40:17.299922Z","iopub.execute_input":"2024-05-06T23:40:17.300254Z","iopub.status.idle":"2024-05-06T23:40:17.312028Z","shell.execute_reply.started":"2024-05-06T23:40:17.300208Z","shell.execute_reply":"2024-05-06T23:40:17.311024Z"},"trusted":true},"execution_count":null,"outputs":[]}]}