{"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":"markdown","source":"https://www.kaggle.com/competitions/vehicle/overview","metadata":{}},{"cell_type":"code","source":"cd ../input/vehicle/","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:50:33.633165Z","iopub.execute_input":"2022-07-21T03:50:33.633554Z","iopub.status.idle":"2022-07-21T03:50:33.663043Z","shell.execute_reply.started":"2022-07-21T03:50:33.633464Z","shell.execute_reply":"2022-07-21T03:50:33.662247Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:50:33.66487Z","iopub.execute_input":"2022-07-21T03:50:33.66521Z","iopub.status.idle":"2022-07-21T03:50:34.355654Z","shell.execute_reply.started":"2022-07-21T03:50:33.665154Z","shell.execute_reply":"2022-07-21T03:50:34.354828Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Import library\nimport os\nimport shutil\nimport glob\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd\nfrom math import ceil\nfrom collections import Counter","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:50:34.357004Z","iopub.execute_input":"2022-07-21T03:50:34.357265Z","iopub.status.idle":"2022-07-21T03:50:35.533291Z","shell.execute_reply.started":"2022-07-21T03:50:34.357224Z","shell.execute_reply":"2022-07-21T03:50:35.532474Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import LabelEncoder\nfrom sklearn.utils import class_weight","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:50:35.535558Z","iopub.execute_input":"2022-07-21T03:50:35.536056Z","iopub.status.idle":"2022-07-21T03:50:35.920694Z","shell.execute_reply.started":"2022-07-21T03:50:35.536018Z","shell.execute_reply":"2022-07-21T03:50:35.91985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import itertools\nimport tensorflow as tf \nfrom tensorflow.keras.layers import Conv2D, MaxPooling2D, Dropout, Flatten, Dense, GlobalAveragePooling2D\nfrom tensorflow.keras.layers import BatchNormalization\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom tensorflow.keras.callbacks import ModelCheckpoint, EarlyStopping\nfrom tensorflow.keras import models, optimizers, regularizers","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:50:35.925654Z","iopub.execute_input":"2022-07-21T03:50:35.928152Z","iopub.status.idle":"2022-07-21T03:50:42.264775Z","shell.execute_reply.started":"2022-07-21T03:50:35.928114Z","shell.execute_reply":"2022-07-21T03:50:42.263921Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.applications.efficientnet import preprocess_input as preprocess_input_efficientnet\nfrom tensorflow.keras.applications.inception_v3 import preprocess_input as preprocess_input_inception_v3","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:50:42.26646Z","iopub.execute_input":"2022-07-21T03:50:42.266986Z","iopub.status.idle":"2022-07-21T03:50:42.280565Z","shell.execute_reply.started":"2022-07-21T03:50:42.266946Z","shell.execute_reply":"2022-07-21T03:50:42.278253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow_hub as hub","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:50:42.28193Z","iopub.execute_input":"2022-07-21T03:50:42.282366Z","iopub.status.idle":"2022-07-21T03:50:42.674161Z","shell.execute_reply.started":"2022-07-21T03:50:42.282333Z","shell.execute_reply":"2022-07-21T03:50:42.673449Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import warnings\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:50:42.677219Z","iopub.execute_input":"2022-07-21T03:50:42.677429Z","iopub.status.idle":"2022-07-21T03:50:42.684065Z","shell.execute_reply.started":"2022-07-21T03:50:42.677404Z","shell.execute_reply":"2022-07-21T03:50:42.682846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path_train_orig='train/train/'\npath_test='test/'","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:50:42.685336Z","iopub.execute_input":"2022-07-21T03:50:42.685702Z","iopub.status.idle":"2022-07-21T03:50:42.695306Z","shell.execute_reply.started":"2022-07-21T03:50:42.685665Z","shell.execute_reply":"2022-07-21T03:50:42.694509Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.DataFrame(os.listdir(path_train_orig)).T","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:50:42.699133Z","iopub.execute_input":"2022-07-21T03:50:42.699384Z","iopub.status.idle":"2022-07-21T03:50:42.729527Z","shell.execute_reply.started":"2022-07-21T03:50:42.699352Z","shell.execute_reply":"2022-07-21T03:50:42.728624Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# make dataset\ndata=[]\nfor categories in os.listdir(path_train_orig):\n    for img in os.listdir(path_train_orig+categories):\n        data.append((path_train_orig+categories+'/'+img, categories, img))\n                    \ndf_train=pd.DataFrame(data, columns=['data_path', 'class', 'imagen' ])\ndf_train.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:50:42.730918Z","iopub.execute_input":"2022-07-21T03:50:42.731221Z","iopub.status.idle":"2022-07-21T03:50:44.111456Z","shell.execute_reply.started":"2022-07-21T03:50:42.731168Z","shell.execute_reply":"2022-07-21T03:50:44.110679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# value count of class\ndf_train['class'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:50:44.112872Z","iopub.execute_input":"2022-07-21T03:50:44.113305Z","iopub.status.idle":"2022-07-21T03:50:44.127579Z","shell.execute_reply.started":"2022-07-21T03:50:44.113265Z","shell.execute_reply":"2022-07-21T03:50:44.126538Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"categories = df_train['class'].unique()\ncategories ","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:50:44.128969Z","iopub.execute_input":"2022-07-21T03:50:44.129272Z","iopub.status.idle":"2022-07-21T03:50:44.14491Z","shell.execute_reply.started":"2022-07-21T03:50:44.129237Z","shell.execute_reply":"2022-07-21T03:50:44.143952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Convolutional Neural Network (CNN)","metadata":{}},{"cell_type":"code","source":"# epochs\nepochs_val = 100\n\n# batch_size\nbatch_size_val = 16\n\n# target_size\n#224\ntarget_size_val=(224,224)\n\n# input_shape\ninput_shape_val = (target_size_val[0],target_size_val[1], 3)","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:50:44.146831Z","iopub.execute_input":"2022-07-21T03:50:44.147096Z","iopub.status.idle":"2022-07-21T03:50:44.152974Z","shell.execute_reply.started":"2022-07-21T03:50:44.14706Z","shell.execute_reply":"2022-07-21T03:50:44.151935Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Data Generators","metadata":{}},{"cell_type":"code","source":"# Datagen and augmentation\ntrain_datagen = ImageDataGenerator(\n    rescale=1./255,\n    rotation_range=10,\n    width_shift_range=0.2,\n    height_shift_range=0.2,\n    shear_range=0.2,\n    zoom_range=0.2,\n    horizontal_flip=True,\n    preprocessing_function=None,\n    validation_split= 0.3)\n\ntest_datagen = ImageDataGenerator(rescale=1./255)","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:50:44.154472Z","iopub.execute_input":"2022-07-21T03:50:44.154811Z","iopub.status.idle":"2022-07-21T03:50:44.164334Z","shell.execute_reply.started":"2022-07-21T03:50:44.154773Z","shell.execute_reply":"2022-07-21T03:50:44.163543Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Train / Validation - Data Generator\ntrain_generator = train_datagen.flow_from_directory(path_train_orig,\n                                 target_size=target_size_val,\n                                 batch_size=batch_size_val,\n                                 class_mode = 'categorical',\n                                 subset = \"training\")\n\nval_generator = train_datagen.flow_from_directory(path_train_orig,\n                                 target_size=target_size_val,\n                                 batch_size=batch_size_val,\n                                 class_mode = 'categorical',\n                                 subset = \"validation\")\n\n# Test \ntest_generator = test_datagen.flow_from_directory(path_test,\n                                 target_size=target_size_val,\n                                 shuffle = False)","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:50:44.165657Z","iopub.execute_input":"2022-07-21T03:50:44.166044Z","iopub.status.idle":"2022-07-21T03:51:00.668821Z","shell.execute_reply.started":"2022-07-21T03:50:44.165952Z","shell.execute_reply":"2022-07-21T03:51:00.668012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# class_weight - Unbalanced Data\n\ncounter = Counter(train_generator.classes)                          \nclass_weights = dict(zip(list(counter.keys()),\n                 class_weight.compute_class_weight('balanced', list(counter.keys()),train_generator.classes)))\nclass_weights","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:51:00.672829Z","iopub.execute_input":"2022-07-21T03:51:00.67312Z","iopub.status.idle":"2022-07-21T03:51:01.107651Z","shell.execute_reply.started":"2022-07-21T03:51:00.673081Z","shell.execute_reply":"2022-07-21T03:51:01.105809Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_generator.classes","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:51:01.108473Z","iopub.status.idle":"2022-07-21T03:51:01.108768Z","shell.execute_reply.started":"2022-07-21T03:51:01.108618Z","shell.execute_reply":"2022-07-21T03:51:01.108639Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_generator.class_indices","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2022-07-21T03:51:01.109951Z","iopub.status.idle":"2022-07-21T03:51:01.110356Z","shell.execute_reply.started":"2022-07-21T03:51:01.110129Z","shell.execute_reply":"2022-07-21T03:51:01.110149Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_generator_dict={y: x for x, y in train_generator.class_indices.items()}\ntrain_generator_dict","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:51:01.111281Z","iopub.status.idle":"2022-07-21T03:51:01.111645Z","shell.execute_reply.started":"2022-07-21T03:51:01.111437Z","shell.execute_reply":"2022-07-21T03:51:01.111458Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# plot image of train_generator_image\n\ntrain_datagen_image = ImageDataGenerator(rescale=1./255)\n\ntrain_generator_image = train_datagen.flow_from_directory(path_train_orig,\n                                 target_size=target_size_val,\n                                 batch_size=100)\nplt.figure(figsize = (19, 8))\nimage_train_gen, cl = next(train_generator_image) # len(next(train_generator)) = batch_size\nfor i in range(18):\n    ax=plt.subplot(3,6,i+1)\n    im = image_train_gen[i]\n    plt.imshow(im)\n    plt.title(train_generator_dict[np.where(cl[i]==1)[0][0]],fontsize=16)\n    plt.axis('off')","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:51:01.11277Z","iopub.status.idle":"2022-07-21T03:51:01.113274Z","shell.execute_reply.started":"2022-07-21T03:51:01.112977Z","shell.execute_reply":"2022-07-21T03:51:01.113012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#module_url = \"https://tfhub.dev/google/imagenet/mobilenet_v1_050_160/classification/4\"\nmodule_url = \"https://tfhub.dev/google/bit/m-r50x1/1\"\n\nmodel_hub = tf.keras.Sequential([\n                                 tf.keras.layers.InputLayer(input_shape=input_shape_val),\n                                 hub.KerasLayer(module_url, trainable=False),\n                                 tf.keras.layers.Flatten(),\n                                 tf.keras.layers.Dense(1024, activation =\"relu\"),\n                                 tf.keras.layers.Dropout(rate=0.5),\n                                 tf.keras.layers.Dense(len(train_generator.class_indices), activation = \"softmax\")\n])\n\nmodel_hub.build((None, input_shape_val))\n# name\nmodel_hub._name = \"model_m-r50x1\"\nmodel_hub.summary()","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:51:01.114423Z","iopub.status.idle":"2022-07-21T03:51:01.114824Z","shell.execute_reply.started":"2022-07-21T03:51:01.114601Z","shell.execute_reply":"2022-07-21T03:51:01.114623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_model_output(history, name='model'):\n    \n    history_dict = history.history\n    loss_values = history_dict['loss']\n    val_loss_values = history_dict['val_loss']\n    accuracy_values = history_dict['accuracy']\n    val_accuracy_values = history_dict['val_accuracy']\n    \n    fig = plt.figure(figsize=(19,3))\n    \n    plt.subplot(1, 2, 1)\n    plt.suptitle(name, fontsize=18)\n    plt.title('loss')\n    epoch = range(1,len(loss_values)+1)\n    plt.plot(epoch,loss_values, '--',label='loss')\n    plt.plot(epoch,val_loss_values, '--',label='val_loss')\n    plt.legend()\n    plt.xlabel('epoch')\n    plt.ylabel('loss')\n    \n    plt.subplot(1, 2, 2)\n    plt.suptitle(name, fontsize=18)\n    plt.title('accuracy')\n    epoch = range(1,len(loss_values)+1)\n    plt.plot(epoch,accuracy_values, '--',label='accuracy')\n    plt.plot(epoch,val_accuracy_values, '--',label='val_accuracy')\n    plt.legend()\n    plt.xlabel('epoch')\n    plt.ylabel('accuracy')\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:51:01.116256Z","iopub.status.idle":"2022-07-21T03:51:01.116872Z","shell.execute_reply.started":"2022-07-21T03:51:01.11663Z","shell.execute_reply":"2022-07-21T03:51:01.116655Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"if os.path.exists('models/'):\n    pass\nelse:\n    os.makedirs('models/')","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:51:01.118885Z","iopub.status.idle":"2022-07-21T03:51:01.119755Z","shell.execute_reply.started":"2022-07-21T03:51:01.119521Z","shell.execute_reply":"2022-07-21T03:51:01.119546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Define optimizer\noptimizer = optimizers.Nadam(lr=0.001, beta_1=0.9, beta_2=0.999)","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:51:01.120814Z","iopub.status.idle":"2022-07-21T03:51:01.121833Z","shell.execute_reply.started":"2022-07-21T03:51:01.121559Z","shell.execute_reply":"2022-07-21T03:51:01.121588Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# callbacks\nearly_stopping = tf.keras.callbacks.EarlyStopping(monitor='val_loss',patience=20)\nrlr = tf.keras.callbacks.ReduceLROnPlateau(monitor='val_loss',patience=8) ","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:51:01.123026Z","iopub.status.idle":"2022-07-21T03:51:01.12404Z","shell.execute_reply.started":"2022-07-21T03:51:01.123807Z","shell.execute_reply":"2022-07-21T03:51:01.123832Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# run models fuction\n\nfilepath=os.getcwd()+'/models/'\ndef run_model(model):\n    \n    # save best model (callback)\n    modelCheckpoint = ModelCheckpoint(filepath+'{}.h5'.format(model.name), save_best_only = True)\n    \n    # Compile the model\n    model.compile(optimizer = optimizer , loss = 'categorical_crossentropy', metrics=[\"accuracy\"])\n    \n    # Fit the model\n    history = model.fit_generator(generator=train_generator,\n                              epochs = epochs_val,\n                              steps_per_epoch=300,\n                              validation_steps = 150,\n                              callbacks=[early_stopping, rlr, modelCheckpoint],\n                              class_weight=class_weights,\n                              validation_data = val_generator)\n    \n    print(history.history.keys())\n    \n    return model, history","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:51:01.125127Z","iopub.status.idle":"2022-07-21T03:51:01.125988Z","shell.execute_reply.started":"2022-07-21T03:51:01.125757Z","shell.execute_reply":"2022-07-21T03:51:01.125782Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"max_accuracy=[]","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:51:01.127055Z","iopub.status.idle":"2022-07-21T03:51:01.127918Z","shell.execute_reply.started":"2022-07-21T03:51:01.127688Z","shell.execute_reply":"2022-07-21T03:51:01.127712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Run model \n#tf.keras.backend.clear_session()\nmodel_mr50x1, history_mr50x1 = run_model(model_hub)\nmax_accuracy.append(('{}.h5'.format(model_hub.name),np.max(history_mr50x1.history['accuracy'])))","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:51:01.129134Z","iopub.status.idle":"2022-07-21T03:51:01.13016Z","shell.execute_reply.started":"2022-07-21T03:51:01.129877Z","shell.execute_reply":"2022-07-21T03:51:01.129904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"max_accuracy.append(('{}.h5'.format(model_hub.name),np.max(history_mr50x1.history['accuracy'])))","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:51:01.131384Z","iopub.status.idle":"2022-07-21T03:51:01.132268Z","shell.execute_reply.started":"2022-07-21T03:51:01.132015Z","shell.execute_reply":"2022-07-21T03:51:01.13204Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# plot model ouputs\nplot_model_output(history_mr50x1, 'model_m-r50x1')","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:51:01.133456Z","iopub.status.idle":"2022-07-21T03:51:01.134385Z","shell.execute_reply.started":"2022-07-21T03:51:01.134133Z","shell.execute_reply":"2022-07-21T03:51:01.134158Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# load best model\nload_model = tf.keras.models.load_model('models/model_m-r50x1.h5',custom_objects={'KerasLayer':hub.KerasLayer})\nload_model","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:51:01.135454Z","iopub.status.idle":"2022-07-21T03:51:01.136337Z","shell.execute_reply.started":"2022-07-21T03:51:01.136083Z","shell.execute_reply":"2022-07-21T03:51:01.136107Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filenames = test_generator.filenames\nfilenames[0:3]","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:51:01.137386Z","iopub.status.idle":"2022-07-21T03:51:01.138267Z","shell.execute_reply.started":"2022-07-21T03:51:01.138017Z","shell.execute_reply":"2022-07-21T03:51:01.138041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions = load_model.predict(test_generator)","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:51:01.139334Z","iopub.status.idle":"2022-07-21T03:51:01.141029Z","shell.execute_reply.started":"2022-07-21T03:51:01.140787Z","shell.execute_reply":"2022-07-21T03:51:01.140812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions[0]","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:51:01.142118Z","iopub.status.idle":"2022-07-21T03:51:01.142877Z","shell.execute_reply.started":"2022-07-21T03:51:01.142607Z","shell.execute_reply":"2022-07-21T03:51:01.142636Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_generator_dict[8]","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:51:01.144467Z","iopub.status.idle":"2022-07-21T03:51:01.145124Z","shell.execute_reply.started":"2022-07-21T03:51:01.144889Z","shell.execute_reply":"2022-07-21T03:51:01.144914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred_class_name=[]\nfor i in range(len(predictions)):\n    pred=np.argmax(predictions[i])\n    pred_class_name.append(train_generator_dict[pred])\n    \npred_class_name[0:3]","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:51:01.146338Z","iopub.status.idle":"2022-07-21T03:51:01.146966Z","shell.execute_reply.started":"2022-07-21T03:51:01.14673Z","shell.execute_reply":"2022-07-21T03:51:01.146754Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### submission","metadata":{}},{"cell_type":"code","source":"submission_df=pd.DataFrame(pred_class_name, test_generator.filenames).reset_index()\nsubmission_df.columns=['Id','Category']\nsubmission_df['Id']=submission_df['Id'].apply(lambda x: x.split('/')[1])\nsubmission_df.head(3)","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:51:01.148157Z","iopub.status.idle":"2022-07-21T03:51:01.148817Z","shell.execute_reply.started":"2022-07-21T03:51:01.148582Z","shell.execute_reply":"2022-07-21T03:51:01.148607Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df['Category'].to_csv('submission.csv',index=True, header=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-21T03:51:01.14999Z","iopub.status.idle":"2022-07-21T03:51:01.150625Z","shell.execute_reply.started":"2022-07-21T03:51:01.150379Z","shell.execute_reply":"2022-07-21T03:51:01.150402Z"},"trusted":true},"execution_count":null,"outputs":[]}]}