{"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":"none","dataSources":[{"sourceId":3362,"databundleVersionId":31148,"sourceType":"competition"}],"dockerImageVersionId":30673,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Applying CNN on Cats vs Dogs Datasets\n","metadata":{}},{"cell_type":"code","source":"\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport zipfile \nimport os\nimport shutil\nimport random\nimport tensorflow as tf\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nimport matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2024-04-01T21:14:14.389394Z","iopub.execute_input":"2024-04-01T21:14:14.389816Z","iopub.status.idle":"2024-04-01T21:14:14.395695Z","shell.execute_reply.started":"2024-04-01T21:14:14.389773Z","shell.execute_reply":"2024-04-01T21:14:14.394350Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"zip_ref = zipfile.ZipFile('/kaggle/input/dogs-vs-cats/train.zip','r')\nzip_ref.extractall()\nzip_ref.close()","metadata":{"execution":{"iopub.status.busy":"2024-04-01T21:14:14.984194Z","iopub.execute_input":"2024-04-01T21:14:14.984621Z","iopub.status.idle":"2024-04-01T21:14:27.174535Z","shell.execute_reply.started":"2024-04-01T21:14:14.984592Z","shell.execute_reply":"2024-04-01T21:14:27.173392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(os.listdir('/kaggle/working/train')[:10])","metadata":{"execution":{"iopub.status.busy":"2024-04-01T21:14:51.056525Z","iopub.execute_input":"2024-04-01T21:14:51.056942Z","iopub.status.idle":"2024-04-01T21:14:51.077504Z","shell.execute_reply.started":"2024-04-01T21:14:51.056911Z","shell.execute_reply":"2024-04-01T21:14:51.076272Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\n\nbase_dir = \"/kaggle/working/dogs_vs_cats_dataset\"\nos.mkdir(base_dir)","metadata":{"execution":{"iopub.status.busy":"2024-04-01T21:14:51.537443Z","iopub.execute_input":"2024-04-01T21:14:51.537821Z","iopub.status.idle":"2024-04-01T21:14:51.543146Z","shell.execute_reply.started":"2024-04-01T21:14:51.537776Z","shell.execute_reply":"2024-04-01T21:14:51.542318Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dogs_data = os.path.join(base_dir, 'dogs')\ncats_data = os.path.join(base_dir, 'cats')\n\nos.mkdir(dogs_data)\nos.mkdir(cats_data)","metadata":{"execution":{"iopub.status.busy":"2024-04-01T21:14:51.931964Z","iopub.execute_input":"2024-04-01T21:14:51.933047Z","iopub.status.idle":"2024-04-01T21:14:51.939487Z","shell.execute_reply.started":"2024-04-01T21:14:51.933012Z","shell.execute_reply":"2024-04-01T21:14:51.938124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ntrain_dir = os.path.join(base_dir, 'train_data')\nvalidate_dir = os.path.join(base_dir, 'val')\n\n\nos.mkdir(train_dir)\nos.mkdir(validate_dir)","metadata":{"execution":{"iopub.status.busy":"2024-04-01T21:14:52.363576Z","iopub.execute_input":"2024-04-01T21:14:52.364035Z","iopub.status.idle":"2024-04-01T21:14:52.369500Z","shell.execute_reply.started":"2024-04-01T21:14:52.364002Z","shell.execute_reply":"2024-04-01T21:14:52.368301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_cats_dir = os.path.join(train_dir, 'cats')\ntrain_dogs_dir = os.path.join(train_dir, 'dogs')\n\n\nval_dog_dir = os.path.join(validate_dir, \"dogs\")\nval_cat_dir = os.path.join(validate_dir, \"cats\")\n\nos.mkdir(train_dogs_dir)\nos.mkdir(train_cats_dir)\n\n\nos.mkdir(val_dog_dir)\nos.mkdir(val_cat_dir)","metadata":{"execution":{"iopub.status.busy":"2024-04-01T21:14:52.820017Z","iopub.execute_input":"2024-04-01T21:14:52.820424Z","iopub.status.idle":"2024-04-01T21:14:52.828156Z","shell.execute_reply.started":"2024-04-01T21:14:52.820395Z","shell.execute_reply":"2024-04-01T21:14:52.826854Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cats_count = 0\ndogs_count = 0\n\ntrain = '/kaggle/working/train'\nfor i in os.listdir(train):\n    if i.startswith('cat.'):\n        cats_count += 1\n    elif i.startswith('dog.'):\n        dogs_count += 1\nprint(f\"Number of dog images: {dogs_count}\")\nprint(f\"Number of cat images: {cats_count}\")","metadata":{"execution":{"iopub.status.busy":"2024-04-01T21:14:53.229796Z","iopub.execute_input":"2024-04-01T21:14:53.230164Z","iopub.status.idle":"2024-04-01T21:14:53.257563Z","shell.execute_reply.started":"2024-04-01T21:14:53.230139Z","shell.execute_reply":"2024-04-01T21:14:53.256391Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\noriginal_dataset = '/kaggle/working/train'\n\nfnames = [f'cat.{i}.jpg' for i in range(12500)]\n\nfor fname in fnames:\n    src = os.path.join(original_dataset, fname)\n    dst = os.path.join('/kaggle/working/dogs_vs_cats_dataset/cats', fname)\n    shutil.copyfile(src, dst)\n    \n    \nfnames_dog_train = [f'dog.{i}.jpg' for i in range(12500)]\n\nfor fname in fnames_dog_train:\n    src = os.path.join(original_dataset, fname)\n    dst = os.path.join('/kaggle/working/dogs_vs_cats_dataset/dogs', fname)\n    shutil.copyfile(src, dst)\n","metadata":{"execution":{"iopub.status.busy":"2024-04-01T21:14:53.690700Z","iopub.execute_input":"2024-04-01T21:14:53.691090Z","iopub.status.idle":"2024-04-01T21:14:56.569362Z","shell.execute_reply.started":"2024-04-01T21:14:53.691061Z","shell.execute_reply":"2024-04-01T21:14:56.568336Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Data Cleaing and Split Data\nAll images should be checked before the copy, so if they have a zero file length, they will be omitted from the copying process. If this is the case then \nthe function should print out a message such as \"filename is zero length, so ignoring.\". this check before the split so that only non-zero images are considered when doing the actual split.","metadata":{}},{"cell_type":"code","source":"# data cleaning  split_data \ndef split_data(SOURCE, TRAINING, TESTING, SPLIT_SIZE):\n    # testing will be for validtation\n  ### START CODE HERE\n  # Shuffle list\n  shuffled_source = random.sample(os.listdir(SOURCE), len(os.listdir(SOURCE)))\n\n  # Find total number of files in training dir\n  training_number = int(len(shuffled_source) * SPLIT_SIZE)\n\n  i = 0\n  target = TRAINING\n\n  for item in shuffled_source:\n    item_source = os.path.join(SOURCE, item)\n    if os.path.getsize(item_source) == 0:\n      print(f'{item} is zero length, so ignoring.')\n    else: \n      shutil.copyfile(item_source, os.path.join(target, item))\n      i += 1\n\n    # Switch copy target to TESTING\n    if i == training_number:\n      target = TESTING\n  ### END CODE HERE","metadata":{"execution":{"iopub.status.busy":"2024-04-01T21:14:56.571615Z","iopub.execute_input":"2024-04-01T21:14:56.571954Z","iopub.status.idle":"2024-04-01T21:14:56.578418Z","shell.execute_reply.started":"2024-04-01T21:14:56.571926Z","shell.execute_reply":"2024-04-01T21:14:56.577593Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"source_dogs = '/kaggle/working/dogs_vs_cats_dataset/dogs'\ntraining_d = '/kaggle/working/dogs_vs_cats_dataset/train_data/dogs'\ntest_d = '/kaggle/working/dogs_vs_cats_dataset/val/dogs'\nsplit_size = .9\nsplit_data(source_dogs, training_d, test_d,split_size)\n\nprint(f\"There are {len(os.listdir(training_d))} images of dogs for training\")\nprint(f\"There are {len(os.listdir(test_d))}images of dogs for training\")","metadata":{"execution":{"iopub.status.busy":"2024-04-01T21:14:56.579446Z","iopub.execute_input":"2024-04-01T21:14:56.580063Z","iopub.status.idle":"2024-04-01T21:14:58.237933Z","shell.execute_reply.started":"2024-04-01T21:14:56.580036Z","shell.execute_reply":"2024-04-01T21:14:58.236600Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**The data for dogs is clean (no zero file)**","metadata":{}},{"cell_type":"code","source":"source_cats = '/kaggle/working/dogs_vs_cats_dataset/cats'\ntraining_c = '/kaggle/working/dogs_vs_cats_dataset/train_data/cats'\ntest_c = '/kaggle/working/dogs_vs_cats_dataset/val/cats'\nsplit_size = .9\nsplit_data(source_cats, training_c, test_c,split_size)\n\nprint(f\"There are {len(os.listdir(training_c))} images of cats for training\")\nprint(f\"There are {len(os.listdir(test_c))}images of cats for training\")","metadata":{"execution":{"iopub.status.busy":"2024-04-01T21:14:58.239866Z","iopub.execute_input":"2024-04-01T21:14:58.240180Z","iopub.status.idle":"2024-04-01T21:14:59.768551Z","shell.execute_reply.started":"2024-04-01T21:14:58.240155Z","shell.execute_reply":"2024-04-01T21:14:59.767565Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**The data for dogs is clean (no zero file)**","metadata":{}},{"cell_type":"markdown","source":"## Use ImageDataGenerator Method","metadata":{}},{"cell_type":"code","source":"def train_val_generators(TRAINING_DIR, VALIDATION_DIR):\n\n  # Instantiate the ImageDataGenerator class \n  train_datagen = ImageDataGenerator(\n      rescale=1./255,\n      rotation_range=40,\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      fill_mode='nearest')\n\n\n  train_generator = train_datagen.flow_from_directory(directory=TRAINING_DIR,\n                                                      batch_size=45,\n                                                      class_mode='binary',\n                                                      target_size=(150, 150))\n\n  validation_datagen = ImageDataGenerator(rescale = 1./255.)\n\n  validation_generator = validation_datagen.flow_from_directory(directory=VALIDATION_DIR,\n                                                                batch_size=5,\n                                                                class_mode='binary',\n                                                                target_size=(150, 150))\n  return train_generator, validation_generator","metadata":{"execution":{"iopub.status.busy":"2024-04-01T21:15:02.613956Z","iopub.execute_input":"2024-04-01T21:15:02.614320Z","iopub.status.idle":"2024-04-01T21:15:02.622001Z","shell.execute_reply.started":"2024-04-01T21:15:02.614293Z","shell.execute_reply":"2024-04-01T21:15:02.620774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_generator, validation_generator = train_val_generators('/kaggle/working/dogs_vs_cats_dataset/train_data','/kaggle/working/dogs_vs_cats_dataset/val')","metadata":{"execution":{"iopub.status.busy":"2024-04-01T21:15:04.193442Z","iopub.execute_input":"2024-04-01T21:15:04.193895Z","iopub.status.idle":"2024-04-01T21:15:04.683291Z","shell.execute_reply.started":"2024-04-01T21:15:04.193838Z","shell.execute_reply":"2024-04-01T21:15:04.682072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Download the pre-trained weights. No top means it excludes the fully connected layer it uses for classification.\n!wget --no-check-certificate \\\n    https://storage.googleapis.com/mledu-datasets/inception_v3_weights_tf_dim_ordering_tf_kernels_notop.h5 \\\n    -O /tmp/inception_v3_weights_tf_dim_ordering_tf_kernels_notop.h5","metadata":{"execution":{"iopub.status.busy":"2024-04-01T21:15:05.518594Z","iopub.execute_input":"2024-04-01T21:15:05.519178Z","iopub.status.idle":"2024-04-01T21:15:10.673404Z","shell.execute_reply.started":"2024-04-01T21:15:05.519144Z","shell.execute_reply":"2024-04-01T21:15:10.671478Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.applications.inception_v3 import InceptionV3\nfrom tensorflow.keras import layers\n\n# Set the weights file you downloaded into a variable\nlocal_weights_file = '/tmp/inception_v3_weights_tf_dim_ordering_tf_kernels_notop.h5'\n\n# Initialize the base model.\n# Set the input shape and remove the dense layers.\npre_trained_model = InceptionV3(input_shape = (150, 150, 3), \n                                include_top = False, \n                                weights = None)\n\n# Load the pre-trained weights you downloaded.\npre_trained_model.load_weights(local_weights_file)\n\n# Freeze the weights of the layers.\nfor layer in pre_trained_model.layers:\n  layer.trainable = False","metadata":{"execution":{"iopub.status.busy":"2024-04-01T21:15:10.677300Z","iopub.execute_input":"2024-04-01T21:15:10.678320Z","iopub.status.idle":"2024-04-01T21:15:13.307779Z","shell.execute_reply.started":"2024-04-01T21:15:10.678261Z","shell.execute_reply":"2024-04-01T21:15:13.306204Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Choose `mixed7` as the last layer of your base model\nlast_layer = pre_trained_model.get_layer('mixed7')\nlast_output = last_layer.output","metadata":{"execution":{"iopub.status.busy":"2024-04-01T21:15:13.309504Z","iopub.execute_input":"2024-04-01T21:15:13.310001Z","iopub.status.idle":"2024-04-01T21:15:13.318854Z","shell.execute_reply.started":"2024-04-01T21:15:13.309949Z","shell.execute_reply":"2024-04-01T21:15:13.315604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras import Model\nx = layers.Flatten()(last_output)\nx = layers.Dense(1024,activation = 'relu')(x)\nx = layers.Dropout(0.2)(x)\nx = layers.Dense  (1, activation='sigmoid')(x) \nmodel = Model(pre_trained_model.input, x)\n","metadata":{"execution":{"iopub.status.busy":"2024-04-01T21:15:13.320860Z","iopub.execute_input":"2024-04-01T21:15:13.321202Z","iopub.status.idle":"2024-04-01T21:15:14.716870Z","shell.execute_reply.started":"2024-04-01T21:15:13.321173Z","shell.execute_reply":"2024-04-01T21:15:14.713696Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.optimizers import RMSprop\nmodel.compile(optimizer=RMSprop(learning_rate=0.001),\n                    loss='binary_crossentropy',\n                    metrics=['accuracy']) \n","metadata":{"execution":{"iopub.status.busy":"2024-04-01T21:15:17.695036Z","iopub.execute_input":"2024-04-01T21:15:17.695601Z","iopub.status.idle":"2024-04-01T21:15:17.726465Z","shell.execute_reply.started":"2024-04-01T21:15:17.695561Z","shell.execute_reply":"2024-04-01T21:15:17.724665Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\nhistory = model.fit(train_generator,\n                    epochs= 20,\n                    steps_per_epoch = 100,\n                    verbose=1,\n                    validation_steps = 50,\n                    validation_data=validation_generator)","metadata":{"execution":{"iopub.status.busy":"2024-04-01T21:15:25.145928Z","iopub.execute_input":"2024-04-01T21:15:25.150415Z","iopub.status.idle":"2024-04-01T21:57:44.462963Z","shell.execute_reply.started":"2024-04-01T21:15:25.150322Z","shell.execute_reply":"2024-04-01T21:57:44.461567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"acc=history.history['accuracy']\nval_acc=history.history['val_accuracy']\nloss=history.history['loss']\nval_loss=history.history['val_loss']\nepochs=range(len(acc))\n\nplt.plot(epochs, acc, 'r', \"Training Accuracy\")\nplt.plot(epochs, val_acc, 'b', \"Validation Accuracy\")\nplt.title('Training and validation accuracy')\n    \nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-04-01T21:57:51.746718Z","iopub.execute_input":"2024-04-01T21:57:51.747197Z","iopub.status.idle":"2024-04-01T21:57:51.975191Z","shell.execute_reply.started":"2024-04-01T21:57:51.747164Z","shell.execute_reply":"2024-04-01T21:57:51.973766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"zip_ref = zipfile.ZipFile('/kaggle/input/dogs-vs-cats/test1.zip','r')\nzip_ref.extractall()\nzip_ref.close()","metadata":{"execution":{"iopub.status.busy":"2024-04-01T20:22:51.511888Z","iopub.execute_input":"2024-04-01T20:22:51.512784Z","iopub.status.idle":"2024-04-01T20:22:57.855402Z","shell.execute_reply.started":"2024-04-01T20:22:51.512743Z","shell.execute_reply":"2024-04-01T20:22:57.854269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(os.listdir('/kaggle/working/test1')[5])","metadata":{"execution":{"iopub.status.busy":"2024-04-01T20:31:03.419189Z","iopub.execute_input":"2024-04-01T20:31:03.419546Z","iopub.status.idle":"2024-04-01T20:31:03.431693Z","shell.execute_reply.started":"2024-04-01T20:31:03.419519Z","shell.execute_reply":"2024-04-01T20:31:03.430567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nfrom tensorflow.keras.utils import load_img, img_to_array\nplt.imshow(load_img(os.path.join('/kaggle/working/test1', os.listdir('/kaggle/working/test1')[11])))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-04-02T10:04:43.508092Z","iopub.execute_input":"2024-04-02T10:04:43.509579Z","iopub.status.idle":"2024-04-02T10:04:43.971801Z","shell.execute_reply.started":"2024-04-02T10:04:43.509521Z","shell.execute_reply":"2024-04-02T10:04:43.970267Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ny=os.listdir('/kaggle/working/test1')\n","metadata":{"execution":{"iopub.status.busy":"2024-04-01T20:52:18.988962Z","iopub.execute_input":"2024-04-01T20:52:18.989723Z","iopub.status.idle":"2024-04-01T20:52:19.000745Z","shell.execute_reply.started":"2024-04-01T20:52:18.989688Z","shell.execute_reply":"2024-04-01T20:52:18.999662Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(y))","metadata":{"execution":{"iopub.status.busy":"2024-04-01T20:53:50.788278Z","iopub.execute_input":"2024-04-01T20:53:50.788698Z","iopub.status.idle":"2024-04-01T20:53:50.794205Z","shell.execute_reply.started":"2024-04-01T20:53:50.788668Z","shell.execute_reply":"2024-04-01T20:53:50.792879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = []\nfor i in range(len(y)):\n    img = load_img(os.path.join('/kaggle/working/test1', os.listdir('/kaggle/working/test1')[i]), target_size=(150, 150))\n    x = img_to_array(img)\n    x /= 255\n    #classes = model.predict(x.reshape(1,150,150,3), batch_size = 10)\n    y_pred.append(x)\n\n\n    \n","metadata":{"execution":{"iopub.status.busy":"2024-04-01T22:40:07.478010Z","iopub.execute_input":"2024-04-01T22:40:07.478436Z","iopub.status.idle":"2024-04-01T22:41:50.641419Z","shell.execute_reply.started":"2024-04-01T22:40:07.478407Z","shell.execute_reply":"2024-04-01T22:41:50.640161Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"images = np.vstack([y_pred])","metadata":{"execution":{"iopub.status.busy":"2024-04-01T22:44:00.019446Z","iopub.execute_input":"2024-04-01T22:44:00.019940Z","iopub.status.idle":"2024-04-01T22:44:09.020734Z","shell.execute_reply.started":"2024-04-01T22:44:00.019908Z","shell.execute_reply":"2024-04-01T22:44:09.019447Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classes = model.predict(images, batch_size = 50)","metadata":{"execution":{"iopub.status.busy":"2024-04-01T22:44:59.270218Z","iopub.execute_input":"2024-04-01T22:44:59.271200Z","iopub.status.idle":"2024-04-01T22:49:30.866462Z","shell.execute_reply.started":"2024-04-01T22:44:59.271163Z","shell.execute_reply":"2024-04-01T22:49:30.865196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = classes.astype('int')","metadata":{"execution":{"iopub.status.busy":"2024-04-01T22:53:10.006776Z","iopub.execute_input":"2024-04-01T22:53:10.007233Z","iopub.status.idle":"2024-04-01T22:53:10.013881Z","shell.execute_reply.started":"2024-04-01T22:53:10.007202Z","shell.execute_reply":"2024-04-01T22:53:10.012493Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\ndf = pd.DataFrame(y, columns = ['label'])","metadata":{"execution":{"iopub.status.busy":"2024-04-01T23:00:12.115500Z","iopub.execute_input":"2024-04-01T23:00:12.116698Z","iopub.status.idle":"2024-04-01T23:00:12.122440Z","shell.execute_reply.started":"2024-04-01T23:00:12.116651Z","shell.execute_reply":"2024-04-01T23:00:12.121389Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-04-01T23:05:38.147375Z","iopub.execute_input":"2024-04-01T23:05:38.148788Z","iopub.status.idle":"2024-04-01T23:05:38.158255Z","shell.execute_reply.started":"2024-04-01T23:05:38.148754Z","shell.execute_reply":"2024-04-01T23:05:38.157325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df1 = df.reset_index()","metadata":{"execution":{"iopub.status.busy":"2024-04-01T23:05:42.198437Z","iopub.execute_input":"2024-04-01T23:05:42.199556Z","iopub.status.idle":"2024-04-01T23:05:42.205406Z","shell.execute_reply.started":"2024-04-01T23:05:42.199519Z","shell.execute_reply":"2024-04-01T23:05:42.204475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df1 = df1.rename(columns = {'index':'id'})","metadata":{"execution":{"iopub.status.busy":"2024-04-01T23:05:45.872849Z","iopub.execute_input":"2024-04-01T23:05:45.873254Z","iopub.status.idle":"2024-04-01T23:05:45.879769Z","shell.execute_reply.started":"2024-04-01T23:05:45.873224Z","shell.execute_reply":"2024-04-01T23:05:45.878033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df1.head()","metadata":{"execution":{"iopub.status.busy":"2024-04-01T23:05:49.990520Z","iopub.execute_input":"2024-04-01T23:05:49.990936Z","iopub.status.idle":"2024-04-01T23:05:50.001385Z","shell.execute_reply.started":"2024-04-01T23:05:49.990904Z","shell.execute_reply":"2024-04-01T23:05:50.000037Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}