{"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        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-07T06:19:31.087514Z","iopub.execute_input":"2022-12-07T06:19:31.087950Z","iopub.status.idle":"2022-12-07T06:19:42.388911Z","shell.execute_reply.started":"2022-12-07T06:19:31.087913Z","shell.execute_reply":"2022-12-07T06:19:42.387897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nfrom tqdm import tqdm, trange\n\n\nfrom skimage import io\nfrom skimage.transform import rescale, resize, downscale_local_mean\n\nimport matplotlib.pyplot as plt\nfrom matplotlib.pyplot import figure","metadata":{"execution":{"iopub.status.busy":"2022-12-07T06:19:42.391698Z","iopub.execute_input":"2022-12-07T06:19:42.392455Z","iopub.status.idle":"2022-12-07T06:19:43.171395Z","shell.execute_reply.started":"2022-12-07T06:19:42.392415Z","shell.execute_reply":"2022-12-07T06:19:43.170386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\n\ntf.config.threading.set_inter_op_parallelism_threads(0)\n\nfrom tensorflow import keras\nfrom tensorflow.keras import layers","metadata":{"execution":{"iopub.status.busy":"2022-12-07T06:19:43.172967Z","iopub.execute_input":"2022-12-07T06:19:43.173381Z","iopub.status.idle":"2022-12-07T06:19:48.302968Z","shell.execute_reply.started":"2022-12-07T06:19:43.173344Z","shell.execute_reply":"2022-12-07T06:19:48.301831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_image_dir = \"/kaggle/input/datathonindoml-2022/train/train\"\nvalid_image_dir = \"/kaggle/input/datathonindoml-2022/validation/validation\"","metadata":{"execution":{"iopub.status.busy":"2022-12-07T06:19:48.304982Z","iopub.execute_input":"2022-12-07T06:19:48.305502Z","iopub.status.idle":"2022-12-07T06:19:48.312959Z","shell.execute_reply.started":"2022-12-07T06:19:48.305474Z","shell.execute_reply":"2022-12-07T06:19:48.312024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_image_file_paths = [ os.path.join(train_image_dir, x) for x in os.listdir(train_image_dir)]\nvalid_image_file_paths = [ os.path.join(valid_image_dir, x) for x in os.listdir(valid_image_dir)]","metadata":{"execution":{"iopub.status.busy":"2022-12-07T06:19:48.314444Z","iopub.execute_input":"2022-12-07T06:19:48.315084Z","iopub.status.idle":"2022-12-07T06:19:48.356038Z","shell.execute_reply.started":"2022-12-07T06:19:48.315042Z","shell.execute_reply":"2022-12-07T06:19:48.355212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xlabels = pd.read_csv('/kaggle/input/datathonindoml-2022/train_labels.csv')\nxlabels.head(5)","metadata":{"execution":{"iopub.status.busy":"2022-12-07T06:19:48.357109Z","iopub.execute_input":"2022-12-07T06:19:48.357464Z","iopub.status.idle":"2022-12-07T06:19:48.388428Z","shell.execute_reply.started":"2022-12-07T06:19:48.357429Z","shell.execute_reply":"2022-12-07T06:19:48.387406Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def find_file_id(path):\n    file_id = int((path.split(\"/\")[-1]).split(\".\")[0])\n    return file_id\n\ndef find_image_label(path):\n    file_id = find_file_id(path)\n    return (xlabels[xlabels.id==file_id]).values[0][1]\n\n\nprint(\"Path:\", train_image_file_paths[0])\nprint(\"File ID:\", find_file_id(train_image_file_paths[0]))\nprint(\"Label:\", find_image_label(train_image_file_paths[0]))","metadata":{"execution":{"iopub.status.busy":"2022-12-07T06:19:51.908671Z","iopub.execute_input":"2022-12-07T06:19:51.909261Z","iopub.status.idle":"2022-12-07T06:19:51.924449Z","shell.execute_reply.started":"2022-12-07T06:19:51.909217Z","shell.execute_reply":"2022-12-07T06:19:51.923395Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_labels = [find_image_label(x) for x in train_image_file_paths]\ny_labels[:10]","metadata":{"execution":{"iopub.status.busy":"2022-12-07T06:19:56.532018Z","iopub.execute_input":"2022-12-07T06:19:56.532515Z","iopub.status.idle":"2022-12-07T06:20:01.733266Z","shell.execute_reply.started":"2022-12-07T06:19:56.532474Z","shell.execute_reply":"2022-12-07T06:20:01.732141Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig,ax = plt.subplots(figsize=(6.4,4.8),dpi=100)\nax =  xlabels['label'].value_counts().plot(kind=\"bar\")\nplt.title(\"Distribution of different classes\")","metadata":{"execution":{"iopub.status.busy":"2022-12-07T06:20:01.735119Z","iopub.execute_input":"2022-12-07T06:20:01.735801Z","iopub.status.idle":"2022-12-07T06:20:02.111500Z","shell.execute_reply.started":"2022-12-07T06:20:01.735751Z","shell.execute_reply":"2022-12-07T06:20:02.110353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"figure(figsize=(5, 5), dpi=100)\nidx = 10\nsample = train_image_file_paths[idx]\nsample_img = io.imread(sample)\nprint(sample, sample_img.shape, y_labels[idx])\nfig = plt.imshow(sample_img, cmap='gray')\nfig.axes.get_xaxis().set_visible(False)\nfig.axes.get_yaxis().set_visible(False)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-07T06:20:05.613899Z","iopub.execute_input":"2022-12-07T06:20:05.614291Z","iopub.status.idle":"2022-12-07T06:20:05.825104Z","shell.execute_reply.started":"2022-12-07T06:20:05.614256Z","shell.execute_reply":"2022-12-07T06:20:05.824204Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train_image_file_paths), xlabels.shape[0]","metadata":{"execution":{"iopub.status.busy":"2022-12-07T06:20:08.975851Z","iopub.execute_input":"2022-12-07T06:20:08.976231Z","iopub.status.idle":"2022-12-07T06:20:08.983430Z","shell.execute_reply.started":"2022-12-07T06:20:08.976191Z","shell.execute_reply":"2022-12-07T06:20:08.982246Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def prep_train_feature_data(paths, dim=(100,100)):\n    total=len(paths)\n    x = np.zeros((total, dim[0], dim[1], 1), dtype='float')\n    for i,path in (enumerate((paths))):\n        img = io.imread(path)/255.0\n        img =  resize(img, (dim[0], dim[1]))\n        img = img.reshape((dim[0], dim[1]))\n        x[i,:,:,0] = img\n    return x","metadata":{"execution":{"iopub.status.busy":"2022-12-07T06:20:11.198392Z","iopub.execute_input":"2022-12-07T06:20:11.198751Z","iopub.status.idle":"2022-12-07T06:20:11.206536Z","shell.execute_reply.started":"2022-12-07T06:20:11.198721Z","shell.execute_reply":"2022-12-07T06:20:11.205456Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow import keras\n\nclass DataGenerator(keras.utils.Sequence):\n    def __init__(self, paths, batch_size=32, dim=(300, 300)):\n        'Initialization'\n        self.dim = dim\n        self.batch_size = batch_size\n        self.paths = paths\n\n    def __len__(self):\n        'Denotes the number of batches per epoch'\n        return len(self.paths)//self.batch_size\n\n    def __getitem__(self, idx):\n        'Generate one batch of data'\n        # Generate indexes of the batch\n        index_start = idx*self.batch_size\n        index_end = (idx+1)*self.batch_size\n\n        sub_paths = self.paths[index_start:index_end]\n        \n        X = prep_train_feature_data(sub_paths, self.dim)\n        y = [find_image_label(path) for path in sub_paths]\n\n        return X, np.array(y)","metadata":{"execution":{"iopub.status.busy":"2022-12-07T06:20:13.309723Z","iopub.execute_input":"2022-12-07T06:20:13.310090Z","iopub.status.idle":"2022-12-07T06:20:13.317705Z","shell.execute_reply.started":"2022-12-07T06:20:13.310059Z","shell.execute_reply":"2022-12-07T06:20:13.316648Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"n_classes=len(set(y_labels))\nimage_size = (300, 225)","metadata":{"execution":{"iopub.status.busy":"2022-12-07T06:20:16.800560Z","iopub.execute_input":"2022-12-07T06:20:16.800932Z","iopub.status.idle":"2022-12-07T06:20:16.807128Z","shell.execute_reply.started":"2022-12-07T06:20:16.800900Z","shell.execute_reply":"2022-12-07T06:20:16.805812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\ntrain_paths,valid_paths,train_labels,valid_labels = train_test_split(train_image_file_paths , y_labels , stratify = y_labels , test_size = 0.1)","metadata":{"execution":{"iopub.status.busy":"2022-12-07T06:20:19.529098Z","iopub.execute_input":"2022-12-07T06:20:19.529752Z","iopub.status.idle":"2022-12-07T06:20:19.646664Z","shell.execute_reply.started":"2022-12-07T06:20:19.529715Z","shell.execute_reply":"2022-12-07T06:20:19.645547Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_paths,test_paths,train_labels,test_labels = train_test_split(train_paths , train_labels , stratify = train_labels , test_size = 0.15)","metadata":{"execution":{"iopub.status.busy":"2022-12-07T06:20:25.356374Z","iopub.execute_input":"2022-12-07T06:20:25.356754Z","iopub.status.idle":"2022-12-07T06:20:25.378308Z","shell.execute_reply.started":"2022-12-07T06:20:25.356719Z","shell.execute_reply":"2022-12-07T06:20:25.377175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"validation_data = prep_train_feature_data(valid_paths, image_size)\nvalidation_preds = np.array(valid_labels)\nvalidation = (validation_data, validation_preds)","metadata":{"execution":{"iopub.status.busy":"2022-12-07T06:20:27.951517Z","iopub.execute_input":"2022-12-07T06:20:27.951887Z","iopub.status.idle":"2022-12-07T06:21:10.679545Z","shell.execute_reply.started":"2022-12-07T06:20:27.951853Z","shell.execute_reply":"2022-12-07T06:21:10.678420Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data=prep_train_feature_data(test_paths,image_size)","metadata":{"execution":{"iopub.status.busy":"2022-12-07T06:21:10.681851Z","iopub.execute_input":"2022-12-07T06:21:10.682251Z","iopub.status.idle":"2022-12-07T06:22:01.694554Z","shell.execute_reply.started":"2022-12-07T06:21:10.682210Z","shell.execute_reply":"2022-12-07T06:22:01.693411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"input_shape = image_size\ninput_shape = input_shape + (1,)\ninputs = keras.Input(input_shape)\n\n# image_augment_input = layers.RandomFlip()(inputs) \n# image_augment_input = layers.RandomRotation(factor=1.0)(image_augment_input)","metadata":{"execution":{"iopub.status.busy":"2022-12-07T06:22:01.695849Z","iopub.execute_input":"2022-12-07T06:22:01.696217Z","iopub.status.idle":"2022-12-07T06:22:01.728825Z","shell.execute_reply.started":"2022-12-07T06:22:01.696162Z","shell.execute_reply":"2022-12-07T06:22:01.727763Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.layers import Conv2D, MaxPooling2D, Dropout, Flatten, Dense, BatchNormalization\nimport tensorflow.keras.callbacks\nfrom tensorflow.keras.optimizers import Adam,SGD,RMSprop\nfrom sklearn.metrics import accuracy_score\n\ninputs = keras.Input(shape=input_shape)\n\nx = layers.Conv2D(32, (3, 3), activation='relu')(inputs)\nx = layers.BatchNormalization()(x)\nx = layers.MaxPooling2D(pool_size=(2, 2),strides = 2)(x)\nx = layers.Dropout(0.25)(x)\n\nx = layers.Conv2D(64, (3, 3), activation='relu')(x)\nx = layers.BatchNormalization()(x)\nx = layers.MaxPooling2D(pool_size=(2, 2),strides = 2)(x)\nx = layers.Dropout(0.25)(x)\n\nx = layers.Conv2D(128, (3, 3), activation='relu')(x)\nx = layers.BatchNormalization()(x)\nx = layers.MaxPooling2D(pool_size=(2, 2),strides = 2)(x)\nx = layers.Dropout(0.25)(x)\n\nx = layers.Conv2D(256, (3, 3), activation='relu')(x)\nx = layers.BatchNormalization()(x)\nx = layers.MaxPooling2D(pool_size=(2, 2),strides = 2)(x)\nx = layers.Dropout(0.25)(x)\n\nx = layers.Flatten()(x)\n\nx = layers.Dense(256, activation='relu')(x)\nx = layers.BatchNormalization()(x)\nx = layers.Dropout(0.25)(x)\n\nx = layers.Dense(512, activation='relu')(x)\nx = layers.BatchNormalization()(x)\nx = layers.Dropout(0.25)(x)\n\nx = layers.Dense(1024, activation='relu')(x)\nx = layers.BatchNormalization()(x)\nx = layers.Dropout(0.25)(x)\n\noutputs = layers.Dense(16, activation=\"softmax\")(x) \nmodel = keras.Model(inputs=inputs, outputs=outputs)\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2022-12-07T08:18:09.960136Z","iopub.execute_input":"2022-12-07T08:18:09.960527Z","iopub.status.idle":"2022-12-07T08:18:10.208775Z","shell.execute_reply.started":"2022-12-07T08:18:09.960495Z","shell.execute_reply":"2022-12-07T08:18:10.207684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"opt = Adam(learning_rate = 0.001)\nmodel.compile(\n    optimizer=opt,\n    loss=\"sparse_categorical_crossentropy\",\n    metrics=[\"accuracy\"],\n)","metadata":{"execution":{"iopub.status.busy":"2022-12-07T08:18:13.908936Z","iopub.execute_input":"2022-12-07T08:18:13.909320Z","iopub.status.idle":"2022-12-07T08:18:13.921039Z","shell.execute_reply.started":"2022-12-07T08:18:13.909286Z","shell.execute_reply":"2022-12-07T08:18:13.919932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.callbacks import ModelCheckpoint, EarlyStopping, ReduceLROnPlateau\n\ncheckpoint = ModelCheckpoint(\"./model.h5\", monitor='val_acc', verbose=0, save_best_only=True, mode='max')\n\nearly_stopping = EarlyStopping(monitor='val_loss',\n                          min_delta=0,\n                          patience=3,\n                          verbose=1,\n                          restore_best_weights=True #restoring the best model\n                          )\n\nreduce_learningrate = ReduceLROnPlateau(monitor='val_loss',\n                              factor=0.2,\n                              patience=2,\n                              verbose=1,\n                              min_delta=0.001)\n\ncallbacks = [early_stopping,checkpoint,reduce_learningrate]\n\nepochs = 15","metadata":{"execution":{"iopub.status.busy":"2022-12-07T08:18:18.796257Z","iopub.execute_input":"2022-12-07T08:18:18.796978Z","iopub.status.idle":"2022-12-07T08:18:18.805603Z","shell.execute_reply.started":"2022-12-07T08:18:18.796942Z","shell.execute_reply":"2022-12-07T08:18:18.802398Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_generator = DataGenerator(train_paths, batch_size=64, dim=image_size)","metadata":{"execution":{"iopub.status.busy":"2022-12-07T08:18:21.360242Z","iopub.execute_input":"2022-12-07T08:18:21.361288Z","iopub.status.idle":"2022-12-07T08:18:21.366491Z","shell.execute_reply.started":"2022-12-07T08:18:21.361245Z","shell.execute_reply":"2022-12-07T08:18:21.365217Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit(\n    train_generator, \n    epochs=epochs,\n    validation_data=validation,\n    callbacks=callbacks\n)","metadata":{"execution":{"iopub.status.busy":"2022-12-07T08:18:23.194634Z","iopub.execute_input":"2022-12-07T08:18:23.194999Z","iopub.status.idle":"2022-12-07T09:00:16.234409Z","shell.execute_reply.started":"2022-12-07T08:18:23.194967Z","shell.execute_reply":"2022-12-07T09:00:16.233341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.save(\"cnn.h5\")","metadata":{"execution":{"iopub.status.busy":"2022-12-07T09:32:14.090462Z","iopub.execute_input":"2022-12-07T09:32:14.091441Z","iopub.status.idle":"2022-12-07T09:32:14.317339Z","shell.execute_reply.started":"2022-12-07T09:32:14.091405Z","shell.execute_reply":"2022-12-07T09:32:14.316081Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.models import load_model\nmodel = load_model(\"cnn.h5\")","metadata":{"execution":{"iopub.status.busy":"2022-12-07T09:00:41.676466Z","iopub.execute_input":"2022-12-07T09:00:41.676824Z","iopub.status.idle":"2022-12-07T09:00:41.997983Z","shell.execute_reply.started":"2022-12-07T09:00:41.676793Z","shell.execute_reply":"2022-12-07T09:00:41.996992Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(history.history['accuracy'])\nplt.plot(history.history['val_accuracy'])\nplt.title('Model Accuracy')\nplt.ylabel('Accuracy')\nplt.xlabel('Epoch')\nplt.legend(['train', 'val'], loc='upper left')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-07T09:00:46.111692Z","iopub.execute_input":"2022-12-07T09:00:46.112065Z","iopub.status.idle":"2022-12-07T09:00:46.300232Z","shell.execute_reply.started":"2022-12-07T09:00:46.112035Z","shell.execute_reply":"2022-12-07T09:00:46.299119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(history.history['loss'])\nplt.plot(history.history['val_loss'])\nplt.title('Model Loss')\nplt.ylabel('Loss')\nplt.xlabel('Epoch')\nplt.legend(['train', 'val'], loc='upper left')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-07T09:00:50.534568Z","iopub.execute_input":"2022-12-07T09:00:50.534963Z","iopub.status.idle":"2022-12-07T09:00:50.741135Z","shell.execute_reply.started":"2022-12-07T09:00:50.534928Z","shell.execute_reply":"2022-12-07T09:00:50.740217Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score, classification_report\n\ny_test_res = model.predict(test_data)\ntest_prediction = []\nfor i in range(test_data.shape[0]):\n    idx = np.argmax(y_test_res[i])\n    test_prediction.append(idx)","metadata":{"execution":{"iopub.status.busy":"2022-12-07T09:00:54.957773Z","iopub.execute_input":"2022-12-07T09:00:54.958682Z","iopub.status.idle":"2022-12-07T09:01:00.056828Z","shell.execute_reply.started":"2022-12-07T09:00:54.958634Z","shell.execute_reply":"2022-12-07T09:01:00.055824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_actual = np.array(test_labels)\naccuracy = accuracy_score(test_actual,test_prediction)\nprint(accuracy)","metadata":{"execution":{"iopub.status.busy":"2022-12-07T09:01:02.534250Z","iopub.execute_input":"2022-12-07T09:01:02.534655Z","iopub.status.idle":"2022-12-07T09:01:02.544024Z","shell.execute_reply.started":"2022-12-07T09:01:02.534622Z","shell.execute_reply":"2022-12-07T09:01:02.542635Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(classification_report(test_actual,test_prediction))","metadata":{"execution":{"iopub.status.busy":"2022-12-07T09:01:14.536603Z","iopub.execute_input":"2022-12-07T09:01:14.537792Z","iopub.status.idle":"2022-12-07T09:01:14.553868Z","shell.execute_reply.started":"2022-12-07T09:01:14.537747Z","shell.execute_reply":"2022-12-07T09:01:14.552756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classes = list(range(16))\nres = tf.math.confusion_matrix(test_prediction,test_actual).numpy()\ncm = pd.DataFrame(res,\n                     index = classes, \n                     columns = classes)","metadata":{"execution":{"iopub.status.busy":"2022-12-07T09:01:19.641984Z","iopub.execute_input":"2022-12-07T09:01:19.642752Z","iopub.status.idle":"2022-12-07T09:01:19.655617Z","shell.execute_reply.started":"2022-12-07T09:01:19.642707Z","shell.execute_reply":"2022-12-07T09:01:19.654425Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nfigure = plt.figure(figsize=(15, 10), dpi=150)\nsns.heatmap(cm, annot=True, cmap=plt.cm.Blues)\nplt.ylabel('True label')\nplt.xlabel('Predicted label')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-07T09:02:24.032284Z","iopub.execute_input":"2022-12-07T09:02:24.032678Z","iopub.status.idle":"2022-12-07T09:02:25.118176Z","shell.execute_reply.started":"2022-12-07T09:02:24.032646Z","shell.execute_reply":"2022-12-07T09:02:25.117224Z"},"trusted":true},"execution_count":null,"outputs":[]}]}