{"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":"import keras\nfrom keras.models import Sequential\nfrom keras.layers import Dense, Dropout, Flatten\nfrom keras.layers import Conv2D, MaxPooling2D\nfrom keras.utils import to_categorical\nfrom keras.preprocessing import image\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom sklearn.model_selection import train_test_split\nfrom keras.utils import to_categorical\nfrom tqdm import tqdm\nimport os","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-11-07T02:58:12.240926Z","iopub.execute_input":"2023-11-07T02:58:12.241292Z","iopub.status.idle":"2023-11-07T02:58:21.266598Z","shell.execute_reply.started":"2023-11-07T02:58:12.241259Z","shell.execute_reply":"2023-11-07T02:58:21.265624Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_old=pd.read_csv('/kaggle/input/dog-breed-identification/labels.csv')\nlabels_old.head()","metadata":{"execution":{"iopub.status.busy":"2023-11-07T02:58:25.990186Z","iopub.execute_input":"2023-11-07T02:58:25.990827Z","iopub.status.idle":"2023-11-07T02:58:26.034830Z","shell.execute_reply.started":"2023-11-07T02:58:25.990793Z","shell.execute_reply":"2023-11-07T02:58:26.033928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_img_path = '/kaggle/input/dog-breed-identification/train/'\ntest_img_path = '/kaggle/input/dog-breed-identification/test/'","metadata":{"execution":{"iopub.status.busy":"2023-11-07T02:58:29.293060Z","iopub.execute_input":"2023-11-07T02:58:29.293515Z","iopub.status.idle":"2023-11-07T02:58:29.297854Z","shell.execute_reply.started":"2023-11-07T02:58:29.293471Z","shell.execute_reply":"2023-11-07T02:58:29.296925Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train = labels_old['breed']\ny_train","metadata":{"execution":{"iopub.status.busy":"2023-11-07T02:58:32.494440Z","iopub.execute_input":"2023-11-07T02:58:32.495052Z","iopub.status.idle":"2023-11-07T02:58:32.503047Z","shell.execute_reply.started":"2023-11-07T02:58:32.495018Z","shell.execute_reply":"2023-11-07T02:58:32.502097Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels=labels_old.assign(train_img_path=lambda x: train_img_path + x['id'] +'.jpg')\ntrain_labels.head()","metadata":{"execution":{"iopub.status.busy":"2023-11-07T02:58:35.545784Z","iopub.execute_input":"2023-11-07T02:58:35.546565Z","iopub.status.idle":"2023-11-07T02:58:35.561902Z","shell.execute_reply.started":"2023-11-07T02:58:35.546537Z","shell.execute_reply":"2023-11-07T02:58:35.561013Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = train_labels['train_img_path']\nX_train","metadata":{"execution":{"iopub.status.busy":"2023-11-07T02:58:38.713839Z","iopub.execute_input":"2023-11-07T02:58:38.714200Z","iopub.status.idle":"2023-11-07T02:58:38.722262Z","shell.execute_reply.started":"2023-11-07T02:58:38.714170Z","shell.execute_reply":"2023-11-07T02:58:38.721304Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(X_train), len(y_train)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T02:58:41.694068Z","iopub.execute_input":"2023-11-07T02:58:41.694449Z","iopub.status.idle":"2023-11-07T02:58:41.700793Z","shell.execute_reply.started":"2023-11-07T02:58:41.694418Z","shell.execute_reply":"2023-11-07T02:58:41.699722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import random\n\n# shuffle X and y\ncombined = list(zip(X_train, y_train))\nrandom.shuffle(combined)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T02:58:44.107139Z","iopub.execute_input":"2023-11-07T02:58:44.108165Z","iopub.status.idle":"2023-11-07T02:58:44.125821Z","shell.execute_reply.started":"2023-11-07T02:58:44.108122Z","shell.execute_reply":"2023-11-07T02:58:44.124829Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample = pd.read_csv('/kaggle/input/dog-breed-identification/sample_submission.csv')\nsample\n\ntest_data = sample[[\"id\"]]\ntest_data\n\ntest_labels=test_data.assign(test_img_path=lambda x: test_img_path + x['id'] +'.jpg')\ntest_labels.head()","metadata":{"execution":{"iopub.status.busy":"2023-11-07T02:58:47.511544Z","iopub.execute_input":"2023-11-07T02:58:47.511931Z","iopub.status.idle":"2023-11-07T02:58:48.008091Z","shell.execute_reply.started":"2023-11-07T02:58:47.511902Z","shell.execute_reply":"2023-11-07T02:58:48.007088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_labels","metadata":{"execution":{"iopub.status.busy":"2023-11-07T02:58:51.357228Z","iopub.execute_input":"2023-11-07T02:58:51.357571Z","iopub.status.idle":"2023-11-07T02:58:51.368937Z","shell.execute_reply.started":"2023-11-07T02:58:51.357542Z","shell.execute_reply":"2023-11-07T02:58:51.368030Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test = test_labels['test_img_path']\nX_test","metadata":{"execution":{"iopub.status.busy":"2023-11-07T02:59:43.681516Z","iopub.execute_input":"2023-11-07T02:59:43.681900Z","iopub.status.idle":"2023-11-07T02:59:43.690242Z","shell.execute_reply.started":"2023-11-07T02:59:43.681871Z","shell.execute_reply":"2023-11-07T02:59:43.689392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\nfrom keras.utils import to_categorical\n\n# Label and one-hot encoding y labels\nle = LabelEncoder()\nle.fit(y_train)\ny_ohe = to_categorical(le.transform(y_train))\ny_ohe = np.array(y_ohe)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T02:59:46.502382Z","iopub.execute_input":"2023-11-07T02:59:46.502872Z","iopub.status.idle":"2023-11-07T02:59:46.515506Z","shell.execute_reply.started":"2023-11-07T02:59:46.502841Z","shell.execute_reply":"2023-11-07T02:59:46.514250Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_ohe","metadata":{"execution":{"iopub.status.busy":"2023-11-07T02:59:50.872445Z","iopub.execute_input":"2023-11-07T02:59:50.872792Z","iopub.status.idle":"2023-11-07T02:59:50.879932Z","shell.execute_reply.started":"2023-11-07T02:59:50.872765Z","shell.execute_reply":"2023-11-07T02:59:50.878940Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"doggy_breeds = pd.DataFrame(train_labels['breed'])\ndoggy_breeds['Sorted_Breeds'] = sorted(doggy_breeds['breed'])\nsorted_breeds = doggy_breeds['Sorted_Breeds'].unique()","metadata":{"execution":{"iopub.status.busy":"2023-11-07T02:59:53.657330Z","iopub.execute_input":"2023-11-07T02:59:53.658035Z","iopub.status.idle":"2023-11-07T02:59:53.673011Z","shell.execute_reply.started":"2023-11-07T02:59:53.658004Z","shell.execute_reply":"2023-11-07T02:59:53.672092Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sorted_breeds","metadata":{"execution":{"iopub.status.busy":"2023-11-07T02:59:56.305054Z","iopub.execute_input":"2023-11-07T02:59:56.305376Z","iopub.status.idle":"2023-11-07T02:59:56.312176Z","shell.execute_reply.started":"2023-11-07T02:59:56.305349Z","shell.execute_reply":"2023-11-07T02:59:56.311273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(sorted_breeds)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T03:00:00.600201Z","iopub.execute_input":"2023-11-07T03:00:00.601121Z","iopub.status.idle":"2023-11-07T03:00:00.606879Z","shell.execute_reply.started":"2023-11-07T03:00:00.601084Z","shell.execute_reply":"2023-11-07T03:00:00.605899Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nfrom tensorflow.keras.utils import img_to_array, load_img\n\nimg_data = np.array([img_to_array(load_img(img, target_size = (192,192)))\n                     for img in X_train])","metadata":{"execution":{"iopub.status.busy":"2023-11-07T03:00:02.773737Z","iopub.execute_input":"2023-11-07T03:00:02.774766Z","iopub.status.idle":"2023-11-07T03:01:08.922008Z","shell.execute_reply.started":"2023-11-07T03:00:02.774730Z","shell.execute_reply":"2023-11-07T03:01:08.921153Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_img_data = np.array([img_to_array(load_img(img, target_size = (192,192)))\n                     for img in X_test])","metadata":{"execution":{"iopub.status.busy":"2023-11-07T03:01:35.636966Z","iopub.execute_input":"2023-11-07T03:01:35.637598Z","iopub.status.idle":"2023-11-07T03:02:41.914527Z","shell.execute_reply.started":"2023-11-07T03:01:35.637564Z","shell.execute_reply":"2023-11-07T03:02:41.913728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_data.shape","metadata":{"execution":{"iopub.status.busy":"2023-11-07T03:03:14.159767Z","iopub.execute_input":"2023-11-07T03:03:14.160096Z","iopub.status.idle":"2023-11-07T03:03:14.166890Z","shell.execute_reply.started":"2023-11-07T03:03:14.160071Z","shell.execute_reply":"2023-11-07T03:03:14.165710Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_img_data.shape","metadata":{"execution":{"iopub.status.busy":"2023-11-07T03:03:17.055049Z","iopub.execute_input":"2023-11-07T03:03:17.055421Z","iopub.status.idle":"2023-11-07T03:03:17.061604Z","shell.execute_reply.started":"2023-11-07T03:03:17.055391Z","shell.execute_reply":"2023-11-07T03:03:17.060708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_ohe.shape","metadata":{"execution":{"iopub.status.busy":"2023-11-07T03:03:19.664796Z","iopub.execute_input":"2023-11-07T03:03:19.665157Z","iopub.status.idle":"2023-11-07T03:03:19.671279Z","shell.execute_reply.started":"2023-11-07T03:03:19.665127Z","shell.execute_reply":"2023-11-07T03:03:19.670338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nX_tr,X_val,y_tr,y_val=train_test_split(img_data,y_ohe,test_size=0.2)\nprint(X_tr.shape)\nprint(y_tr.shape)\nprint(X_val.shape)\nprint(y_val.shape)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T03:03:22.549805Z","iopub.execute_input":"2023-11-07T03:03:22.550530Z","iopub.status.idle":"2023-11-07T03:03:23.744923Z","shell.execute_reply.started":"2023-11-07T03:03:22.550495Z","shell.execute_reply":"2023-11-07T03:03:23.743931Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.applications.inception_v3 import preprocess_input\nfrom keras.preprocessing.image import ImageDataGenerator\n\nbatch_size = 64","metadata":{"execution":{"iopub.status.busy":"2023-11-07T03:03:27.336344Z","iopub.execute_input":"2023-11-07T03:03:27.336705Z","iopub.status.idle":"2023-11-07T03:03:27.341324Z","shell.execute_reply.started":"2023-11-07T03:03:27.336675Z","shell.execute_reply":"2023-11-07T03:03:27.340327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_datagen = ImageDataGenerator(preprocessing_function=preprocess_input, # only use rescale=1./255 if training from scratch\n                                  rotation_range = 30,\n                                  width_shift_range = 0.2,\n                                  height_shift_range = 0.2,\n                                  horizontal_flip = True) # CHECK\n\ntrain_generator = train_datagen.flow(X_tr, y_tr,\n                                     shuffle = False, batch_size = batch_size, seed = 1)\n\n# Create validation generator\nval_datagen = ImageDataGenerator(preprocessing_function=preprocess_input) # do not augment validation data\n\nval_generator = val_datagen.flow(X_val, y_val,\n                                shuffle = False, batch_size = batch_size, seed = 1)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T03:03:46.758231Z","iopub.execute_input":"2023-11-07T03:03:46.758919Z","iopub.status.idle":"2023-11-07T03:03:46.764883Z","shell.execute_reply.started":"2023-11-07T03:03:46.758886Z","shell.execute_reply":"2023-11-07T03:03:46.763872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras import models\nfrom keras import layers\nfrom keras.optimizers import Adam\nfrom keras.layers import GlobalAveragePooling2D, Dense, Flatten, Dropout\nfrom keras.applications.inception_v3 import InceptionV3\nfrom keras.utils.np_utils import to_categorical\nfrom keras.utils.vis_utils import plot_model\n\n# load InceptionV3 pre-trained model\nbase_model = InceptionV3(weights = 'imagenet', include_top = False, input_shape = (192,192,3))\n\nmodel = models.Sequential()\nmodel.add(base_model) # add pre_trained layers\nmodel.add(GlobalAveragePooling2D())\n#model.add(Flatten()) # flatten to 1-D vector to prepare for fully connected layers\nmodel.add(Dropout(0.3))\nmodel.add(Dense(512, activation = 'relu'))\nmodel.add(Dense(512, activation = 'relu'))\nmodel.add(Dense(512, activation = 'relu'))\nmodel.add(Dense(120, activation = 'softmax'))","metadata":{"execution":{"iopub.status.busy":"2023-11-07T03:03:55.079900Z","iopub.execute_input":"2023-11-07T03:03:55.080275Z","iopub.status.idle":"2023-11-07T03:04:03.330121Z","shell.execute_reply.started":"2023-11-07T03:03:55.080243Z","shell.execute_reply":"2023-11-07T03:04:03.329142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nclass myCallback(tf.keras.callbacks.Callback):\n  def on_epoch_end(self, epoch, logs={}):\n    if(logs.get('accuracy')>0.95):\n      self.model.stop_training = True","metadata":{"execution":{"iopub.status.busy":"2023-11-07T03:04:10.869840Z","iopub.execute_input":"2023-11-07T03:04:10.870586Z","iopub.status.idle":"2023-11-07T03:04:10.875774Z","shell.execute_reply.started":"2023-11-07T03:04:10.870554Z","shell.execute_reply":"2023-11-07T03:04:10.874703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(y_train)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T03:04:17.088304Z","iopub.execute_input":"2023-11-07T03:04:17.088648Z","iopub.status.idle":"2023-11-07T03:04:17.094740Z","shell.execute_reply.started":"2023-11-07T03:04:17.088610Z","shell.execute_reply":"2023-11-07T03:04:17.093692Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Number of trainable weights before freezing the base layer:', len(model.trainable_weights))\nmodel.layers[0].trainable = False\nprint('Number of trainable weights after freezing the base layer:', len(model.trainable_weights))","metadata":{"execution":{"iopub.status.busy":"2023-11-07T03:04:21.252186Z","iopub.execute_input":"2023-11-07T03:04:21.252550Z","iopub.status.idle":"2023-11-07T03:04:21.272220Z","shell.execute_reply.started":"2023-11-07T03:04:21.252519Z","shell.execute_reply":"2023-11-07T03:04:21.271284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(Adam(learning_rate=.000001), loss='categorical_crossentropy', metrics=['accuracy']) \nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2023-11-07T03:04:24.744254Z","iopub.execute_input":"2023-11-07T03:04:24.745141Z","iopub.status.idle":"2023-11-07T03:04:24.803754Z","shell.execute_reply.started":"2023-11-07T03:04:24.745105Z","shell.execute_reply":"2023-11-07T03:04:24.802847Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"callbacks = myCallback()\ntrain_steps_per_epoch = X_tr.shape[0] // batch_size\nval_steps_per_epoch = X_val.shape[0] // batch_size\nepochs = 500\n\nhistory = model.fit(train_generator,\n                             steps_per_epoch = train_steps_per_epoch,\n                             validation_data = val_generator,\n                             validation_steps = val_steps_per_epoch,\n                             epochs = epochs, verbose = 1, callbacks=[callbacks])","metadata":{"execution":{"iopub.status.busy":"2023-11-07T03:05:25.160876Z","iopub.execute_input":"2023-11-07T03:05:25.161267Z","iopub.status.idle":"2023-11-07T14:01:16.934388Z","shell.execute_reply.started":"2023-11-07T03:05:25.161234Z","shell.execute_reply":"2023-11-07T14:01:16.933444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.shape","metadata":{"execution":{"iopub.status.busy":"2023-11-07T14:01:22.739329Z","iopub.execute_input":"2023-11-07T14:01:22.739706Z","iopub.status.idle":"2023-11-07T14:01:22.746185Z","shell.execute_reply.started":"2023-11-07T14:01:22.739670Z","shell.execute_reply":"2023-11-07T14:01:22.745382Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_tr.shape","metadata":{"execution":{"iopub.status.busy":"2023-11-07T14:01:25.736928Z","iopub.execute_input":"2023-11-07T14:01:25.737275Z","iopub.status.idle":"2023-11-07T14:01:25.742912Z","shell.execute_reply.started":"2023-11-07T14:01:25.737247Z","shell.execute_reply":"2023-11-07T14:01:25.742034Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nX_val1 = X_val / 255. # rescale to 0-1. Divide by 255 as its the max RGB value\nval_predictions = model.predict(X_val1)\n\n# get model predictions\ny_val_predict = le.classes_[np.argmax(val_predictions,axis=1)] # get labels and reverse back to get the text labels\n# get target labels\ntarget_labels = le.classes_[np.argmax(y_val,axis=1)]\n\n# Store in dataframe\npredict_df = pd.DataFrame({'Target_Labels': target_labels, 'Predictions': y_val_predict})\npredict_df.head(20)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T14:25:23.846429Z","iopub.execute_input":"2023-11-07T14:25:23.847282Z","iopub.status.idle":"2023-11-07T14:25:28.859805Z","shell.execute_reply.started":"2023-11-07T14:25:23.847246Z","shell.execute_reply":"2023-11-07T14:25:28.858812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_predictions.shape, y_val_predict.shape","metadata":{"execution":{"iopub.status.busy":"2023-11-07T14:25:33.528347Z","iopub.execute_input":"2023-11-07T14:25:33.528775Z","iopub.status.idle":"2023-11-07T14:25:33.534985Z","shell.execute_reply.started":"2023-11-07T14:25:33.528731Z","shell.execute_reply":"2023-11-07T14:25:33.533893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score\ntest_acc = accuracy_score(target_labels, y_val_predict)\nprint (test_acc)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T14:25:39.764293Z","iopub.execute_input":"2023-11-07T14:25:39.764698Z","iopub.status.idle":"2023-11-07T14:25:39.774808Z","shell.execute_reply.started":"2023-11-07T14:25:39.764660Z","shell.execute_reply":"2023-11-07T14:25:39.773786Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"correct = (target_labels == y_val_predict)\naccuracy = correct.sum() / correct.size\nprint(accuracy)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T14:25:42.825852Z","iopub.execute_input":"2023-11-07T14:25:42.826745Z","iopub.status.idle":"2023-11-07T14:25:42.832454Z","shell.execute_reply.started":"2023-11-07T14:25:42.826704Z","shell.execute_reply":"2023-11-07T14:25:42.831311Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_img_data.shape #execute this","metadata":{"execution":{"iopub.status.busy":"2023-11-07T14:25:45.960902Z","iopub.execute_input":"2023-11-07T14:25:45.961709Z","iopub.status.idle":"2023-11-07T14:25:45.967648Z","shell.execute_reply.started":"2023-11-07T14:25:45.961674Z","shell.execute_reply":"2023-11-07T14:25:45.966632Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test1 = test_img_data / 255. # rescale to 0-1. Divide by 255 as its the max RGB value\ntest_prediction = model.predict(X_test1)\n\n# get model predictions\ny_test_predict = le.classes_[np.argmax(test_prediction,axis=1)] # get labels and reverse back to get the text labels\n# get target labels\n\n\n# Store in dataframe\n#predict_df = pd.DataFrame({'Predictions': y_val_predict})\n#predict_df.head(20)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T14:25:49.018081Z","iopub.execute_input":"2023-11-07T14:25:49.018542Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test_predict = pd.DataFrame({'Predictions': y_test_predict})\ny_test_predict.head(20)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T14:02:58.192236Z","iopub.execute_input":"2023-11-07T14:02:58.192654Z","iopub.status.idle":"2023-11-07T14:02:58.240904Z","shell.execute_reply.started":"2023-11-07T14:02:58.192607Z","shell.execute_reply":"2023-11-07T14:02:58.239703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#predict_df.shape","metadata":{"execution":{"iopub.status.busy":"2023-11-02T13:40:54.554763Z","iopub.execute_input":"2023-11-02T13:40:54.555155Z","iopub.status.idle":"2023-11-02T13:40:54.559628Z","shell.execute_reply.started":"2023-11-02T13:40:54.555099Z","shell.execute_reply":"2023-11-02T13:40:54.558676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_prediction.shape","metadata":{"execution":{"iopub.status.busy":"2023-11-07T14:03:03.008135Z","iopub.execute_input":"2023-11-07T14:03:03.008465Z","iopub.status.idle":"2023-11-07T14:03:03.014480Z","shell.execute_reply.started":"2023-11-07T14:03:03.008438Z","shell.execute_reply":"2023-11-07T14:03:03.013591Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#predictions = []\n \n#for prediction_row in test_prediction:     # test_predictions contain the predictions from model.predict\n    #prediction_op_row = [np.format_float_positional(prob, precision=6) for prob in prediction_row]\n    #predictions.append(prediction_op_row)","metadata":{"execution":{"iopub.status.busy":"2023-10-28T15:49:24.138419Z","iopub.execute_input":"2023-10-28T15:49:24.139018Z","iopub.status.idle":"2023-10-28T15:49:24.143001Z","shell.execute_reply.started":"2023-10-28T15:49:24.138983Z","shell.execute_reply":"2023-10-28T15:49:24.142113Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#test_predictions","metadata":{"execution":{"iopub.status.busy":"2023-10-28T15:49:40.341441Z","iopub.execute_input":"2023-10-28T15:49:40.342342Z","iopub.status.idle":"2023-10-28T15:49:40.346578Z","shell.execute_reply.started":"2023-10-28T15:49:40.342306Z","shell.execute_reply":"2023-10-28T15:49:40.345432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_predictions = []\n \nfor prediction_row in test_prediction:     # test_predictions contain the predictions from model.predict\n    test_pred_row_by_row = [np.format_float_positional(prob, precision=6) for prob in prediction_row]\n    test_predictions.append(test_pred_row_by_row)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T14:03:08.274850Z","iopub.execute_input":"2023-11-07T14:03:08.275206Z","iopub.status.idle":"2023-11-07T14:03:11.087045Z","shell.execute_reply.started":"2023-11-07T14:03:08.275172Z","shell.execute_reply":"2023-11-07T14:03:11.086245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(test_predictions)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T14:03:18.461886Z","iopub.execute_input":"2023-11-07T14:03:18.462718Z","iopub.status.idle":"2023-11-07T14:03:18.468200Z","shell.execute_reply.started":"2023-11-07T14:03:18.462677Z","shell.execute_reply":"2023-11-07T14:03:18.467269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#submission_df = pd.DataFrame(predictions, columns=ordered_text_labels) ","metadata":{"execution":{"iopub.status.busy":"2023-10-28T14:31:06.530296Z","iopub.execute_input":"2023-10-28T14:31:06.531030Z","iopub.status.idle":"2023-10-28T14:31:06.534726Z","shell.execute_reply.started":"2023-10-28T14:31:06.530998Z","shell.execute_reply":"2023-10-28T14:31:06.533846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(train_labels['breed']).unique()","metadata":{"execution":{"iopub.status.busy":"2023-11-07T14:03:21.582486Z","iopub.execute_input":"2023-11-07T14:03:21.582866Z","iopub.status.idle":"2023-11-07T14:03:21.598559Z","shell.execute_reply.started":"2023-11-07T14:03:21.582835Z","shell.execute_reply":"2023-11-07T14:03:21.597571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df = pd.DataFrame(test_predictions, columns=sorted_breeds)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T14:03:24.925057Z","iopub.execute_input":"2023-11-07T14:03:24.925683Z","iopub.status.idle":"2023-11-07T14:03:25.002578Z","shell.execute_reply.started":"2023-11-07T14:03:24.925648Z","shell.execute_reply":"2023-11-07T14:03:25.001773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#submission_df","metadata":{"execution":{"iopub.status.busy":"2023-10-28T15:50:22.023895Z","iopub.execute_input":"2023-10-28T15:50:22.024232Z","iopub.status.idle":"2023-10-28T15:50:22.028391Z","shell.execute_reply.started":"2023-10-28T15:50:22.024206Z","shell.execute_reply":"2023-10-28T15:50:22.027429Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df['id'] = test_labels['id']","metadata":{"execution":{"iopub.status.busy":"2023-11-07T14:03:28.765285Z","iopub.execute_input":"2023-11-07T14:03:28.765652Z","iopub.status.idle":"2023-11-07T14:03:28.771220Z","shell.execute_reply.started":"2023-11-07T14:03:28.765606Z","shell.execute_reply":"2023-11-07T14:03:28.770153Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df.shape","metadata":{"execution":{"iopub.status.busy":"2023-11-07T14:03:31.537863Z","iopub.execute_input":"2023-11-07T14:03:31.538214Z","iopub.status.idle":"2023-11-07T14:03:31.544159Z","shell.execute_reply.started":"2023-11-07T14:03:31.538185Z","shell.execute_reply":"2023-11-07T14:03:31.543247Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#submission_df","metadata":{"execution":{"iopub.status.busy":"2023-10-28T15:50:38.801906Z","iopub.execute_input":"2023-10-28T15:50:38.802244Z","iopub.status.idle":"2023-10-28T15:50:38.806359Z","shell.execute_reply.started":"2023-10-28T15:50:38.802218Z","shell.execute_reply":"2023-10-28T15:50:38.805377Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"if 'id' in submission_df:\n    cols = ['id'] + [col for col in submission_df if col != 'id']\n    submission_df = submission_df[cols]","metadata":{"execution":{"iopub.status.busy":"2023-11-07T14:03:34.229511Z","iopub.execute_input":"2023-11-07T14:03:34.230140Z","iopub.status.idle":"2023-11-07T14:03:34.302431Z","shell.execute_reply.started":"2023-11-07T14:03:34.230107Z","shell.execute_reply":"2023-11-07T14:03:34.301686Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df","metadata":{"execution":{"iopub.status.busy":"2023-11-07T14:09:57.734295Z","iopub.execute_input":"2023-11-07T14:09:57.735031Z","iopub.status.idle":"2023-11-07T14:09:57.792458Z","shell.execute_reply.started":"2023-11-07T14:09:57.735002Z","shell.execute_reply":"2023-11-07T14:09:57.791594Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df.to_csv('/kaggle/working/Palash_2022mt12133_submission_v16.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T14:11:01.676425Z","iopub.execute_input":"2023-11-07T14:11:01.676804Z","iopub.status.idle":"2023-11-07T14:11:02.401112Z","shell.execute_reply.started":"2023-11-07T14:11:01.676774Z","shell.execute_reply":"2023-11-07T14:11:02.400161Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df","metadata":{"execution":{"iopub.status.busy":"2023-11-07T14:12:56.172366Z","iopub.execute_input":"2023-11-07T14:12:56.173235Z","iopub.status.idle":"2023-11-07T14:12:56.229572Z","shell.execute_reply.started":"2023-11-07T14:12:56.173189Z","shell.execute_reply":"2023-11-07T14:12:56.228655Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df.to_csv('/kaggle/working/Palash_2022mt12133_submission_v17.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T14:24:27.078141Z","iopub.execute_input":"2023-11-07T14:24:27.078521Z","iopub.status.idle":"2023-11-07T14:24:27.808745Z","shell.execute_reply.started":"2023-11-07T14:24:27.078490Z","shell.execute_reply":"2023-11-07T14:24:27.807792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df.to_csv('C:\\\\Dell\\\\Palash_2022mt12133_submission_v17.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2023-11-07T14:26:20.991012Z","iopub.execute_input":"2023-11-07T14:26:20.991533Z","iopub.status.idle":"2023-11-07T14:26:21.343961Z","shell.execute_reply.started":"2023-11-07T14:26:20.991487Z","shell.execute_reply":"2023-11-07T14:26:21.342691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from IPython.display import FileLink\nFileLink('submission.csv')","metadata":{},"execution_count":null,"outputs":[]}]}