{"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#Importing packages\nimport tensorflow as tf\nimport os\nimport cv2\nimport imageio\nimport numpy as np\nfrom tqdm import tqdm\nimport seaborn as sns\nimport matplotlib.patches as mpatches\nfrom scipy.signal import find_peaks\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd\nfrom tensorflow import keras\nfrom tensorflow.keras.layers import Dense,Input,Conv2D,MaxPool2D,Activation,Dropout,Flatten\nfrom tensorflow.keras.models import Model\nimport random as rn\nfrom tensorflow.keras.callbacks import EarlyStopping\nfrom tensorflow.keras.applications import VGG16\nimport datetime\nimport glob\nimport warnings\nfrom tensorflow.keras import models, layers\nfrom sklearn.metrics import cohen_kappa_score\nimport math\nfrom keras.regularizers import l1 ,l2\nimport keras\nfrom tensorflow.keras.layers import BatchNormalization, Activation, Flatten\nfrom tensorflow.keras.optimizers import Adam, SGD\nfrom sklearn.metrics import confusion_matrix, classification_report\nimport seaborn as sns\nfrom matplotlib import pyplot as plt\n\nimport argparse\nimport os\nimport warnings\n\nfrom keras.callbacks import Callback\nfrom keras import backend as K\nwarnings.filterwarnings('ignore')\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":"2021-09-03T18:13:21.607556Z","iopub.execute_input":"2021-09-03T18:13:21.607925Z","iopub.status.idle":"2021-09-03T18:13:27.130318Z","shell.execute_reply.started":"2021-09-03T18:13:21.607851Z","shell.execute_reply":"2021-09-03T18:13:27.129465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**1.1 Reading data**","metadata":{}},{"cell_type":"code","source":"# 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\n\nimg_path = list()\nimg_fullname = list()\nimg_name = list()\nfor dirname, _, filenames in os.walk('/kaggle/input/aptos2019-blindness-detection/train_images/'):\n    for filename in filenames:\n        img_path.append(os.path.join(dirname, filename))\n        temp = os.path.join(dirname, filename)\n        temp = temp.split(\"/\")[-1]\n        img_fullname.append(temp)\n        temp = temp.split(\".\")[0]\n        img_name.append(str(temp))\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":{"execution":{"iopub.status.busy":"2021-09-03T18:15:24.829645Z","iopub.execute_input":"2021-09-03T18:15:24.830001Z","iopub.status.idle":"2021-09-03T18:15:26.558201Z","shell.execute_reply.started":"2021-09-03T18:15:24.829969Z","shell.execute_reply":"2021-09-03T18:15:26.557372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pre_df = pd.DataFrame()\npre_df['path'] = img_path\npre_df['fullname'] = img_fullname\npre_df['id_code'] = img_name","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:15:33.706289Z","iopub.execute_input":"2021-09-03T18:15:33.706611Z","iopub.status.idle":"2021-09-03T18:15:33.724406Z","shell.execute_reply.started":"2021-09-03T18:15:33.706583Z","shell.execute_reply":"2021-09-03T18:15:33.723378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Reading DR grades files of 2019, Messidor & IDRiD\ntrain2019 = pd.read_csv('../input/aptos2019-blindness-detection/train.csv')\ntrain2019 = train2019[['id_code', 'diagnosis']]","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:15:39.720459Z","iopub.execute_input":"2021-09-03T18:15:39.720777Z","iopub.status.idle":"2021-09-03T18:15:39.74141Z","shell.execute_reply.started":"2021-09-03T18:15:39.720747Z","shell.execute_reply":"2021-09-03T18:15:39.740635Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Fetching DR grades of the respective images of 2019\nlabels = list()\nid_code = list()\nfor i, j in train2019.iterrows():\n    id_code.append(j['id_code'])\n    labels.append(j['diagnosis'])","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:15:43.442792Z","iopub.execute_input":"2021-09-03T18:15:43.443095Z","iopub.status.idle":"2021-09-03T18:15:43.72504Z","shell.execute_reply.started":"2021-09-03T18:15:43.443066Z","shell.execute_reply":"2021-09-03T18:15:43.72422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels = pd.DataFrame() # Storing the image file name & DR grades into the dataframe\ntrain_labels['id_code'] = id_code\ntrain_labels['diagnosis'] = labels","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:15:47.11233Z","iopub.execute_input":"2021-09-03T18:15:47.11264Z","iopub.status.idle":"2021-09-03T18:15:47.124569Z","shell.execute_reply.started":"2021-09-03T18:15:47.112611Z","shell.execute_reply":"2021-09-03T18:15:47.123785Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Merging the image path & DR grades \npre_df = pd.merge(pre_df, train_labels, on='id_code', how='left')","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:15:50.848982Z","iopub.execute_input":"2021-09-03T18:15:50.849349Z","iopub.status.idle":"2021-09-03T18:15:50.869866Z","shell.execute_reply.started":"2021-09-03T18:15:50.849315Z","shell.execute_reply":"2021-09-03T18:15:50.868772Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pre_df = pre_df[pre_df['diagnosis'].notna()] # removing row if the DR grade is NaN","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:15:59.814037Z","iopub.execute_input":"2021-09-03T18:15:59.814389Z","iopub.status.idle":"2021-09-03T18:15:59.822149Z","shell.execute_reply.started":"2021-09-03T18:15:59.814361Z","shell.execute_reply":"2021-09-03T18:15:59.821401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(pre_df[pre_df['diagnosis'].isnull()]) # Verify if there is any NaN present in the DR grades field","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:16:03.498729Z","iopub.execute_input":"2021-09-03T18:16:03.499033Z","iopub.status.idle":"2021-09-03T18:16:03.509975Z","shell.execute_reply.started":"2021-09-03T18:16:03.499005Z","shell.execute_reply":"2021-09-03T18:16:03.508947Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"convert_dict = {'diagnosis': str}\n  \npre_df = pre_df.astype(convert_dict)","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:16:11.040635Z","iopub.execute_input":"2021-09-03T18:16:11.040941Z","iopub.status.idle":"2021-09-03T18:16:11.05365Z","shell.execute_reply.started":"2021-09-03T18:16:11.040912Z","shell.execute_reply":"2021-09-03T18:16:11.052812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Train and test data split up**","metadata":{}},{"cell_type":"code","source":"# train test split\nfrom sklearn.model_selection import train_test_split\ny = pre_df['diagnosis'].values\nX_train, X_test, y_train, y_test = train_test_split(pre_df, y, test_size=0.20, stratify=y)","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:16:30.102784Z","iopub.execute_input":"2021-09-03T18:16:30.10311Z","iopub.status.idle":"2021-09-03T18:16:30.13125Z","shell.execute_reply.started":"2021-09-03T18:16:30.103081Z","shell.execute_reply":"2021-09-03T18:16:30.13042Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(X_train.shape)\nprint(X_test.shape)\nprint(y_train.shape)\nprint(y_test.shape)","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:16:33.995998Z","iopub.execute_input":"2021-09-03T18:16:33.996324Z","iopub.status.idle":"2021-09-03T18:16:34.001576Z","shell.execute_reply.started":"2021-09-03T18:16:33.996293Z","shell.execute_reply":"2021-09-03T18:16:34.000761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Hyperparameters\nbatch_size = 8\nnum_classes = 5\nl = 14\nnum_filter = 32\ncompression = 0.5\ndropout_rate = 0","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:16:55.462113Z","iopub.execute_input":"2021-09-03T18:16:55.462448Z","iopub.status.idle":"2021-09-03T18:16:55.466636Z","shell.execute_reply.started":"2021-09-03T18:16:55.46242Z","shell.execute_reply":"2021-09-03T18:16:55.465592Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_height = 32\nimg_width = 32\nchannel = 3","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:16:59.233632Z","iopub.execute_input":"2021-09-03T18:16:59.233943Z","iopub.status.idle":"2021-09-03T18:16:59.237876Z","shell.execute_reply.started":"2021-09-03T18:16:59.233914Z","shell.execute_reply":"2021-09-03T18:16:59.236872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Building DensetNet Model**","metadata":{}},{"cell_type":"code","source":"tf.keras.backend.clear_session()\n# Dense Block\ndef denseblock(input, num_filter, dropout_rate):\n    global compression\n    temp = input\n    for _ in range(l): \n        BatchNorm = layers.BatchNormalization()(temp)\n        relu = layers.Activation('relu')(BatchNorm)\n        Conv2D_3_3 = layers.Conv2D(int(num_filter*compression), (3,3), use_bias=False ,padding='same')(relu)\n        if dropout_rate>0:\n            Conv2D_3_3 = layers.Dropout(dropout_rate)(Conv2D_3_3)\n        concat = layers.Concatenate(axis=-1)([temp,Conv2D_3_3])\n        \n        temp = concat\n        \n    return temp\n\n## transition Blosck\ndef transition(input, num_filter, dropout_rate):\n    global compression\n    BatchNorm = layers.BatchNormalization()(input)\n    relu = layers.Activation('relu')(BatchNorm)\n    Conv2D_BottleNeck = layers.Conv2D(int(num_filter*compression), (1,1), use_bias=False ,padding='same')(relu)\n    if dropout_rate>0:\n         Conv2D_BottleNeck = layers.Dropout(dropout_rate)(Conv2D_BottleNeck)\n    avg = layers.AveragePooling2D(pool_size=(2,2))(Conv2D_BottleNeck)\n    return avg\n\n#output layer\ndef output_layer(input):\n    global compression\n    BatchNorm = layers.BatchNormalization()(input)\n    relu = layers.Activation('relu')(BatchNorm)\n    AvgPooling = layers.AveragePooling2D(pool_size=(2,2))(relu)\n    flat = layers.Flatten()(AvgPooling)\n    output = layers.Dense(num_classes, activation='softmax')(flat)\n    return output","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:17:03.300885Z","iopub.execute_input":"2021-09-03T18:17:03.301218Z","iopub.status.idle":"2021-09-03T18:17:03.325592Z","shell.execute_reply.started":"2021-09-03T18:17:03.301184Z","shell.execute_reply":"2021-09-03T18:17:03.324826Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_filter = 32\ndropout_rate = 0\nl = 14\n\ntf.keras.backend.clear_session()\ninput = layers.Input(shape=(img_height, img_width, channel,))\nFirst_Conv2D = layers.Conv2D(24, (2,2), use_bias=False ,padding='same', kernel_initializer='he_uniform', bias_initializer='zeros',kernel_regularizer=l2(0.0001))(input)\n\nFirst_Block = denseblock(First_Conv2D, num_filter, dropout_rate)\nFirst_Transition = transition(First_Block, num_filter, dropout_rate)\n\nSecond_Block = denseblock(First_Transition, num_filter, dropout_rate)\nSecond_Transition = transition(Second_Block, num_filter, dropout_rate)\n\nThird_Block = denseblock(Second_Transition, num_filter, dropout_rate)\nThird_Transition = transition(Third_Block, num_filter, dropout_rate)\n\nLast_Block = denseblock(Third_Transition, num_filter, dropout_rate)\noutput = output_layer(Last_Block)","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:17:10.25037Z","iopub.execute_input":"2021-09-03T18:17:10.250689Z","iopub.status.idle":"2021-09-03T18:17:13.51411Z","shell.execute_reply.started":"2021-09-03T18:17:10.250661Z","shell.execute_reply":"2021-09-03T18:17:13.513311Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = Model(inputs=[input], outputs=[output])\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:17:16.362516Z","iopub.execute_input":"2021-09-03T18:17:16.362858Z","iopub.status.idle":"2021-09-03T18:17:16.494125Z","shell.execute_reply.started":"2021-09-03T18:17:16.362827Z","shell.execute_reply":"2021-09-03T18:17:16.493364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#optimizer = SGD(learning_rate=0.1, momentum=0.9, decay= 1e-6, nesterov=True)\noptimizer = tf.keras.optimizers.Adam(learning_rate=0.0001)\nmodel.compile(loss='categorical_crossentropy',\n              optimizer=optimizer,\n              metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:19:03.192728Z","iopub.execute_input":"2021-09-03T18:19:03.193065Z","iopub.status.idle":"2021-09-03T18:19:03.212918Z","shell.execute_reply.started":"2021-09-03T18:19:03.19301Z","shell.execute_reply":"2021-09-03T18:19:03.212089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# reference URL - https://vijayabhaskar96.medium.com/tutorial-on-keras-flow-from-dataframe-1fd4493d237c\nfrom keras_preprocessing.image import ImageDataGenerator\n\ndatagen=ImageDataGenerator(rescale=1./255., validation_split=0.20, horizontal_flip=True)\n\ntrain_generator=datagen.flow_from_dataframe(dataframe=X_train, directory=None, x_col=\"path\", y_col=\"diagnosis\", subset=\"training\", \n                batch_size=8, shuffle=True, class_mode=\"categorical\", drop_duplicates = False, target_size=(32,32))\n\nvalid_generator=datagen.flow_from_dataframe(dataframe=X_train, directory=None, x_col=\"path\", y_col=\"diagnosis\", subset=\"validation\", \n                        batch_size=8, shuffle=True, class_mode=\"categorical\", drop_duplicates = False, target_size=(32,32))\n\ntest_datagen=ImageDataGenerator(rescale=1./255.)\n\ntest_generator=test_datagen.flow_from_dataframe(dataframe=X_test, directory=None, x_col=\"path\", \n                y_col=None, batch_size=1, shuffle=False, class_mode=None, target_size=(32,32))","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:17:52.209511Z","iopub.execute_input":"2021-09-03T18:17:52.209824Z","iopub.status.idle":"2021-09-03T18:17:53.426655Z","shell.execute_reply.started":"2021-09-03T18:17:52.209793Z","shell.execute_reply":"2021-09-03T18:17:53.425763Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Training the model**","metadata":{}},{"cell_type":"code","source":"STEP_SIZE_TRAIN=train_generator.n//train_generator.batch_size\nSTEP_SIZE_VALID=valid_generator.n//valid_generator.batch_size\nSTEP_SIZE_TEST=test_generator.n//test_generator.batch_size\nmodel.fit_generator(generator=train_generator, steps_per_epoch=STEP_SIZE_TRAIN, validation_data=valid_generator,\n                    validation_steps=STEP_SIZE_VALID, epochs=50)","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:21:08.894239Z","iopub.execute_input":"2021-09-03T18:21:08.894608Z","iopub.status.idle":"2021-09-03T18:28:54.015287Z","shell.execute_reply.started":"2021-09-03T18:21:08.894575Z","shell.execute_reply":"2021-09-03T18:28:54.014485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Prediction on test data**","metadata":{}},{"cell_type":"code","source":"y_pred = model.predict(test_generator)\ny_pred_class = np.argmax(y_pred, axis=1)","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:31:02.521618Z","iopub.execute_input":"2021-09-03T18:31:02.521959Z","iopub.status.idle":"2021-09-03T18:32:53.458977Z","shell.execute_reply.started":"2021-09-03T18:31:02.521926Z","shell.execute_reply":"2021-09-03T18:32:53.458128Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Calcualting KAPPA and Macro F1 score on test data**","metadata":{}},{"cell_type":"code","source":"cohen = cohen_kappa_score(y_pred_class, y_test.astype('int'), weights='quadratic')\nprint(\"Quadratic Cohen kappa score of VGG model on test data is - %.3f\" %cohen)","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:33:15.728913Z","iopub.execute_input":"2021-09-03T18:33:15.729241Z","iopub.status.idle":"2021-09-03T18:33:15.738849Z","shell.execute_reply.started":"2021-09-03T18:33:15.729211Z","shell.execute_reply":"2021-09-03T18:33:15.737856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print ('Classification Report : \\n', classification_report(y_test.astype('int'), y_pred_class))\nsns.heatmap(confusion_matrix(y_test.astype('int'), y_pred_class), annot=True, fmt=\"d\");\nplt.title(\"Confusion matrix\")\nplt.ylabel('Actual class')\nplt.xlabel('Predicted class')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:33:18.002741Z","iopub.execute_input":"2021-09-03T18:33:18.003059Z","iopub.status.idle":"2021-09-03T18:33:18.296742Z","shell.execute_reply.started":"2021-09-03T18:33:18.003029Z","shell.execute_reply":"2021-09-03T18:33:18.295972Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Reading Test data and predicting DR grades using trained model**","metadata":{}},{"cell_type":"code","source":"img_path = list()\nimg_fullname = list()\nimg_name = list()\nfor dirname, _, filenames in os.walk('../input/aptos2019-blindness-detection/test_images/'):\n    for filename in filenames:\n        img_path.append(os.path.join(dirname, filename))\n        temp = os.path.join(dirname, filename)\n        temp = temp.split(\"/\")[-1]\n        img_fullname.append(temp)\n        temp = temp.split(\".\")[0]\n        img_name.append(str(temp))\n","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:39:13.236759Z","iopub.execute_input":"2021-09-03T18:39:13.237067Z","iopub.status.idle":"2021-09-03T18:39:13.257911Z","shell.execute_reply.started":"2021-09-03T18:39:13.237038Z","shell.execute_reply":"2021-09-03T18:39:13.257134Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pre_df = pd.DataFrame()\npre_df['path'] = img_path\npre_df['fullname'] = img_fullname\npre_df['id_code'] = img_name","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:39:14.931026Z","iopub.execute_input":"2021-09-03T18:39:14.931397Z","iopub.status.idle":"2021-09-03T18:39:14.941893Z","shell.execute_reply.started":"2021-09-03T18:39:14.931365Z","shell.execute_reply":"2021-09-03T18:39:14.940943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_datagen=ImageDataGenerator(rescale=1./255.)\n\ntest_generator_2019=test_datagen.flow_from_dataframe(dataframe=pre_df, directory=None, x_col=\"path\", \n                y_col=None, batch_size=1, shuffle=False, class_mode=None, target_size=(32,32))","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:39:36.55454Z","iopub.execute_input":"2021-09-03T18:39:36.554859Z","iopub.status.idle":"2021-09-03T18:39:37.273701Z","shell.execute_reply.started":"2021-09-03T18:39:36.554829Z","shell.execute_reply":"2021-09-03T18:39:37.27287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred_2019 = model.predict(test_generator_2019)\ny_pred_class_2019 = np.argmax(y_pred_2019, axis=1)","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:39:50.395676Z","iopub.execute_input":"2021-09-03T18:39:50.39599Z","iopub.status.idle":"2021-09-03T18:40:57.86113Z","shell.execute_reply.started":"2021-09-03T18:39:50.39596Z","shell.execute_reply":"2021-09-03T18:40:57.860277Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filenames = list()\nfor i in test_generator_2019.filenames:\n    temp = i.split('.')[-2]\n    temp = temp.split('/')[-1]\n    filenames.append(temp)","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:41:56.294073Z","iopub.execute_input":"2021-09-03T18:41:56.294479Z","iopub.status.idle":"2021-09-03T18:41:56.302738Z","shell.execute_reply.started":"2021-09-03T18:41:56.294437Z","shell.execute_reply":"2021-09-03T18:41:56.301678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_dense = pd.DataFrame()\nsubmission_dense['id_code'] = filenames\nsubmission_dense['diagnosis'] = y_pred_class_2019","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:42:05.296251Z","iopub.execute_input":"2021-09-03T18:42:05.296588Z","iopub.status.idle":"2021-09-03T18:42:05.303711Z","shell.execute_reply.started":"2021-09-03T18:42:05.296558Z","shell.execute_reply":"2021-09-03T18:42:05.302882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_dense","metadata":{"execution":{"iopub.status.busy":"2021-09-03T18:42:07.26776Z","iopub.execute_input":"2021-09-03T18:42:07.268073Z","iopub.status.idle":"2021-09-03T18:42:07.289938Z","shell.execute_reply.started":"2021-09-03T18:42:07.268044Z","shell.execute_reply":"2021-09-03T18:42:07.289196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_dense.to_csv('./submission.csv', index=False)","metadata":{},"execution_count":null,"outputs":[]}]}