{"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":"# 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":"2022-06-11T06:00:31.878253Z","iopub.execute_input":"2022-06-11T06:00:31.878762Z","iopub.status.idle":"2022-06-11T06:00:35.407112Z","shell.execute_reply.started":"2022-06-11T06:00:31.878648Z","shell.execute_reply":"2022-06-11T06:00:35.406187Z"},"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":"2022-06-11T06:00:35.409505Z","iopub.execute_input":"2022-06-11T06:00:35.409807Z","iopub.status.idle":"2022-06-11T06:00:35.419031Z","shell.execute_reply.started":"2022-06-11T06:00:35.409762Z","shell.execute_reply":"2022-06-11T06:00:35.418078Z"},"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":"2022-06-11T06:00:35.420239Z","iopub.execute_input":"2022-06-11T06:00:35.420786Z","iopub.status.idle":"2022-06-11T06:00:36.226727Z","shell.execute_reply.started":"2022-06-11T06:00:35.420711Z","shell.execute_reply":"2022-06-11T06:00:36.22577Z"},"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":"2022-06-11T06:00:36.228406Z","iopub.execute_input":"2022-06-11T06:00:36.228795Z","iopub.status.idle":"2022-06-11T06:00:36.892033Z","shell.execute_reply.started":"2022-06-11T06:00:36.228728Z","shell.execute_reply":"2022-06-11T06:00:36.89096Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-11T06:00:36.894943Z","iopub.execute_input":"2022-06-11T06:00:36.895592Z","iopub.status.idle":"2022-06-11T06:00:36.915157Z","shell.execute_reply.started":"2022-06-11T06:00:36.895263Z","shell.execute_reply":"2022-06-11T06:00:36.914398Z"},"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().head(10)","metadata":{"execution":{"iopub.status.busy":"2022-06-11T06:00:36.916964Z","iopub.execute_input":"2022-06-11T06:00:36.917299Z","iopub.status.idle":"2022-06-11T06:00:36.929586Z","shell.execute_reply.started":"2022-06-11T06:00:36.917236Z","shell.execute_reply":"2022-06-11T06:00:36.928482Z"},"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":"df = train_data.loc[5, 'id']\nbreed = train_data.loc[0, 'breed']\nfile = df+'.jpg'\nimg = cv2.imread(path+'train/'+file)\nprint('Shape:', img.shape)","metadata":{"execution":{"iopub.status.busy":"2022-06-11T06:00:36.931142Z","iopub.execute_input":"2022-06-11T06:00:36.931726Z","iopub.status.idle":"2022-06-11T06:00:36.964262Z","shell.execute_reply.started":"2022-06-11T06:00:36.931681Z","shell.execute_reply":"2022-06-11T06:00:36.963503Z"},"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":"2022-06-11T06:00:39.425342Z","iopub.execute_input":"2022-06-11T06:00:39.425914Z","iopub.status.idle":"2022-06-11T06:00:39.722022Z","shell.execute_reply.started":"2022-06-11T06:00:39.425868Z","shell.execute_reply":"2022-06-11T06:00:39.720652Z"},"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        df = temp.loc[i, 'id']\n        breed = temp.loc[i, 'breed']\n        file = df+'.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":"2022-06-11T06:00:40.067323Z","iopub.execute_input":"2022-06-11T06:00:40.067985Z","iopub.status.idle":"2022-06-11T06:00:40.078266Z","shell.execute_reply.started":"2022-06-11T06:00:40.067928Z","shell.execute_reply":"2022-06-11T06:00:40.077295Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_examples()","metadata":{"execution":{"iopub.status.busy":"2022-06-11T06:00:40.417142Z","iopub.execute_input":"2022-06-11T06:00:40.41755Z","iopub.status.idle":"2022-06-11T06:00:41.458087Z","shell.execute_reply.started":"2022-06-11T06:00:40.417486Z","shell.execute_reply":"2022-06-11T06:00:41.457154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_examples('maltese_dog')","metadata":{"execution":{"iopub.status.busy":"2022-06-11T06:00:43.647545Z","iopub.execute_input":"2022-06-11T06:00:43.64787Z","iopub.status.idle":"2022-06-11T06:00:44.758618Z","shell.execute_reply.started":"2022-06-11T06:00:43.647822Z","shell.execute_reply":"2022-06-11T06:00:44.757764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_examples('pomeranian')","metadata":{"execution":{"iopub.status.busy":"2022-06-11T06:00:46.582029Z","iopub.execute_input":"2022-06-11T06:00:46.582392Z","iopub.status.idle":"2022-06-11T06:00:47.576158Z","shell.execute_reply.started":"2022-06-11T06:00:46.582331Z","shell.execute_reply":"2022-06-11T06:00:47.575314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_examples('afghan_hound')","metadata":{"execution":{"iopub.status.busy":"2022-06-11T06:00:47.577811Z","iopub.execute_input":"2022-06-11T06:00:47.578309Z","iopub.status.idle":"2022-06-11T06:00:48.633189Z","shell.execute_reply.started":"2022-06-11T06:00:47.578247Z","shell.execute_reply":"2022-06-11T06:00:48.632368Z"},"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":"2022-06-11T06:00:48.635286Z","iopub.execute_input":"2022-06-11T06:00:48.635589Z","iopub.status.idle":"2022-06-11T06:00:48.649836Z","shell.execute_reply.started":"2022-06-11T06:00:48.635537Z","shell.execute_reply":"2022-06-11T06:00:48.64904Z"},"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":"2022-06-11T06:00:53.208277Z","iopub.execute_input":"2022-06-11T06:00:53.20867Z","iopub.status.idle":"2022-06-11T06:00:53.213442Z","shell.execute_reply.started":"2022-06-11T06:00:53.208606Z","shell.execute_reply":"2022-06-11T06:00:53.212347Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Example Landscape:","metadata":{}},{"cell_type":"code","source":"row = 6\ndf = train_data.loc[row, 'id']\nbreed = train_data.loc[row, 'breed']\nfile = df+'.jpg'\nimage = cv2.imread(path+'train/'+file)\nprint('Shape:', image.shape)","metadata":{"execution":{"iopub.status.busy":"2022-06-11T06:00:57.28525Z","iopub.execute_input":"2022-06-11T06:00:57.285871Z","iopub.status.idle":"2022-06-11T06:00:57.306276Z","shell.execute_reply.started":"2022-06-11T06:00:57.285823Z","shell.execute_reply":"2022-06-11T06:00:57.304992Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_befor_after(image)","metadata":{"execution":{"iopub.status.busy":"2022-06-11T06:00:57.725296Z","iopub.execute_input":"2022-06-11T06:00:57.725909Z","iopub.status.idle":"2022-06-11T06:00:58.178375Z","shell.execute_reply.started":"2022-06-11T06:00:57.725857Z","shell.execute_reply":"2022-06-11T06:00:58.177473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Example Portrait:","metadata":{}},{"cell_type":"code","source":"row = 10\ndf = train_data.loc[row, 'id']\nbreed = train_data.loc[row, 'breed']\nfile = df+'.jpg'\nimage = cv2.imread(path+'train/'+file)\nprint('Shape:', image.shape)","metadata":{"execution":{"iopub.status.busy":"2022-06-11T06:01:00.705097Z","iopub.execute_input":"2022-06-11T06:01:00.705399Z","iopub.status.idle":"2022-06-11T06:01:00.723126Z","shell.execute_reply.started":"2022-06-11T06:01:00.705351Z","shell.execute_reply":"2022-06-11T06:01:00.722097Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_befor_after(image)","metadata":{"execution":{"iopub.status.busy":"2022-06-11T06:01:00.915749Z","iopub.execute_input":"2022-06-11T06:01:00.916206Z","iopub.status.idle":"2022-06-11T06:01:01.398796Z","shell.execute_reply.started":"2022-06-11T06:01:00.916166Z","shell.execute_reply":"2022-06-11T06:01:01.397761Z"},"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":"2022-06-11T06:01:03.745193Z","iopub.execute_input":"2022-06-11T06:01:03.745524Z","iopub.status.idle":"2022-06-11T06:01:03.749632Z","shell.execute_reply.started":"2022-06-11T06:01:03.745446Z","shell.execute_reply":"2022-06-11T06:01:03.748361Z"},"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        df = data.loc[row, 'id']\n        file = df + '.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":"2022-06-11T06:01:05.055449Z","iopub.execute_input":"2022-06-11T06:01:05.056034Z","iopub.status.idle":"2022-06-11T06:01:05.063607Z","shell.execute_reply.started":"2022-06-11T06:01:05.055986Z","shell.execute_reply":"2022-06-11T06:01:05.062654Z"},"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":"2022-06-11T06:01:07.68417Z","iopub.execute_input":"2022-06-11T06:01:07.684517Z","iopub.status.idle":"2022-06-11T06:05:02.6962Z","shell.execute_reply.started":"2022-06-11T06:01:07.68445Z","shell.execute_reply":"2022-06-11T06:05:02.695337Z"},"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":"2022-06-11T06:05:48.127901Z","iopub.execute_input":"2022-06-11T06:05:48.128357Z","iopub.status.idle":"2022-06-11T06:05:48.13651Z","shell.execute_reply.started":"2022-06-11T06:05:48.128314Z","shell.execute_reply":"2022-06-11T06:05:48.135616Z"},"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.3, random_state=100)","metadata":{"execution":{"iopub.status.busy":"2022-06-11T06:06:02.668825Z","iopub.execute_input":"2022-06-11T06:06:02.669354Z","iopub.status.idle":"2022-06-11T06:06:03.184337Z","shell.execute_reply.started":"2022-06-11T06:06:02.669288Z","shell.execute_reply":"2022-06-11T06:06:03.183534Z"},"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":"2022-06-11T06:06:05.356977Z","iopub.execute_input":"2022-06-11T06:06:05.3575Z","iopub.status.idle":"2022-06-11T06:06:05.362533Z","shell.execute_reply.started":"2022-06-11T06:06:05.357405Z","shell.execute_reply":"2022-06-11T06:06:05.361744Z"},"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":"2022-06-11T06:06:14.530971Z","iopub.execute_input":"2022-06-11T06:06:14.531732Z","iopub.status.idle":"2022-06-11T06:06:14.537007Z","shell.execute_reply.started":"2022-06-11T06:06:14.53168Z","shell.execute_reply":"2022-06-11T06:06:14.536349Z"},"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\nmodel.add(Conv2D(128, (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\nmodel.add(Flatten())\n\nmodel.add(Dense(120, activation = 'softmax'))","metadata":{"execution":{"iopub.status.busy":"2022-06-11T06:06:18.997234Z","iopub.execute_input":"2022-06-11T06:06:18.997888Z","iopub.status.idle":"2022-06-11T06:06:19.149068Z","shell.execute_reply.started":"2022-06-11T06:06:18.997831Z","shell.execute_reply":"2022-06-11T06:06:19.148247Z"},"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":"2022-06-11T06:06:21.997307Z","iopub.execute_input":"2022-06-11T06:06:21.997654Z","iopub.status.idle":"2022-06-11T06:06:22.134196Z","shell.execute_reply.started":"2022-06-11T06:06:21.9976Z","shell.execute_reply":"2022-06-11T06:06:22.133221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nmodel.compile(optimizer=Adam(lr=1e-3), loss='categorical_crossentropy', metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2022-06-11T06:06:24.63021Z","iopub.execute_input":"2022-06-11T06:06:24.630566Z","iopub.status.idle":"2022-06-11T06:06:24.675348Z","shell.execute_reply.started":"2022-06-11T06:06:24.630506Z","shell.execute_reply":"2022-06-11T06:06:24.674592Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2022-06-11T06:06:29.067141Z","iopub.execute_input":"2022-06-11T06:06:29.067572Z","iopub.status.idle":"2022-06-11T06:06:29.075806Z","shell.execute_reply.started":"2022-06-11T06:06:29.067531Z","shell.execute_reply":"2022-06-11T06:06:29.074612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"epochs = 25\nbatch_size = 128","metadata":{"execution":{"iopub.status.busy":"2022-06-11T06:18:21.644893Z","iopub.execute_input":"2022-06-11T06:18:21.645233Z","iopub.status.idle":"2022-06-11T06:18:21.651624Z","shell.execute_reply.started":"2022-06-11T06:18:21.645184Z","shell.execute_reply":"2022-06-11T06:18:21.650845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# training the model\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":"2022-06-11T06:18:24.335298Z","iopub.execute_input":"2022-06-11T06:18:24.33584Z","iopub.status.idle":"2022-06-11T10:36:44.79437Z","shell.execute_reply.started":"2022-06-11T06:18:24.335774Z","shell.execute_reply":"2022-06-11T10:36:44.792142Z"},"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":"2022-06-11T10:38:30.122773Z","iopub.execute_input":"2022-06-11T10:38:30.123254Z","iopub.status.idle":"2022-06-11T10:38:30.406906Z","shell.execute_reply.started":"2022-06-11T10:38:30.123185Z","shell.execute_reply":"2022-06-11T10:38:30.40572Z"},"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":"2022-06-11T10:38:32.439898Z","iopub.execute_input":"2022-06-11T10:38:32.440385Z","iopub.status.idle":"2022-06-11T10:38:32.630826Z","shell.execute_reply.started":"2022-06-11T10:38:32.44018Z","shell.execute_reply":"2022-06-11T10:38:32.629795Z"},"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":"2022-06-11T10:38:35.899172Z","iopub.execute_input":"2022-06-11T10:38:35.899835Z","iopub.status.idle":"2022-06-11T10:41:30.795668Z","shell.execute_reply.started":"2022-06-11T10:38:35.899768Z","shell.execute_reply":"2022-06-11T10:41:30.794764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test","metadata":{"execution":{"iopub.status.busy":"2022-06-11T10:42:08.890535Z","iopub.execute_input":"2022-06-11T10:42:08.890889Z","iopub.status.idle":"2022-06-11T10:42:08.899339Z","shell.execute_reply.started":"2022-06-11T10:42:08.890842Z","shell.execute_reply":"2022-06-11T10:42:08.898363Z"},"trusted":true},"execution_count":null,"outputs":[]}]}