{"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":"# Intro\nWelcome to the [Dog Breed Identification](https://www.kaggle.com/c/dog-breed-identification/overview) competition.\n![](https://storage.googleapis.com/kaggle-competitions/kaggle/7327/logos/header.png)\n\n<font size=\"4\"><span style=\"color: royalblue;\">Please vote the notebook up if it helps you. Feel free to leave a comment above the notebook. Thank you. </span></font>","metadata":{}},{"cell_type":"markdown","source":"# Libraries","metadata":{}},{"cell_type":"code","source":"import os\nimport numpy as np\nimport pandas as pd\n\nimport cv2\nimport matplotlib.pyplot as plt\n\nfrom sklearn import preprocessing\nfrom sklearn.model_selection import train_test_split\n\nfrom keras.utils import to_categorical\nfrom keras.models import Sequential, Model\nfrom keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPool2D\nfrom keras.optimizers import RMSprop,Adam\nfrom keras.preprocessing.image import ImageDataGenerator\nfrom keras.applications import VGG16","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-12-24T11:01:45.360636Z","iopub.execute_input":"2021-12-24T11:01:45.360994Z","iopub.status.idle":"2021-12-24T11:01:48.86211Z","shell.execute_reply.started":"2021-12-24T11:01:45.360937Z","shell.execute_reply":"2021-12-24T11:01:48.860843Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Path","metadata":{}},{"cell_type":"code","source":"path = '../input/'\nos.listdir(path)","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:01:48.864114Z","iopub.execute_input":"2021-12-24T11:01:48.864675Z","iopub.status.idle":"2021-12-24T11:01:48.875622Z","shell.execute_reply.started":"2021-12-24T11:01:48.864422Z","shell.execute_reply":"2021-12-24T11:01:48.87314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Load Data","metadata":{}},{"cell_type":"code","source":"train_data = pd.read_csv(path+'labels.csv')\nsamp_subm = pd.read_csv(path+'sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:01:48.87756Z","iopub.execute_input":"2021-12-24T11:01:48.8838Z","iopub.status.idle":"2021-12-24T11:01:49.659093Z","shell.execute_reply.started":"2021-12-24T11:01:48.883708Z","shell.execute_reply":"2021-12-24T11:01:49.657728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Overview","metadata":{}},{"cell_type":"code","source":"print('Number train samples:', len(train_data))\nprint('Number train images:', len(os.listdir(path+'train/')))\nprint('Number test images:', len(os.listdir(path+'test/')))","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:01:49.660752Z","iopub.execute_input":"2021-12-24T11:01:49.661037Z","iopub.status.idle":"2021-12-24T11:01:50.165795Z","shell.execute_reply.started":"2021-12-24T11:01:49.66099Z","shell.execute_reply":"2021-12-24T11:01:50.164726Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:01:50.169084Z","iopub.execute_input":"2021-12-24T11:01:50.169381Z","iopub.status.idle":"2021-12-24T11:01:50.190761Z","shell.execute_reply.started":"2021-12-24T11:01:50.169329Z","shell.execute_reply":"2021-12-24T11:01:50.189548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# EDA","metadata":{}},{"cell_type":"markdown","source":"There are 120 breeds. Here you can see the distribution of the top 10: ","metadata":{}},{"cell_type":"code","source":"train_data['breed'].value_counts()[0:10]","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:01:50.194517Z","iopub.execute_input":"2021-12-24T11:01:50.194928Z","iopub.status.idle":"2021-12-24T11:01:50.206808Z","shell.execute_reply.started":"2021-12-24T11:01:50.19486Z","shell.execute_reply":"2021-12-24T11:01:50.205669Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Load Single Image\nWe plot the first image of of the train data.","metadata":{}},{"cell_type":"code","source":"id_ = train_data.loc[0, 'id']\nbreed = train_data.loc[0, 'breed']\nfile = id_+'.jpg'\nimg = cv2.imread(path+'train/'+file)\nprint('Shape:', img.shape)","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:01:50.208589Z","iopub.execute_input":"2021-12-24T11:01:50.209219Z","iopub.status.idle":"2021-12-24T11:01:50.243161Z","shell.execute_reply.started":"2021-12-24T11:01:50.208905Z","shell.execute_reply":"2021-12-24T11:01:50.242138Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(1, 1, figsize=(7, 7))\nax.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))\nax.set_xticklabels([])\nax.set_yticklabels([])\nax.set_title(breed)\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-12-24T11:01:50.245513Z","iopub.execute_input":"2021-12-24T11:01:50.246232Z","iopub.status.idle":"2021-12-24T11:01:50.558518Z","shell.execute_reply.started":"2021-12-24T11:01:50.24617Z","shell.execute_reply":"2021-12-24T11:01:50.557584Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Plot Examples\nWe plot example images of the breed top 10.","metadata":{}},{"cell_type":"code","source":"def plot_examples(category = 'scottish_deerhound'):\n    \"\"\" Plot 5 images of a given category \"\"\"\n    \n    fig, axs = plt.subplots(1, 5, figsize=(25, 20))\n    fig.subplots_adjust(hspace = .1, wspace=.1)\n    axs = axs.ravel()\n    temp = train_data[train_data['breed']==category].copy()\n    temp.index = range(len(temp.index))\n    for i in range(5):\n        id_ = temp.loc[i, 'id']\n        breed = temp.loc[i, 'breed']\n        file = id_+'.jpg'\n        img = cv2.imread(path+'train/'+file)\n        axs[i].imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))\n        axs[i].set_title(breed)\n        axs[i].set_xticklabels([])\n        axs[i].set_yticklabels([])\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:01:50.559753Z","iopub.execute_input":"2021-12-24T11:01:50.560212Z","iopub.status.idle":"2021-12-24T11:01:50.569244Z","shell.execute_reply.started":"2021-12-24T11:01:50.560167Z","shell.execute_reply":"2021-12-24T11:01:50.568118Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_examples()","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:01:50.570443Z","iopub.execute_input":"2021-12-24T11:01:50.570753Z","iopub.status.idle":"2021-12-24T11:01:51.588327Z","shell.execute_reply.started":"2021-12-24T11:01:50.570701Z","shell.execute_reply":"2021-12-24T11:01:51.586351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_examples('maltese_dog')","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:01:51.590383Z","iopub.execute_input":"2021-12-24T11:01:51.590741Z","iopub.status.idle":"2021-12-24T11:01:52.744957Z","shell.execute_reply.started":"2021-12-24T11:01:51.590684Z","shell.execute_reply":"2021-12-24T11:01:52.742969Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_examples('afghan_hound')","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:01:52.746649Z","iopub.execute_input":"2021-12-24T11:01:52.747318Z","iopub.status.idle":"2021-12-24T11:01:53.90682Z","shell.execute_reply.started":"2021-12-24T11:01:52.74724Z","shell.execute_reply":"2021-12-24T11:01:53.905179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Image Preprocessing\nAs we can see the images have different format: landscape or portrait. For the neural network we need a standard size. So we have to prepare the data. ","metadata":{}},{"cell_type":"code","source":"def image_preprocessing(image, image_size):\n    \"\"\" Image Preprocessing \"\"\"\n\n    # Load Image\n    readFlag=cv2.COLOR_BGR2GRAY\n    #image = np.asarray(bytearray(resp.read()), dtype=\"uint8\")\n    #image = cv2.imdecode(image, readFlag)\n    image_gray = cv2.cvtColor(image, readFlag)\n    \n    # Crop Image\n    mid_row = int(image_gray.shape[0]/2)\n    mid_col = int(image_gray.shape[1]/2)\n    if image_gray.shape[0]>image_gray.shape[1]:\n        image_cropped = image_gray[mid_row-mid_col:mid_row+mid_col,\n                                   0:image_gray.shape[1]]\n    else:\n        image_cropped = image_gray[0:image_gray.shape[0],\n                                   mid_col-mid_row:mid_col+mid_row]\n    \n    # Rescale Image\n    image_rescale = cv2.resize(image_cropped,\n                               dsize=(image_size, image_size),\n                               interpolation=cv2.INTER_AREA)\n    return image_rescale\n\ndef plot_befor_after(image):\n    \"\"\" Compare original and prepared image \"\"\"\n    \n    fig, axs = plt.subplots(1, 2, figsize=(15, 10))\n    fig.subplots_adjust(hspace = .1, wspace=.1)\n    axs = axs.ravel()\n    # Plot Original Image\n    axs[0].imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))\n    axs[0].set_title('original shape: '+str(image.shape))\n    # Image Preprocessing\n    image_rescale = image_preprocessing(image, image_size)\n    # Plot Prepared Image\n    axs[1].imshow(image_rescale, cmap='gray')\n    axs[1].set_title('rescaled shape: '+str(image_rescale.shape))\n    for i in range(2):\n        axs[i].set_xticklabels([])\n        axs[i].set_yticklabels([])\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:01:53.909074Z","iopub.execute_input":"2021-12-24T11:01:53.909413Z","iopub.status.idle":"2021-12-24T11:01:53.923346Z","shell.execute_reply.started":"2021-12-24T11:01:53.909355Z","shell.execute_reply":"2021-12-24T11:01:53.921637Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We set the image size:","metadata":{}},{"cell_type":"code","source":"image_size = 128","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:01:53.925913Z","iopub.execute_input":"2021-12-24T11:01:53.926303Z","iopub.status.idle":"2021-12-24T11:01:53.943385Z","shell.execute_reply.started":"2021-12-24T11:01:53.926244Z","shell.execute_reply":"2021-12-24T11:01:53.942179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Example Landscape:","metadata":{}},{"cell_type":"code","source":"row = 0\nid_ = train_data.loc[row, 'id']\nbreed = train_data.loc[row, 'breed']\nfile = id_+'.jpg'\nimage = cv2.imread(path+'train/'+file)\nprint('Shape:', image.shape)","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:01:53.945458Z","iopub.execute_input":"2021-12-24T11:01:53.945903Z","iopub.status.idle":"2021-12-24T11:01:53.969446Z","shell.execute_reply.started":"2021-12-24T11:01:53.945835Z","shell.execute_reply":"2021-12-24T11:01:53.967933Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_befor_after(image)","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:01:53.972152Z","iopub.execute_input":"2021-12-24T11:01:53.972936Z","iopub.status.idle":"2021-12-24T11:01:54.418431Z","shell.execute_reply.started":"2021-12-24T11:01:53.972869Z","shell.execute_reply":"2021-12-24T11:01:54.416938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Example Portrait:","metadata":{}},{"cell_type":"code","source":"row = 10\nid_ = train_data.loc[row, 'id']\nbreed = train_data.loc[row, 'breed']\nfile = id_+'.jpg'\nimage = cv2.imread(path+'train/'+file)\nprint('Shape:', image.shape)","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:01:54.420209Z","iopub.execute_input":"2021-12-24T11:01:54.420555Z","iopub.status.idle":"2021-12-24T11:01:54.437557Z","shell.execute_reply.started":"2021-12-24T11:01:54.420458Z","shell.execute_reply":"2021-12-24T11:01:54.436343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_befor_after(image)","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:01:54.439272Z","iopub.execute_input":"2021-12-24T11:01:54.439587Z","iopub.status.idle":"2021-12-24T11:01:54.943622Z","shell.execute_reply.started":"2021-12-24T11:01:54.43952Z","shell.execute_reply":"2021-12-24T11:01:54.942685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Read All Images","metadata":{}},{"cell_type":"code","source":"image_size = 128","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:01:54.945448Z","iopub.execute_input":"2021-12-24T11:01:54.94599Z","iopub.status.idle":"2021-12-24T11:01:54.950149Z","shell.execute_reply.started":"2021-12-24T11:01:54.945907Z","shell.execute_reply":"2021-12-24T11:01:54.949018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def prepare_data(path, data, image_size):\n    \"\"\" Read all images into a numpy array \"\"\"\n    \n    X = np.empty((len(data), image_size, image_size), dtype=np.uint8)\n    for row in data.index:\n        id_ = data.loc[row, 'id']\n        file = id_ + '.jpg'\n        image = cv2.imread(path+file)\n        image_rescaled = image_preprocessing(image, image_size)\n        X[row, :, :] = image_rescaled\n    X = X.astype('float32')/255\n    return X","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:01:54.952059Z","iopub.execute_input":"2021-12-24T11:01:54.952435Z","iopub.status.idle":"2021-12-24T11:01:54.968514Z","shell.execute_reply.started":"2021-12-24T11:01:54.952366Z","shell.execute_reply":"2021-12-24T11:01:54.96726Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = prepare_data(path+'train/', train_data, image_size)\nX_test = prepare_data(path+'test/', samp_subm, image_size)","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:01:54.970423Z","iopub.execute_input":"2021-12-24T11:01:54.970724Z","iopub.status.idle":"2021-12-24T11:05:05.040974Z","shell.execute_reply.started":"2021-12-24T11:01:54.970683Z","shell.execute_reply":"2021-12-24T11:05:05.038734Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Encode the labels","metadata":{}},{"cell_type":"code","source":"y_train = train_data['breed']\ny_train = pd.get_dummies(y_train)","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:05:05.042794Z","iopub.execute_input":"2021-12-24T11:05:05.04306Z","iopub.status.idle":"2021-12-24T11:05:05.050565Z","shell.execute_reply.started":"2021-12-24T11:05:05.043019Z","shell.execute_reply":"2021-12-24T11:05:05.049663Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Split Train Data ","metadata":{"execution":{"iopub.status.busy":"2021-12-24T09:36:37.396854Z","iopub.execute_input":"2021-12-24T09:36:37.39741Z"}}},{"cell_type":"code","source":"X_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size = 0.2, random_state=2021)","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:05:05.053038Z","iopub.execute_input":"2021-12-24T11:05:05.053471Z","iopub.status.idle":"2021-12-24T11:05:05.589834Z","shell.execute_reply.started":"2021-12-24T11:05:05.053403Z","shell.execute_reply":"2021-12-24T11:05:05.588814Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Shape train data:', X_train.shape)\nprint('Shape val data:', X_val.shape)","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:05:05.592815Z","iopub.execute_input":"2021-12-24T11:05:05.593189Z","iopub.status.idle":"2021-12-24T11:05:05.600105Z","shell.execute_reply.started":"2021-12-24T11:05:05.593131Z","shell.execute_reply":"2021-12-24T11:05:05.598597Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Reshape Data","metadata":{}},{"cell_type":"code","source":"X_train = X_train.reshape(-1,image_size,image_size,1)\nX_val = X_val.reshape(-1,image_size,image_size,1)\nX_test = X_test.reshape(-1,image_size,image_size,1)","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:05:05.601128Z","iopub.execute_input":"2021-12-24T11:05:05.601385Z","iopub.status.idle":"2021-12-24T11:05:05.615327Z","shell.execute_reply.started":"2021-12-24T11:05:05.601332Z","shell.execute_reply":"2021-12-24T11:05:05.613814Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Define Model","metadata":{}},{"cell_type":"code","source":"model = Sequential()\n\nmodel.add(Conv2D(filters=32, kernel_size = (3, 3), activation='relu', input_shape=(image_size, image_size, 1)))\nmodel.add(MaxPool2D((2, 2)))\n\nmodel.add(Conv2D(32, (3, 3),activation='relu'))\nmodel.add(MaxPool2D((2, 2)))\n\nmodel.add(Conv2D(64, (3, 3),activation='relu'))\nmodel.add(MaxPool2D((2, 2)))\n\n#model.add(Conv2D(128, (3, 3),activation='relu'))\n#model.add(MaxPool2D((2, 2)))\n\n#model.add(Conv2D(128, (3, 3),activation='relu'))\n#model.add(MaxPool2D((2, 2)))\n\nmodel.add(Flatten())\n\nmodel.add(Dense(120, activation = 'softmax'))","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:05:05.616764Z","iopub.execute_input":"2021-12-24T11:05:05.617088Z","iopub.status.idle":"2021-12-24T11:05:05.744223Z","shell.execute_reply.started":"2021-12-24T11:05:05.616999Z","shell.execute_reply":"2021-12-24T11:05:05.743159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = Sequential()\nmodel.add(Conv2D(filters = 32, kernel_size = (5,5),padding = 'Same', \n                 activation ='relu', input_shape = (image_size, image_size, 1)))\nmodel.add(Conv2D(filters = 32, kernel_size = (5,5),padding = 'Same', \n                 activation ='relu'))\nmodel.add(MaxPool2D(pool_size=(2,2)))\nmodel.add(Dropout(0.15))\n\n\nmodel.add(Conv2D(filters = 64, kernel_size = (3,3),padding = 'Same', \n                 activation ='relu'))\nmodel.add(Conv2D(filters = 64, kernel_size = (3,3),padding = 'Same', \n                 activation ='relu'))\nmodel.add(MaxPool2D(pool_size=(2,2), strides=(2,2)))\nmodel.add(Dropout(0.15))\n\n\nmodel.add(Flatten())\n#model.add(Dense(256, activation = \"relu\"))\n#model.add(Dropout(0.3))\nmodel.add(Dense(120, activation = \"softmax\"))","metadata":{"execution":{"iopub.status.busy":"2021-12-24T12:18:32.574701Z","iopub.execute_input":"2021-12-24T12:18:32.575047Z","iopub.status.idle":"2021-12-24T12:18:32.713412Z","shell.execute_reply.started":"2021-12-24T12:18:32.575006Z","shell.execute_reply":"2021-12-24T12:18:32.712053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#model.compile(optimizer = RMSprop(lr=0.0001), loss='categorical_crossentropy', metrics=['categorical_accuracy'])\nmodel.compile(optimizer=Adam(lr=1e-3), loss='categorical_crossentropy', metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2021-12-24T12:18:35.423347Z","iopub.execute_input":"2021-12-24T12:18:35.423808Z","iopub.status.idle":"2021-12-24T12:18:35.48282Z","shell.execute_reply.started":"2021-12-24T12:18:35.423741Z","shell.execute_reply":"2021-12-24T12:18:35.481752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2021-12-24T12:18:36.371334Z","iopub.execute_input":"2021-12-24T12:18:36.371799Z","iopub.status.idle":"2021-12-24T12:18:36.383271Z","shell.execute_reply.started":"2021-12-24T12:18:36.371756Z","shell.execute_reply":"2021-12-24T12:18:36.38232Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"epochs = 5\nbatch_size = 128","metadata":{"execution":{"iopub.status.busy":"2021-12-24T12:18:39.480611Z","iopub.execute_input":"2021-12-24T12:18:39.480952Z","iopub.status.idle":"2021-12-24T12:18:39.485209Z","shell.execute_reply.started":"2021-12-24T12:18:39.480894Z","shell.execute_reply":"2021-12-24T12:18:39.483909Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#history = model.fit_generator(datagen.flow(X_train, y_train, batch_size=batch_size),\n                              #epochs = epochs, validation_data = (X_val,y_val), steps_per_epoch=X_train.shape[0] / batch_size)\n\nhistory = model.fit(X_train, y_train,\n                    epochs=epochs,\n                    batch_size=batch_size,\n                    validation_data=(X_val, y_val))","metadata":{"execution":{"iopub.status.busy":"2021-12-24T12:18:44.896234Z","iopub.execute_input":"2021-12-24T12:18:44.897036Z","iopub.status.idle":"2021-12-24T13:13:13.774309Z","shell.execute_reply.started":"2021-12-24T12:18:44.896985Z","shell.execute_reply":"2021-12-24T13:13:13.773524Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Analyse Training","metadata":{}},{"cell_type":"code","source":"loss = history.history['loss']\nloss_val = history.history['val_loss']\nepochs = range(1, len(loss)+1)\nplt.plot(epochs, loss, 'bo', label='loss_train')\nplt.plot(epochs, loss_val, 'b', label='loss_val')\nplt.title('value of the loss function')\nplt.xlabel('epochs')\nplt.ylabel('value of the loss function')\nplt.legend()\nplt.grid()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:13:04.557055Z","iopub.execute_input":"2021-12-24T11:13:04.557431Z","iopub.status.idle":"2021-12-24T11:13:04.877767Z","shell.execute_reply.started":"2021-12-24T11:13:04.557372Z","shell.execute_reply":"2021-12-24T11:13:04.876773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"acc = history.history['acc']\nacc_val = history.history['val_acc']\nepochs = range(1, len(loss)+1)\nplt.plot(epochs, acc, 'bo', label='accuracy_train')\nplt.plot(epochs, acc_val, 'b', label='accuracy_val')\nplt.title('accuracy')\nplt.xlabel('epochs')\nplt.ylabel('value of accuracy')\nplt.legend()\nplt.grid()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:13:04.881231Z","iopub.execute_input":"2021-12-24T11:13:04.881717Z","iopub.status.idle":"2021-12-24T11:13:05.078446Z","shell.execute_reply.started":"2021-12-24T11:13:04.881466Z","shell.execute_reply":"2021-12-24T11:13:05.077602Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Predict Test Data","metadata":{}},{"cell_type":"code","source":"y_test = model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:13:05.080362Z","iopub.execute_input":"2021-12-24T11:13:05.080765Z","iopub.status.idle":"2021-12-24T11:13:33.795092Z","shell.execute_reply.started":"2021-12-24T11:13:05.080592Z","shell.execute_reply":"2021-12-24T11:13:33.793917Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"samp_subm[samp_subm.columns[1:]] = y_test","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:13:33.796658Z","iopub.execute_input":"2021-12-24T11:13:33.797288Z","iopub.status.idle":"2021-12-24T11:13:34.451029Z","shell.execute_reply.started":"2021-12-24T11:13:33.797121Z","shell.execute_reply":"2021-12-24T11:13:34.450081Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Export Data","metadata":{}},{"cell_type":"code","source":"samp_subm.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2021-12-24T11:13:34.452724Z","iopub.execute_input":"2021-12-24T11:13:34.453012Z","iopub.status.idle":"2021-12-24T11:13:37.410624Z","shell.execute_reply.started":"2021-12-24T11:13:34.452963Z","shell.execute_reply":"2021-12-24T11:13:37.409532Z"},"trusted":true},"execution_count":null,"outputs":[]}]}