{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":5441,"databundleVersionId":38425,"sourceType":"competition"}],"dockerImageVersionId":30699,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Preprocessing","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n\nimport os\nimport cv2\nimport glob as gb\nfrom PIL import Image\n\nimport tensorflow as tf\nfrom tensorflow import keras\nfrom tensorflow.keras import layers\n\nfrom keras.applications import MobileNetV2\n\nfrom keras.callbacks import EarlyStopping\nfrom sklearn.model_selection import train_test_split\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom sklearn.metrics import classification_report, confusion_matrix","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-05-22T15:18:20.926722Z","iopub.execute_input":"2024-05-22T15:18:20.927628Z","iopub.status.idle":"2024-05-22T15:18:20.933834Z","shell.execute_reply.started":"2024-05-22T15:18:20.927595Z","shell.execute_reply":"2024-05-22T15:18:20.932832Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Extracting the Compressed Datasets \n\nfrom zipfile import ZipFile \n\ntrain_folder  = '/kaggle/input/dogs-vs-cats-redux-kernels-edition/train.zip'\n           \nwith ZipFile(train_folder,'r') as zip :\n    zip.extractall(path = '/kaggle/working/')\n    print('The train_folder is extracted')","metadata":{"execution":{"iopub.status.busy":"2024-05-22T14:16:53.917556Z","iopub.execute_input":"2024-05-22T14:16:53.918915Z","iopub.status.idle":"2024-05-22T14:17:04.271524Z","shell.execute_reply.started":"2024-05-22T14:16:53.918869Z","shell.execute_reply":"2024-05-22T14:17:04.270528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_path, train_dirs, train_files = next(os.walk('/kaggle/working/train'))\nprint('Number of images in train is :',len(train_files))","metadata":{"execution":{"iopub.status.busy":"2024-05-22T14:17:08.594865Z","iopub.execute_input":"2024-05-22T14:17:08.595232Z","iopub.status.idle":"2024-05-22T14:17:08.635364Z","shell.execute_reply.started":"2024-05-22T14:17:08.595205Z","shell.execute_reply":"2024-05-22T14:17:08.634386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_files[0:5]","metadata":{"execution":{"iopub.status.busy":"2024-05-22T14:17:12.402314Z","iopub.execute_input":"2024-05-22T14:17:12.402659Z","iopub.status.idle":"2024-05-22T14:17:12.410025Z","shell.execute_reply.started":"2024-05-22T14:17:12.402632Z","shell.execute_reply":"2024-05-22T14:17:12.409050Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Check the balance of the training data\n\ncategories=[]\nfor img in train_files :\n    category=img.split('.')[0]\n    if category=='dog':\n        categories.append('dog')\n    else :\n        categories.append('cat')\n        \ndf=pd.DataFrame({'Image':train_files,'Category':categories})\n\ndf","metadata":{"execution":{"iopub.status.busy":"2024-05-22T14:17:17.482187Z","iopub.execute_input":"2024-05-22T14:17:17.482542Z","iopub.status.idle":"2024-05-22T14:17:17.521636Z","shell.execute_reply.started":"2024-05-22T14:17:17.482514Z","shell.execute_reply":"2024-05-22T14:17:17.520769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualizations","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(5,5))\nsns.countplot(data=df,x='Category');","metadata":{"execution":{"iopub.status.busy":"2024-05-22T14:17:54.809647Z","iopub.execute_input":"2024-05-22T14:17:54.810463Z","iopub.status.idle":"2024-05-22T14:17:55.009052Z","shell.execute_reply.started":"2024-05-22T14:17:54.810430Z","shell.execute_reply":"2024-05-22T14:17:55.008091Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = plt.figure(figsize=(10,10))\nfig.suptitle(\"Some examples of images\", fontsize=10)\nfor i in range(16):\n        plt.subplot(4,4,i+1)\n        plt.xticks([])\n        plt.yticks([])\n        plt.grid(False)\n        plt.imshow(plt.imread('/kaggle/working/train/'+train_files[i]))\n        plt.xlabel(categories[i])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-05-22T14:17:59.079877Z","iopub.execute_input":"2024-05-22T14:17:59.080198Z","iopub.status.idle":"2024-05-22T14:18:00.330681Z","shell.execute_reply.started":"2024-05-22T14:17:59.080174Z","shell.execute_reply":"2024-05-22T14:18:00.329712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#plot random image from the training set\nsample=np.random.choice(train_files)\nplt.imshow(plt.imread('/kaggle/working/train/'+sample))\n","metadata":{"execution":{"iopub.status.busy":"2024-05-22T14:18:07.514044Z","iopub.execute_input":"2024-05-22T14:18:07.514799Z","iopub.status.idle":"2024-05-22T14:18:07.835094Z","shell.execute_reply.started":"2024-05-22T14:18:07.514766Z","shell.execute_reply":"2024-05-22T14:18:07.834131Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Splitting the data \ntrain,validation =train_test_split(df,test_size=0.2,random_state=42)\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2024-05-22T14:18:11.766816Z","iopub.execute_input":"2024-05-22T14:18:11.767141Z","iopub.status.idle":"2024-05-22T14:18:11.781715Z","shell.execute_reply.started":"2024-05-22T14:18:11.767117Z","shell.execute_reply":"2024-05-22T14:18:11.780813Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Rename the index of train and test\ntrain = train.reset_index(drop=True)\nvalidation  = validation.reset_index(drop=True)\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2024-05-22T14:18:14.124361Z","iopub.execute_input":"2024-05-22T14:18:14.125293Z","iopub.status.idle":"2024-05-22T14:18:14.136159Z","shell.execute_reply.started":"2024-05-22T14:18:14.125261Z","shell.execute_reply":"2024-05-22T14:18:14.135052Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Prepare Generator","metadata":{}},{"cell_type":"code","source":"# Data augmentation for training\n\ntrain_datagen = ImageDataGenerator(\n    \n    rescale=1.0/255,                                     # Rescale pixel values to [0, 1]\n    rotation_range=20,                                   # Random rotation within 20 degrees\n    width_shift_range=0.2,                               # Random horizontal shift by 20% of image width\n    height_shift_range=0.2,                              # Random vertical shift by 20% of image height\n    horizontal_flip=True,                                # Random horizontal flipping\n    fill_mode='nearest'                                  # Fill mode for new pixels after shifts/rotations\n)\n\n\ntrain_generator = train_datagen.flow_from_dataframe(\n                                            \n     train,                                              # dataframe\n     directory=\"/kaggle/working/train\",    \n     x_col='Image',\n     y_col='Category',\n     target_size=(224, 224),                             # Resize images to this size\n     batch_size=32,                                      # Number of images in each batch\n     seed=42,                                            # Optional: Set a random seed for shuffling\n     class_mode='categorical',                           # Mode for class labels (categorical for one-hot encoding)\n) ","metadata":{"execution":{"iopub.status.busy":"2024-05-22T14:18:21.634702Z","iopub.execute_input":"2024-05-22T14:18:21.635437Z","iopub.status.idle":"2024-05-22T14:18:21.879508Z","shell.execute_reply.started":"2024-05-22T14:18:21.635405Z","shell.execute_reply":"2024-05-22T14:18:21.878622Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Data augmentation for testing\n\nvalidation_datagen  = ImageDataGenerator( rescale = 1.0/255.)    # Rescale pixel values to [0, 1]\n\nvalidation_generator = validation_datagen.flow_from_dataframe(\n    \n     validation,\n     directory=\"/kaggle/working/train\",\n     x_col='Image',\n     y_col='Category',\n     target_size = (224, 224),\n     batch_size=32,\n     class_mode  = 'categorical',\n     shuffle = False                      #shuffle=False to keep the order of image labels matching the generator & \n                                                                         #get good results in Confusion_Matrix  \n)","metadata":{"execution":{"iopub.status.busy":"2024-05-22T14:18:27.423046Z","iopub.execute_input":"2024-05-22T14:18:27.423725Z","iopub.status.idle":"2024-05-22T14:18:27.493594Z","shell.execute_reply.started":"2024-05-22T14:18:27.423696Z","shell.execute_reply":"2024-05-22T14:18:27.492855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# show augmentation\n\nplt.figure(figsize=(10, 10))\nfor i in range(0, 15):\n    plt.subplot(5, 3, i+1)\n    for img, label in train_generator:\n        image = img[0]\n        plt.imshow(image)\n        break\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-05-22T14:18:59.365407Z","iopub.execute_input":"2024-05-22T14:18:59.366060Z","iopub.status.idle":"2024-05-22T14:19:07.002572Z","shell.execute_reply.started":"2024-05-22T14:18:59.366027Z","shell.execute_reply":"2024-05-22T14:19:07.001618Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Transfer Learning Model","metadata":{}},{"cell_type":"code","source":"MobileNetV2_model = MobileNetV2(\n                                     input_shape=(224,224,3),\n                                     weights='imagenet',\n                                     include_top=False\n                                     )\nMobileNetV2_model.trainable = False","metadata":{"execution":{"iopub.status.busy":"2024-05-22T14:19:14.992504Z","iopub.execute_input":"2024-05-22T14:19:14.993199Z","iopub.status.idle":"2024-05-22T14:19:16.973550Z","shell.execute_reply.started":"2024-05-22T14:19:14.993167Z","shell.execute_reply":"2024-05-22T14:19:16.972793Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = tf.keras.models.Sequential([\n    \n    MobileNetV2_model,\n    \n    keras.layers.Flatten(),\n    \n    keras.layers.Dense(256,activation='relu'),\n    keras.layers.Dropout(0.5),\n    keras.layers.Dense(2,activation='softmax'),\n])\n","metadata":{"execution":{"iopub.status.busy":"2024-05-22T14:19:23.875012Z","iopub.execute_input":"2024-05-22T14:19:23.875684Z","iopub.status.idle":"2024-05-22T14:19:23.888946Z","shell.execute_reply.started":"2024-05-22T14:19:23.875650Z","shell.execute_reply":"2024-05-22T14:19:23.887959Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(loss='binary_crossentropy',\n              optimizer=tf.keras.optimizers.Adam(learning_rate=0.0001),\n              metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2024-05-22T14:20:33.204323Z","iopub.execute_input":"2024-05-22T14:20:33.204684Z","iopub.status.idle":"2024-05-22T14:20:33.214472Z","shell.execute_reply.started":"2024-05-22T14:20:33.204656Z","shell.execute_reply":"2024-05-22T14:20:33.213562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"early_stopping = tf.keras.callbacks.EarlyStopping(monitor='val_accuracy', patience=15)","metadata":{"execution":{"iopub.status.busy":"2024-05-22T14:47:23.260144Z","iopub.execute_input":"2024-05-22T14:47:23.260534Z","iopub.status.idle":"2024-05-22T14:47:23.265062Z","shell.execute_reply.started":"2024-05-22T14:47:23.260504Z","shell.execute_reply":"2024-05-22T14:47:23.264196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"batch_size = 64\n\nhistory = model.fit(\n                    train_generator,\n                    steps_per_epoch  = train_generator.samples // batch_size,\n                    validation_data  = validation_generator,\n                    validation_steps = validation_generator.samples // batch_size,\n                    callbacks=[early_stopping], verbose=1,\n                    epochs = 20\n    )","metadata":{"execution":{"iopub.status.busy":"2024-05-22T14:47:27.092605Z","iopub.execute_input":"2024-05-22T14:47:27.093523Z","iopub.status.idle":"2024-05-22T15:09:51.184274Z","shell.execute_reply.started":"2024-05-22T14:47:27.093487Z","shell.execute_reply":"2024-05-22T15:09:51.182959Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2024-05-22T15:10:02.318002Z","iopub.execute_input":"2024-05-22T15:10:02.318854Z","iopub.status.idle":"2024-05-22T15:10:02.347490Z","shell.execute_reply.started":"2024-05-22T15:10:02.318822Z","shell.execute_reply":"2024-05-22T15:10:02.346559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Save the Model for future use\nfor i in range(len(model.weights)):\n    model.weights[i]._handle_name = model.weights[i].name + \"_\" + str(i)\n    ","metadata":{"execution":{"iopub.status.busy":"2024-05-22T15:12:22.185203Z","iopub.execute_input":"2024-05-22T15:12:22.186061Z","iopub.status.idle":"2024-05-22T15:12:22.453591Z","shell.execute_reply.started":"2024-05-22T15:12:22.186027Z","shell.execute_reply":"2024-05-22T15:12:22.452675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Evaluation","metadata":{}},{"cell_type":"code","source":" plt.figure(1, figsize = (15,8)) \n    \nplt.subplot(221)  \nplt.plot(history.history['accuracy'],'b')  \nplt.plot(history.history['val_accuracy'],'r')  \nplt.title('model accuracy')  \nplt.ylabel('accuracy')  \nplt.xlabel('epoch')  \nplt.legend(['train', 'valid']) \n    \nplt.subplot(222)  \nplt.plot(history.history['loss'],'b')  \nplt.plot(history.history['val_loss'],'r')  \nplt.title('model loss')  \nplt.ylabel('loss')  \nplt.xlabel('epoch')  \nplt.legend(['train', 'valid']) \n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-05-22T15:15:22.297713Z","iopub.execute_input":"2024-05-22T15:15:22.298716Z","iopub.status.idle":"2024-05-22T15:15:22.918831Z","shell.execute_reply.started":"2024-05-22T15:15:22.298674Z","shell.execute_reply":"2024-05-22T15:15:22.917858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Evaluate on validation dataset\nscore = model.evaluate(validation_generator ,verbose=False)\nprint('Test loss:', score[0])\nprint('Test accuracy:', score[1])","metadata":{"execution":{"iopub.status.busy":"2024-05-22T15:15:34.927137Z","iopub.execute_input":"2024-05-22T15:15:34.927539Z","iopub.status.idle":"2024-05-22T15:15:44.710882Z","shell.execute_reply.started":"2024-05-22T15:15:34.927507Z","shell.execute_reply":"2024-05-22T15:15:44.709893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Make predictions on the validation data\npredictions = model.predict(validation_generator)\n\n# Convert probabilities to class labels\npredicted_labels = np.argmax(predictions, axis=1)\n\n\n# Get true labels from the validation_generator\ntrue_labels = validation_generator.classes\n\nlabels =['Cat','Dog']\n\nprint(classification_report(true_labels,predicted_labels,target_names=labels))\n","metadata":{"execution":{"iopub.status.busy":"2024-05-22T15:15:50.097584Z","iopub.execute_input":"2024-05-22T15:15:50.098487Z","iopub.status.idle":"2024-05-22T15:16:05.831983Z","shell.execute_reply.started":"2024-05-22T15:15:50.098453Z","shell.execute_reply":"2024-05-22T15:16:05.831053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"confusion_mtx = confusion_matrix(true_labels,predicted_labels) \n\nf,ax = plt.subplots(figsize = (8,4),dpi=100)\nsns.heatmap(confusion_mtx, annot=True, linewidths=0.1,\n            cmap = \"gist_yarg_r\", linecolor=\"black\",\n            fmt='.0f', ax=ax,cbar=False,\n            xticklabels=labels, yticklabels=labels)\n\nplt.xlabel(\"Predicted Label\",fontsize=10)\nplt.ylabel(\"True Label\",fontsize=10)\nplt.title(\"Confusion Matrix\",fontsize=13)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-05-22T15:16:16.139038Z","iopub.execute_input":"2024-05-22T15:16:16.139669Z","iopub.status.idle":"2024-05-22T15:16:16.287983Z","shell.execute_reply.started":"2024-05-22T15:16:16.139639Z","shell.execute_reply":"2024-05-22T15:16:16.286663Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Collect true labels and model predictions\ntrue_labels = []\npredicted_labels = []\nclass_names = validation_generator.class_indices.keys()    \nclass_names = list(class_names)\nnum_batches = len(validation_generator)                         # num_batches = 157  each batch is 32\n\nfor i in range(20):\n    x_batch,y_batch = validation_generator[i]\n    predictions = model.predict(x_batch)\n    true_labels.extend(np.argmax(y_batch, axis=1))              # Convert one-hot encoded labels to class indices\n    predicted_labels.extend(np.argmax(predictions, axis=1))\n\n\ntrue_class_labels = [class_names[i] for i in true_labels]\npredicted_class_labels = [class_names[i] for i in predicted_labels]\n\n# Plot true labels and predicted labels\nplt.figure(figsize=(10, 5))\nfor i in range(10):\n    plt.subplot(2,5, i + 1)\n    plt.imshow(x_batch[i])\n    plt.title(f'True: {true_class_labels[i]}\\nPredicted: {predicted_class_labels[i]}', fontsize=8)\n    plt.axis('off')\n\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-05-22T15:16:22.165640Z","iopub.execute_input":"2024-05-22T15:16:22.166265Z","iopub.status.idle":"2024-05-22T15:16:29.288345Z","shell.execute_reply.started":"2024-05-22T15:16:22.166234Z","shell.execute_reply":"2024-05-22T15:16:29.287429Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":" # Predict Test Data","metadata":{}},{"cell_type":"code","source":"test_folder  = '/kaggle/input/dogs-vs-cats-redux-kernels-edition/test.zip'\n           \nwith ZipFile(test_folder,'r') as zip :\n    zip.extractall(path = \"/kaggle/working/\")\n    print('The test_folder is extracted')\n    \ntest_path,  test_dirs,  test_files  = next(os.walk('/kaggle/working/test'))\nprint('Number of images in test is :',len(test_files))","metadata":{"execution":{"iopub.status.busy":"2024-05-22T15:16:39.351126Z","iopub.execute_input":"2024-05-22T15:16:39.351760Z","iopub.status.idle":"2024-05-22T15:16:44.503870Z","shell.execute_reply.started":"2024-05-22T15:16:39.351713Z","shell.execute_reply":"2024-05-22T15:16:44.502891Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data = pd.DataFrame({\"filename\": test_files})\ntest_data['label'] = 'unknown'\ntest_data","metadata":{"execution":{"iopub.status.busy":"2024-05-22T15:16:56.511616Z","iopub.execute_input":"2024-05-22T15:16:56.512426Z","iopub.status.idle":"2024-05-22T15:16:56.525229Z","shell.execute_reply.started":"2024-05-22T15:16:56.512393Z","shell.execute_reply":"2024-05-22T15:16:56.524244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Create data genenerator for test data\ntest_generator =  validation_datagen.flow_from_dataframe(test_data, \n                                     \"/kaggle/working/test\", \n                                     x_col= \"filename\",\n                                     y_col= 'label',\n                                     target_size=(224,224),\n                                     batch_size=32,\n                                     shuffle=False)","metadata":{"execution":{"iopub.status.busy":"2024-05-22T15:16:58.572094Z","iopub.execute_input":"2024-05-22T15:16:58.572932Z","iopub.status.idle":"2024-05-22T15:16:58.727252Z","shell.execute_reply.started":"2024-05-22T15:16:58.572892Z","shell.execute_reply":"2024-05-22T15:16:58.726535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Test Prediction\ntest_prediction = model.predict(test_generator,verbose = 0)\n\ntest_prediction_argmax = np.argmax(test_prediction, axis=1)\n\ny_test_pred = test_prediction_argmax\n\ntest_data['label'] = y_test_pred\n\n# mapping\nlabel_mapping = {0: 'cat', 1: 'dog'}\ntest_data['label'] = test_data['label'].map(label_mapping)\ntest_data.head(10)","metadata":{"execution":{"iopub.status.busy":"2024-05-22T15:17:01.418066Z","iopub.execute_input":"2024-05-22T15:17:01.418705Z","iopub.status.idle":"2024-05-22T15:17:33.125009Z","shell.execute_reply.started":"2024-05-22T15:17:01.418677Z","shell.execute_reply":"2024-05-22T15:17:33.123885Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(20,20))\nfor n , i in enumerate(list(np.random.randint(0,len(test_files),36))) : \n    plt.subplot(6,6,n+1)\n    image_path = os.path.join(test_path, test_data.iloc[i]['filename'])\n    image = Image.open(image_path)\n    plt.imshow(image)\n    plt.title(\"Label: \" + test_data.iloc[i]['label'])\n    plt.axis('off')\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2024-05-22T15:18:31.387653Z","iopub.execute_input":"2024-05-22T15:18:31.388007Z","iopub.status.idle":"2024-05-22T15:18:35.473338Z","shell.execute_reply.started":"2024-05-22T15:18:31.387980Z","shell.execute_reply":"2024-05-22T15:18:35.471987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Submission","metadata":{}},{"cell_type":"code","source":"# csv file output for submission\nsubmission = pd.read_csv('/kaggle/input/dogs-vs-cats-redux-kernels-edition/sample_submission.csv',index_col='id')\n\nsubmission['label'] = y_test_pred\n\nsubmission.to_csv('submission.csv',index=True)","metadata":{"execution":{"iopub.status.busy":"2024-05-22T15:18:51.400512Z","iopub.execute_input":"2024-05-22T15:18:51.401320Z","iopub.status.idle":"2024-05-22T15:18:51.435974Z","shell.execute_reply.started":"2024-05-22T15:18:51.401288Z","shell.execute_reply":"2024-05-22T15:18:51.435226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission","metadata":{"execution":{"iopub.status.busy":"2024-05-22T15:18:53.792898Z","iopub.execute_input":"2024-05-22T15:18:53.793773Z","iopub.status.idle":"2024-05-22T15:18:53.803218Z","shell.execute_reply.started":"2024-05-22T15:18:53.793731Z","shell.execute_reply":"2024-05-22T15:18:53.802183Z"},"trusted":true},"execution_count":null,"outputs":[]}]}