{"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":"# importing required libraries, modules and pretrained model \n\nimport os\nimport tensorflow as tf\nfrom tensorflow import keras\nfrom skimage import io\nimport matplotlib.pyplot as plt\nimport pandas as pd\nimport numpy as np\nfrom sklearn.model_selection import train_test_split\nfrom tensorflow.keras.layers import Input, Dense, Conv2D, MaxPool2D, Dropout, Flatten, AveragePooling2D\nfrom tensorflow.keras.optimizers import RMSprop, SGD\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint\nfrom tensorflow.keras import Sequential\nfrom tensorflow.keras.models import Model\nfrom tensorflow.keras.applications.xception import Xception\n\n\nSEED = 42\nSIZE = (224, 224)\nBATCH_SIZE = 32\n\npd.set_option('display.max_rows', None)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-05-03T16:31:31.223035Z","iopub.execute_input":"2022-05-03T16:31:31.223301Z","iopub.status.idle":"2022-05-03T16:31:32.421049Z","shell.execute_reply.started":"2022-05-03T16:31:31.223257Z","shell.execute_reply":"2022-05-03T16:31:32.420325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# training and validation data\n\nlabels = pd.read_csv('../input/dog-breed-identification/labels.csv')\nlabels.head()","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:31:32.423031Z","iopub.execute_input":"2022-05-03T16:31:32.423362Z","iopub.status.idle":"2022-05-03T16:31:32.461115Z","shell.execute_reply.started":"2022-05-03T16:31:32.423323Z","shell.execute_reply":"2022-05-03T16:31:32.460347Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels['id'] = labels['id'].apply(lambda x: x + '.jpg')\nlabels.head()","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:31:32.462574Z","iopub.execute_input":"2022-05-03T16:31:32.462834Z","iopub.status.idle":"2022-05-03T16:31:32.478916Z","shell.execute_reply.started":"2022-05-03T16:31:32.4628Z","shell.execute_reply":"2022-05-03T16:31:32.477891Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels['breed'].value_counts().plot.bar(figsize=(16, 8))","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:31:32.481308Z","iopub.execute_input":"2022-05-03T16:31:32.481567Z","iopub.status.idle":"2022-05-03T16:31:34.392681Z","shell.execute_reply.started":"2022-05-03T16:31:32.481525Z","shell.execute_reply":"2022-05-03T16:31:34.391997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"****The data distribution is kind of ok. Maybe some data augmentaion to increase the lower quantity classes can be useful. Hopefully this part will be added to the notebook soon.****","metadata":{}},{"cell_type":"code","source":"# ImageDatagenerator to load the images in batches and perform data augmentation\n\ndata_generator = ImageDataGenerator(rescale= 1./255, validation_split=0.2, rotation_range=20,\n                                    zoom_range=0.1, width_shift_range=0.2, height_shift_range=0.2,\n                                    shear_range=0.1, horizontal_flip=True, fill_mode=\"nearest\")","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:31:34.393625Z","iopub.execute_input":"2022-05-03T16:31:34.393859Z","iopub.status.idle":"2022-05-03T16:31:34.399207Z","shell.execute_reply.started":"2022-05-03T16:31:34.393824Z","shell.execute_reply":"2022-05-03T16:31:34.398159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_generator = data_generator.flow_from_dataframe(labels, directory='../input/dog-breed-identification/train/', x_col='id', y_col='breed', target_size=SIZE, class_mode='categorical', batch_size=BATCH_SIZE, shuffle=True, seed=SEED, subset='training')\nval_generator = data_generator.flow_from_dataframe(labels, directory='../input/dog-breed-identification/train/', x_col='id', y_col='breed', target_size=SIZE, class_mode='categorical', batch_size=BATCH_SIZE, shuffle=True, seed=SEED, subset='validation')","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:31:34.400651Z","iopub.execute_input":"2022-05-03T16:31:34.401101Z","iopub.status.idle":"2022-05-03T16:32:10.277376Z","shell.execute_reply.started":"2022-05-03T16:31:34.401064Z","shell.execute_reply":"2022-05-03T16:32:10.27664Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 12 images after augmentation\n\nimg, label = next(train_generator)\nfig = plt.figure(figsize=(15, 10))\n\nfor i in range(12):\n    fig.add_subplot(3, 4, i+1)\n    plt.imshow(img[i])\n    plt.axis('off')","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:10.278486Z","iopub.execute_input":"2022-05-03T16:32:10.27891Z","iopub.status.idle":"2022-05-03T16:32:11.780001Z","shell.execute_reply.started":"2022-05-03T16:32:10.278872Z","shell.execute_reply":"2022-05-03T16:32:11.779396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# callbacks that will be used during training\n\nearly_stopping = EarlyStopping(monitor='val_loss', mode = 'min', patience=10)\ncheckpoint = ModelCheckpoint(filepath = './weights.hdf5', verbose=1, save_best_only=True)\\","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:11.781011Z","iopub.execute_input":"2022-05-03T16:32:11.781422Z","iopub.status.idle":"2022-05-03T16:32:11.788637Z","shell.execute_reply.started":"2022-05-03T16:32:11.781386Z","shell.execute_reply":"2022-05-03T16:32:11.788001Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"****The pretrained Xeption model on the imagenet dataset will be used. The Inception and ResNet models were also tried but have not performed better.****","metadata":{}},{"cell_type":"code","source":"from keras.applications.vgg16 import VGG16\nfrom keras.applications.vgg16 import preprocess_input","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:11.789962Z","iopub.execute_input":"2022-05-03T16:32:11.790407Z","iopub.status.idle":"2022-05-03T16:32:11.795653Z","shell.execute_reply.started":"2022-05-03T16:32:11.790372Z","shell.execute_reply":"2022-05-03T16:32:11.794893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_model = VGG16(weights='imagenet', include_top = True, input_shape=(224,224,3))","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:11.799052Z","iopub.execute_input":"2022-05-03T16:32:11.799519Z","iopub.status.idle":"2022-05-03T16:32:13.653758Z","shell.execute_reply.started":"2022-05-03T16:32:11.799485Z","shell.execute_reply":"2022-05-03T16:32:13.653019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for layer in base_model.layers:\n    layer.trainable = False","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.655257Z","iopub.execute_input":"2022-05-03T16:32:13.655521Z","iopub.status.idle":"2022-05-03T16:32:13.660111Z","shell.execute_reply.started":"2022-05-03T16:32:13.655485Z","shell.execute_reply":"2022-05-03T16:32:13.659438Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\nx = base_model.output\nx = Flatten()(x)\nx = Dense(1024, activation='relu')(x)\nx = Dropout(0.3)(x)\nx = Dense(512, activation='relu')(x)\nx = Dropout(0.3)(x)\nx = Dense(120, activation='softmax')(x)\ntransfer_model = Model(inputs=base_model.input, outputs=x)\n\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:52:29.797991Z","iopub.execute_input":"2022-05-03T16:52:29.798256Z","iopub.status.idle":"2022-05-03T16:52:29.835963Z","shell.execute_reply.started":"2022-05-03T16:52:29.798227Z","shell.execute_reply":"2022-05-03T16:52:29.835331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\noptimizer = SGD(learning_rate=0.1, momentum=0.9, decay=0.01)\ntransfer_model.compile(loss=\"categorical_crossentropy\", optimizer=optimizer, metrics=[\"accuracy\"])","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:52:37.895945Z","iopub.execute_input":"2022-05-03T16:52:37.896201Z","iopub.status.idle":"2022-05-03T16:52:37.90981Z","shell.execute_reply.started":"2022-05-03T16:52:37.896173Z","shell.execute_reply":"2022-05-03T16:52:37.909129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"#first cycle\n\nhistory1 = transfer_model.fit(train_generator, epochs=5, validation_data=val_generator, callbacks=[checkpoint])","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-05-03T16:52:42.988792Z","iopub.execute_input":"2022-05-03T16:52:42.989043Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.applications.xception import Xception\n\nearly_stopping = EarlyStopping(monitor='val_loss', mode = 'min', patience=10)\ncheckpoint = ModelCheckpoint(filepath = './weights.hdf5', verbose=1, save_best_only=True)","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.774898Z","iopub.status.idle":"2022-05-03T16:32:13.775514Z","shell.execute_reply.started":"2022-05-03T16:32:13.775271Z","shell.execute_reply":"2022-05-03T16:32:13.77531Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**The model clearly started overfitting after after couple of epochs so the best weights saved in the weigh.hdf5 file will be loaded before the third cycle.**","metadata":{}},{"cell_type":"code","source":"\n\nbase_model = Xception(weights=\"imagenet\", include_top=False, input_tensor=Input(shape=(224, 224, 3)))\n\nbase_model.summary()\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.776686Z","iopub.status.idle":"2022-05-03T16:32:13.777316Z","shell.execute_reply.started":"2022-05-03T16:32:13.777065Z","shell.execute_reply":"2022-05-03T16:32:13.777089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\nfor layer in base_model.layers:\n    layer.trainable = False\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.778485Z","iopub.status.idle":"2022-05-03T16:32:13.779102Z","shell.execute_reply.started":"2022-05-03T16:32:13.778871Z","shell.execute_reply":"2022-05-03T16:32:13.778895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**The model performance did not improve at all so we will return to the best weights reached in the second cycle.**","metadata":{}},{"cell_type":"code","source":"\n\nhead_model = AveragePooling2D(pool_size=(4, 4))(base_model.output)\nhead_model = Flatten(name='flatten')(head_model)\nhead_model = Dense(1024, activation='relu')(head_model)\nhead_model = Dropout(0.3)(head_model)\nhead_model = Dense(512, activation='relu')(head_model)\nhead_model = Dropout(0.3)(head_model)\nhead_model = Dense(120, activation='softmax')(head_model)\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.780278Z","iopub.status.idle":"2022-05-03T16:32:13.780908Z","shell.execute_reply.started":"2022-05-03T16:32:13.780667Z","shell.execute_reply":"2022-05-03T16:32:13.780691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\nmodel = Model(inputs=base_model.input, outputs=head_model)\noptimizer = SGD(learning_rate=0.1, momentum=0.9, decay=0.01)\nmodel.compile(loss=\"categorical_crossentropy\", optimizer=optimizer, metrics=[\"accuracy\"])\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.782229Z","iopub.status.idle":"2022-05-03T16:32:13.782933Z","shell.execute_reply.started":"2022-05-03T16:32:13.782689Z","shell.execute_reply":"2022-05-03T16:32:13.782723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history1 = model.fit(train_generator, epochs=5, validation_data=val_generator, callbacks=[checkpoint])","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.784085Z","iopub.status.idle":"2022-05-03T16:32:13.784721Z","shell.execute_reply.started":"2022-05-03T16:32:13.784479Z","shell.execute_reply":"2022-05-03T16:32:13.784504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(history1.history['accuracy'], label='training accuracy')\nplt.plot(history1.history['val_accuracy'], label='validation accuracy')\nplt.xlabel('Epochs')\nplt.ylabel('Training and Validation Accuracy')\nplt.legend(loc='lower right')","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.785878Z","iopub.status.idle":"2022-05-03T16:32:13.786489Z","shell.execute_reply.started":"2022-05-03T16:32:13.786249Z","shell.execute_reply":"2022-05-03T16:32:13.786274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\nplt.plot(history1.history['loss'], label='training loss')\nplt.plot(history1.history['val_loss'], label='validation loss')\nplt.xlabel('Epochs')\nplt.ylabel('Training and Validation Loss')\nplt.legend()\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.787634Z","iopub.status.idle":"2022-05-03T16:32:13.788248Z","shell.execute_reply.started":"2022-05-03T16:32:13.788018Z","shell.execute_reply":"2022-05-03T16:32:13.788043Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for layer in base_model.layers[len(base_model.layers)//2:]:\n    layer.trainable = True\n\noptimizer = SGD(learning_rate=0.01, momentum=0.9, decay=0.001)\nmodel.compile(loss=\"categorical_crossentropy\", optimizer=optimizer, metrics=[\"accuracy\"])","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.789424Z","iopub.status.idle":"2022-05-03T16:32:13.790041Z","shell.execute_reply.started":"2022-05-03T16:32:13.78981Z","shell.execute_reply":"2022-05-03T16:32:13.789834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history2 = model.fit(train_generator, epochs=10, validation_data=val_generator, callbacks=[checkpoint])","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.791222Z","iopub.status.idle":"2022-05-03T16:32:13.791937Z","shell.execute_reply.started":"2022-05-03T16:32:13.791663Z","shell.execute_reply":"2022-05-03T16:32:13.79169Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\nplt.plot(history2.history['accuracy'], label='training accuracy')\nplt.plot(history2.history['val_accuracy'], label='validation accuracy')\nplt.xlabel('Epochs')\nplt.ylabel('Training and Validation Accuracy')\nplt.legend(loc='lower right')\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.793144Z","iopub.status.idle":"2022-05-03T16:32:13.793772Z","shell.execute_reply.started":"2022-05-03T16:32:13.793531Z","shell.execute_reply":"2022-05-03T16:32:13.793555Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\nplt.plot(history2.history['loss'], label='training loss')\nplt.plot(history2.history['val_loss'], label='validation loss')\nplt.xlabel('Epochs')\nplt.ylabel('Training and Validation Loss')\nplt.legend()\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.794919Z","iopub.status.idle":"2022-05-03T16:32:13.795533Z","shell.execute_reply.started":"2022-05-03T16:32:13.795309Z","shell.execute_reply":"2022-05-03T16:32:13.795333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for layer in base_model.layers:\n    layer.trainable = True\n\noptimizer = SGD(learning_rate=0.01, momentum=0.9, decay=0.001)\nmodel.compile(loss=\"categorical_crossentropy\", optimizer=optimizer, metrics=[\"accuracy\"])","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.796674Z","iopub.status.idle":"2022-05-03T16:32:13.797307Z","shell.execute_reply.started":"2022-05-03T16:32:13.797056Z","shell.execute_reply":"2022-05-03T16:32:13.79708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\nhistory3 = model.fit(train_generator, epochs=100, validation_data=val_generator, callbacks=[checkpoint, early_stopping])\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.798447Z","iopub.status.idle":"2022-05-03T16:32:13.799058Z","shell.execute_reply.started":"2022-05-03T16:32:13.798829Z","shell.execute_reply":"2022-05-03T16:32:13.798853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(history3.history['loss'], label='training loss')\nplt.plot(history3.history['val_loss'], label='validation loss')\nplt.xlabel('Epochs')\nplt.ylabel('Training and Validation Loss')\nplt.legend()","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.800214Z","iopub.status.idle":"2022-05-03T16:32:13.800991Z","shell.execute_reply.started":"2022-05-03T16:32:13.800609Z","shell.execute_reply":"2022-05-03T16:32:13.800633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_images_files_names = os.listdir('../input/dog-breed-identification/test/')\ntest_set = pd.DataFrame(test_images_files_names, columns=['id'])\ntest_set.head()","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.803039Z","iopub.status.idle":"2022-05-03T16:32:13.803586Z","shell.execute_reply.started":"2022-05-03T16:32:13.803328Z","shell.execute_reply":"2022-05-03T16:32:13.803354Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data_generator = ImageDataGenerator(rescale= 1./255)\ntest_generator = test_data_generator.flow_from_dataframe(test_set, directory='../input/dog-breed-identification/test/', x_col='id',target_size=SIZE, class_mode=None, batch_size=BATCH_SIZE, shuffle=False)","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.805115Z","iopub.status.idle":"2022-05-03T16:32:13.805543Z","shell.execute_reply.started":"2022-05-03T16:32:13.805319Z","shell.execute_reply":"2022-05-03T16:32:13.805342Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.load_weights('./weights.hdf5')","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.806971Z","iopub.status.idle":"2022-05-03T16:32:13.80786Z","shell.execute_reply.started":"2022-05-03T16:32:13.807611Z","shell.execute_reply":"2022-05-03T16:32:13.807636Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_prop = model.predict(test_generator)","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.808893Z","iopub.status.idle":"2022-05-03T16:32:13.809706Z","shell.execute_reply.started":"2022-05-03T16:32:13.809463Z","shell.execute_reply":"2022-05-03T16:32:13.809489Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\nresults = pd.DataFrame(columns=[\"id\"] + [*train_generator.class_indices.keys()])\nresults\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.810859Z","iopub.status.idle":"2022-05-03T16:32:13.811319Z","shell.execute_reply.started":"2022-05-03T16:32:13.811038Z","shell.execute_reply":"2022-05-03T16:32:13.81106Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\nresults[\"id\"] = [os.path.splitext(file)[0] for file in os.listdir('../input/dog-breed-identification/test/')]\nresults.head()\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.812594Z","iopub.status.idle":"2022-05-03T16:32:13.813338Z","shell.execute_reply.started":"2022-05-03T16:32:13.813075Z","shell.execute_reply":"2022-05-03T16:32:13.8131Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nresults[[*train_generator.class_indices.keys()]] = y_prop\nresults.to_csv(\"results.csv\",index=False)\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.814577Z","iopub.status.idle":"2022-05-03T16:32:13.814991Z","shell.execute_reply.started":"2022-05-03T16:32:13.814775Z","shell.execute_reply":"2022-05-03T16:32:13.814797Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"results.head()","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.816135Z","iopub.status.idle":"2022-05-03T16:32:13.816789Z","shell.execute_reply.started":"2022-05-03T16:32:13.816542Z","shell.execute_reply":"2022-05-03T16:32:13.816572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = results.loc[ : , results.columns != 'id']","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.817901Z","iopub.status.idle":"2022-05-03T16:32:13.818854Z","shell.execute_reply.started":"2022-05-03T16:32:13.818615Z","shell.execute_reply":"2022-05-03T16:32:13.81864Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.820101Z","iopub.status.idle":"2022-05-03T16:32:13.820529Z","shell.execute_reply.started":"2022-05-03T16:32:13.820313Z","shell.execute_reply":"2022-05-03T16:32:13.820335Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.idxmax(axis=1).head()","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.8217Z","iopub.status.idle":"2022-05-03T16:32:13.822382Z","shell.execute_reply.started":"2022-05-03T16:32:13.822077Z","shell.execute_reply":"2022-05-03T16:32:13.822106Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nresultsColumn = df.columns.to_numpy()\nresultsColumn","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.823561Z","iopub.status.idle":"2022-05-03T16:32:13.824176Z","shell.execute_reply.started":"2022-05-03T16:32:13.823942Z","shell.execute_reply":"2022-05-03T16:32:13.823965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"maxPrediction = max(prediction[0])","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.82569Z","iopub.status.idle":"2022-05-03T16:32:13.826085Z","shell.execute_reply.started":"2022-05-03T16:32:13.825873Z","shell.execute_reply":"2022-05-03T16:32:13.825895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"index = np.where(prediction[0] == maxPrediction)","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.828029Z","iopub.status.idle":"2022-05-03T16:32:13.828918Z","shell.execute_reply.started":"2022-05-03T16:32:13.828672Z","shell.execute_reply":"2022-05-03T16:32:13.828697Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(resultsColumn[index])","metadata":{"execution":{"iopub.status.busy":"2022-05-03T16:32:13.829958Z","iopub.status.idle":"2022-05-03T16:32:13.830767Z","shell.execute_reply.started":"2022-05-03T16:32:13.830523Z","shell.execute_reply":"2022-05-03T16:32:13.830553Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}