{"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":"from keras import layers\nfrom keras.datasets import mnist\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom sklearn.preprocessing import LabelEncoder\nfrom keras.utils import to_categorical\nimport keras\nfrom sklearn.model_selection import train_test_split\nfrom keras.models import Sequential,Input,Model\nfrom keras.layers import Dense, Dropout, Flatten\nfrom keras.layers import Conv2D, MaxPooling2D\nfrom keras.layers.normalization import BatchNormalization\nfrom keras.layers.advanced_activations import LeakyReLU\nfrom sklearn.metrics import classification_report\n\n# This is the size of our encoded representations\nencoding_dim = 32  # 32 floats -> compression of factor 24.5, assuming the input is 784 floats\n\n# This is our input image\ninput_img = keras.Input(shape=(784,))\n# \"encoded\" is the encoded representation of the input\nencoded = layers.Dense(encoding_dim, activation='relu')(input_img)\n# \"decoded\" is the lossy reconstruction of the input\ndecoded = layers.Dense(784, activation='sigmoid')(encoded)\n\n# This model maps an input to its reconstruction\nautoencoder = keras.Model(input_img, decoded)","metadata":{"execution":{"iopub.status.busy":"2021-08-04T07:01:04.676693Z","iopub.execute_input":"2021-08-04T07:01:04.677061Z","iopub.status.idle":"2021-08-04T07:01:04.706837Z","shell.execute_reply.started":"2021-08-04T07:01:04.677029Z","shell.execute_reply":"2021-08-04T07:01:04.705774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# This model maps an input to its encoded representation\nencoder = keras.Model(input_img, encoded)","metadata":{"execution":{"iopub.status.busy":"2021-08-04T07:01:04.749875Z","iopub.execute_input":"2021-08-04T07:01:04.750238Z","iopub.status.idle":"2021-08-04T07:01:04.758283Z","shell.execute_reply.started":"2021-08-04T07:01:04.750208Z","shell.execute_reply":"2021-08-04T07:01:04.757050Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# This is our encoded (32-dimensional) input\nencoded_input = keras.Input(shape=(encoding_dim,))\n# Retrieve the last layer of the autoencoder model\ndecoder_layer = autoencoder.layers[-1]\n# Create the decoder model\ndecoder = keras.Model(encoded_input, decoder_layer(encoded_input))","metadata":{"execution":{"iopub.status.busy":"2021-08-04T07:01:05.001437Z","iopub.execute_input":"2021-08-04T07:01:05.001786Z","iopub.status.idle":"2021-08-04T07:01:05.016680Z","shell.execute_reply.started":"2021-08-04T07:01:05.001755Z","shell.execute_reply":"2021-08-04T07:01:05.015672Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"autoencoder.compile(optimizer='adam', loss='binary_crossentropy')","metadata":{"execution":{"iopub.status.busy":"2021-08-04T07:01:05.079403Z","iopub.execute_input":"2021-08-04T07:01:05.079748Z","iopub.status.idle":"2021-08-04T07:01:05.092424Z","shell.execute_reply.started":"2021-08-04T07:01:05.079717Z","shell.execute_reply":"2021-08-04T07:01:05.091534Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(x_train, train_y), (x_test, test_y) = mnist.load_data()","metadata":{"execution":{"iopub.status.busy":"2021-08-04T07:01:05.094033Z","iopub.execute_input":"2021-08-04T07:01:05.094312Z","iopub.status.idle":"2021-08-04T07:01:05.414927Z","shell.execute_reply.started":"2021-08-04T07:01:05.094284Z","shell.execute_reply":"2021-08-04T07:01:05.414014Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train = x_train.astype('float32') / 255.\nx_test = x_test.astype('float32') / 255.\nx_train = x_train.reshape((len(x_train), np.prod(x_train.shape[1:])))\nx_test = x_test.reshape((len(x_test), np.prod(x_test.shape[1:])))\nprint(x_train.shape)\nprint(x_test.shape)","metadata":{"execution":{"iopub.status.busy":"2021-08-04T07:01:05.416851Z","iopub.execute_input":"2021-08-04T07:01:05.417279Z","iopub.status.idle":"2021-08-04T07:01:05.499681Z","shell.execute_reply.started":"2021-08-04T07:01:05.417237Z","shell.execute_reply":"2021-08-04T07:01:05.498484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"autoencoder.fit(x_train, x_train,\n                epochs=50,\n                batch_size=256,\n                shuffle=True,\n                validation_data=(x_test, x_test))","metadata":{"execution":{"iopub.status.busy":"2021-08-04T07:01:05.501485Z","iopub.execute_input":"2021-08-04T07:01:05.501906Z","iopub.status.idle":"2021-08-04T07:02:31.629517Z","shell.execute_reply.started":"2021-08-04T07:01:05.501862Z","shell.execute_reply":"2021-08-04T07:02:31.628477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_encoded_imgs = encoder.predict(x_train)\ntest_encoded_imgs = encoder.predict(x_test)\n\ntrain_decoded_imgs = decoder.predict(train_encoded_imgs)\ntest_decoded_imgs = decoder.predict(test_encoded_imgs)","metadata":{"execution":{"iopub.status.busy":"2021-08-04T07:02:31.630885Z","iopub.execute_input":"2021-08-04T07:02:31.631265Z","iopub.status.idle":"2021-08-04T07:02:34.995943Z","shell.execute_reply.started":"2021-08-04T07:02:31.631233Z","shell.execute_reply":"2021-08-04T07:02:34.995173Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"n = 10  # How many digits we will display\nplt.figure(figsize=(20, 4))\nfor i in range(n):\n    # Display original\n    ax = plt.subplot(2, n, i + 1)\n    plt.imshow(x_test[i].reshape(28, 28))\n    plt.gray()\n    ax.get_xaxis().set_visible(False)\n    ax.get_yaxis().set_visible(False)\n\n    # Display reconstruction\n    ax = plt.subplot(2, n, i + 1 + n)\n    plt.imshow(test_decoded_imgs[i].reshape(28, 28))\n    plt.gray()\n    ax.get_xaxis().set_visible(False)\n    ax.get_yaxis().set_visible(False)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-08-04T07:02:34.997227Z","iopub.execute_input":"2021-08-04T07:02:34.997719Z","iopub.status.idle":"2021-08-04T07:02:35.970656Z","shell.execute_reply.started":"2021-08-04T07:02:34.997688Z","shell.execute_reply":"2021-08-04T07:02:35.969835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_X = train_decoded_imgs[:].reshape(-1, 28,28, 1)\ntest_X = test_decoded_imgs[:].reshape(-1, 28,28, 1)\ntrain_X.shape, test_X.shape","metadata":{"execution":{"iopub.status.busy":"2021-08-04T07:02:35.972407Z","iopub.execute_input":"2021-08-04T07:02:35.972841Z","iopub.status.idle":"2021-08-04T07:02:35.980495Z","shell.execute_reply.started":"2021-08-04T07:02:35.972808Z","shell.execute_reply":"2021-08-04T07:02:35.979603Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_Y_one_hot = to_categorical(train_y)\ntest_Y_one_hot = to_categorical(test_y)\n\nprint('Original label:', train_y[0])\nprint('After conversion to one-hot:', train_Y_one_hot[0])","metadata":{"execution":{"iopub.status.busy":"2021-08-04T07:02:35.981799Z","iopub.execute_input":"2021-08-04T07:02:35.982102Z","iopub.status.idle":"2021-08-04T07:02:35.996425Z","shell.execute_reply.started":"2021-08-04T07:02:35.982074Z","shell.execute_reply":"2021-08-04T07:02:35.995685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_X,valid_X,train_label,valid_label = train_test_split(train_X, train_Y_one_hot, test_size=0.2, random_state=13)","metadata":{"execution":{"iopub.status.busy":"2021-08-04T07:02:35.997566Z","iopub.execute_input":"2021-08-04T07:02:35.997851Z","iopub.status.idle":"2021-08-04T07:02:36.074130Z","shell.execute_reply.started":"2021-08-04T07:02:35.997824Z","shell.execute_reply":"2021-08-04T07:02:36.073052Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_X","metadata":{"execution":{"iopub.status.busy":"2021-08-04T07:03:44.157622Z","iopub.execute_input":"2021-08-04T07:03:44.158231Z","iopub.status.idle":"2021-08-04T07:03:44.172493Z","shell.execute_reply.started":"2021-08-04T07:03:44.158196Z","shell.execute_reply":"2021-08-04T07:03:44.171354Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_X.shape,valid_X.shape,train_label.shape,valid_label.shape","metadata":{"execution":{"iopub.status.busy":"2021-08-04T06:14:34.643841Z","iopub.execute_input":"2021-08-04T06:14:34.644152Z","iopub.status.idle":"2021-08-04T06:14:34.649575Z","shell.execute_reply.started":"2021-08-04T06:14:34.644125Z","shell.execute_reply":"2021-08-04T06:14:34.648863Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"batch_size = 64\nepochs = 20\nnum_classes = 10","metadata":{"execution":{"iopub.status.busy":"2021-08-04T06:14:34.650601Z","iopub.execute_input":"2021-08-04T06:14:34.651059Z","iopub.status.idle":"2021-08-04T06:14:34.662582Z","shell.execute_reply.started":"2021-08-04T06:14:34.651030Z","shell.execute_reply":"2021-08-04T06:14:34.661643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_ = Sequential()\nmodel_.add(Conv2D(32, kernel_size=(3, 3),activation='linear',input_shape=(28,28,1),padding='same'))\nmodel_.add(LeakyReLU(alpha=0.1))\nmodel_.add(MaxPooling2D((2, 2),padding='same'))\nmodel_.add(Conv2D(64, (3, 3), activation='linear',padding='same'))\nmodel_.add(LeakyReLU(alpha=0.1))\nmodel_.add(MaxPooling2D(pool_size=(2, 2),padding='same'))\nmodel_.add(Conv2D(128, (3, 3), activation='linear',padding='same'))\nmodel_.add(LeakyReLU(alpha=0.1))                  \nmodel_.add(MaxPooling2D(pool_size=(2, 2),padding='same'))\nmodel_.add(Flatten())\nmodel_.add(Dense(128, activation='linear'))\nmodel_.add(LeakyReLU(alpha=0.1))                  \nmodel_.add(Dense(num_classes, activation='softmax'))","metadata":{"execution":{"iopub.status.busy":"2021-08-04T06:14:34.663657Z","iopub.execute_input":"2021-08-04T06:14:34.663987Z","iopub.status.idle":"2021-08-04T06:14:34.753858Z","shell.execute_reply.started":"2021-08-04T06:14:34.663935Z","shell.execute_reply":"2021-08-04T06:14:34.753048Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_.summary()","metadata":{"execution":{"iopub.status.busy":"2021-08-04T06:14:34.754887Z","iopub.execute_input":"2021-08-04T06:14:34.755313Z","iopub.status.idle":"2021-08-04T06:14:34.766103Z","shell.execute_reply.started":"2021-08-04T06:14:34.755285Z","shell.execute_reply":"2021-08-04T06:14:34.764807Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_.compile(loss=keras.losses.categorical_crossentropy, optimizer=keras.optimizers.Adam(),metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2021-08-04T06:14:34.767727Z","iopub.execute_input":"2021-08-04T06:14:34.768182Z","iopub.status.idle":"2021-08-04T06:14:34.782418Z","shell.execute_reply.started":"2021-08-04T06:14:34.768137Z","shell.execute_reply":"2021-08-04T06:14:34.781328Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mnist_train = model_.fit(train_X, train_label, batch_size=batch_size,epochs=epochs,verbose=1,validation_data=(valid_X, valid_label))","metadata":{"execution":{"iopub.status.busy":"2021-08-04T06:14:34.785710Z","iopub.execute_input":"2021-08-04T06:14:34.786057Z","iopub.status.idle":"2021-08-04T06:28:24.624424Z","shell.execute_reply.started":"2021-08-04T06:14:34.786022Z","shell.execute_reply":"2021-08-04T06:28:24.623494Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_eval = model_.evaluate(test_X, test_Y_one_hot, verbose=0)\nprint(test_eval)","metadata":{"execution":{"iopub.status.busy":"2021-08-04T06:28:24.625516Z","iopub.execute_input":"2021-08-04T06:28:24.625778Z","iopub.status.idle":"2021-08-04T06:28:27.624449Z","shell.execute_reply.started":"2021-08-04T06:28:24.625753Z","shell.execute_reply":"2021-08-04T06:28:27.623701Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy = mnist_train.history['accuracy']\nval_accuracy = mnist_train.history['val_accuracy']\nloss = mnist_train.history['loss']\nval_loss = mnist_train.history['val_loss']\nepochs = range(len(accuracy))\nplt.plot(epochs, accuracy, 'go', label='Training accuracy', alpha = 0.5)\nplt.plot(epochs, val_accuracy, 'g', label='Validation accuracy')\nplt.title('Training and validation accuracy')\nplt.legend()\nplt.figure()\nplt.plot(epochs, loss, 'go', label='Training loss', alpha = 0.5)\nplt.plot(epochs, val_loss, 'g', label='Validation loss')\nplt.title('Training and validation loss')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-08-04T06:28:27.625460Z","iopub.execute_input":"2021-08-04T06:28:27.625722Z","iopub.status.idle":"2021-08-04T06:28:28.057907Z","shell.execute_reply.started":"2021-08-04T06:28:27.625695Z","shell.execute_reply":"2021-08-04T06:28:28.056920Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"batch_size = 64\nepochs = 20\nnum_classes = 10","metadata":{"execution":{"iopub.status.busy":"2021-08-04T06:42:04.567803Z","iopub.execute_input":"2021-08-04T06:42:04.568189Z","iopub.status.idle":"2021-08-04T06:42:04.572625Z","shell.execute_reply.started":"2021-08-04T06:42:04.568156Z","shell.execute_reply":"2021-08-04T06:42:04.571790Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_ = Sequential()\nmodel_.add(Conv2D(32, kernel_size=(3, 3),activation='linear',padding='same',input_shape=(28,28,1)))\nmodel_.add(LeakyReLU(alpha=0.1))\nmodel_.add(MaxPooling2D((2, 2),padding='same'))\nmodel_.add(Dropout(0.25))\nmodel_.add(Conv2D(64, (3, 3), activation='linear',padding='same'))\nmodel_.add(LeakyReLU(alpha=0.1))\nmodel_.add(MaxPooling2D(pool_size=(2, 2),padding='same'))\nmodel_.add(Dropout(0.25))\nmodel_.add(Conv2D(128, (3, 3), activation='linear',padding='same'))\nmodel_.add(LeakyReLU(alpha=0.1))                  \nmodel_.add(MaxPooling2D(pool_size=(2, 2),padding='same'))\nmodel_.add(Dropout(0.4))\nmodel_.add(Flatten())\nmodel_.add(Dense(128, activation='linear'))\nmodel_.add(LeakyReLU(alpha=0.1))           \nmodel_.add(Dropout(0.3))\nmodel_.add(Dense(num_classes, activation='softmax'))","metadata":{"execution":{"iopub.status.busy":"2021-08-04T06:42:06.610195Z","iopub.execute_input":"2021-08-04T06:42:06.610859Z","iopub.status.idle":"2021-08-04T06:42:06.708268Z","shell.execute_reply.started":"2021-08-04T06:42:06.610822Z","shell.execute_reply":"2021-08-04T06:42:06.707195Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_.summary()","metadata":{"execution":{"iopub.status.busy":"2021-08-04T06:42:09.219563Z","iopub.execute_input":"2021-08-04T06:42:09.220026Z","iopub.status.idle":"2021-08-04T06:42:09.233044Z","shell.execute_reply.started":"2021-08-04T06:42:09.219985Z","shell.execute_reply":"2021-08-04T06:42:09.229709Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_.compile(loss=keras.losses.categorical_crossentropy, optimizer=keras.optimizers.Adam(),metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2021-08-04T06:42:15.203450Z","iopub.execute_input":"2021-08-04T06:42:15.203806Z","iopub.status.idle":"2021-08-04T06:42:15.217064Z","shell.execute_reply.started":"2021-08-04T06:42:15.203774Z","shell.execute_reply":"2021-08-04T06:42:15.215814Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mnist_train_dropout = model_.fit(train_X, train_label, batch_size=batch_size,epochs=epochs,verbose=1,validation_data=(valid_X, valid_label))","metadata":{"execution":{"iopub.status.busy":"2021-08-04T06:42:19.320539Z","iopub.execute_input":"2021-08-04T06:42:19.320909Z","iopub.status.idle":"2021-08-04T06:57:09.394920Z","shell.execute_reply.started":"2021-08-04T06:42:19.320877Z","shell.execute_reply":"2021-08-04T06:57:09.394071Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_eval = model_.evaluate(test_X, test_Y_one_hot, verbose=0)\nprint(test_eval)","metadata":{"execution":{"iopub.status.busy":"2021-08-04T06:57:09.396418Z","iopub.execute_input":"2021-08-04T06:57:09.396819Z","iopub.status.idle":"2021-08-04T06:57:12.411654Z","shell.execute_reply.started":"2021-08-04T06:57:09.396790Z","shell.execute_reply":"2021-08-04T06:57:12.410853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy = mnist_train_dropout.history['accuracy']\nval_accuracy = mnist_train_dropout.history['val_accuracy']\nloss = mnist_train_dropout.history['loss']\nval_loss = mnist_train_dropout.history['val_loss']\nepochs = range(len(accuracy))\nplt.plot(epochs, accuracy, 'go', label='Training accuracy', alpha = 0.5)\nplt.plot(epochs, val_accuracy, 'g', label='Validation accuracy')\nplt.title('Training and validation accuracy')\nplt.legend()\nplt.figure()\nplt.plot(epochs, loss, 'go', label='Training loss', alpha = 0.5)\nplt.plot(epochs, val_loss, 'g', label='Validation loss')\nplt.title('Training and validation loss')\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-08-04T06:57:18.106100Z","iopub.execute_input":"2021-08-04T06:57:18.106640Z","iopub.status.idle":"2021-08-04T06:57:18.474342Z","shell.execute_reply.started":"2021-08-04T06:57:18.106596Z","shell.execute_reply":"2021-08-04T06:57:18.473569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted_classes = model_.predict(test_X)\npredicted_classes = np.argmax(np.round(predicted_classes),axis=1)\n\ntarget_names = [\"Class {}\".format(i) for i in range(num_classes)]\nprint(classification_report(test_y, predicted_classes, target_names=target_names))","metadata":{"execution":{"iopub.status.busy":"2021-08-04T06:57:24.335514Z","iopub.execute_input":"2021-08-04T06:57:24.336074Z","iopub.status.idle":"2021-08-04T06:57:27.341541Z","shell.execute_reply.started":"2021-08-04T06:57:24.336021Z","shell.execute_reply":"2021-08-04T06:57:27.340360Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_.save(\"model_mnist.h5py\")","metadata":{"execution":{"iopub.status.busy":"2021-08-04T06:41:44.810226Z","iopub.status.idle":"2021-08-04T06:41:44.810791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd","metadata":{"execution":{"iopub.status.busy":"2021-08-04T06:57:36.046783Z","iopub.execute_input":"2021-08-04T06:57:36.047409Z","iopub.status.idle":"2021-08-04T06:57:36.051420Z","shell.execute_reply.started":"2021-08-04T06:57:36.047372Z","shell.execute_reply":"2021-08-04T06:57:36.050433Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"testing_data = pd.read_csv('../input/digit-recognizer/test.csv')","metadata":{"execution":{"iopub.status.busy":"2021-08-04T06:58:14.009017Z","iopub.execute_input":"2021-08-04T06:58:14.009369Z","iopub.status.idle":"2021-08-04T06:58:16.246093Z","shell.execute_reply.started":"2021-08-04T06:58:14.009339Z","shell.execute_reply":"2021-08-04T06:58:16.245115Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"testing_data = np.array(testing_data).reshape(-1,28,28,1);","metadata":{"execution":{"iopub.status.busy":"2021-08-04T07:05:19.099348Z","iopub.execute_input":"2021-08-04T07:05:19.099702Z","iopub.status.idle":"2021-08-04T07:05:19.217547Z","shell.execute_reply.started":"2021-08-04T07:05:19.099669Z","shell.execute_reply":"2021-08-04T07:05:19.216532Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted_classes = model_.predict(testing_data)\npredicted_classes = np.argmax(np.round(predicted_classes),axis=1)","metadata":{"execution":{"iopub.status.busy":"2021-08-04T07:10:53.211754Z","iopub.execute_input":"2021-08-04T07:10:53.212122Z","iopub.status.idle":"2021-08-04T07:11:01.947890Z","shell.execute_reply.started":"2021-08-04T07:10:53.212090Z","shell.execute_reply":"2021-08-04T07:11:01.946789Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted_classes = pd.DataFrame(predicted_classes, columns=['Label'])","metadata":{"execution":{"iopub.status.busy":"2021-08-04T07:11:30.089996Z","iopub.execute_input":"2021-08-04T07:11:30.090367Z","iopub.status.idle":"2021-08-04T07:11:30.095282Z","shell.execute_reply.started":"2021-08-04T07:11:30.090331Z","shell.execute_reply":"2021-08-04T07:11:30.094269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted_classes['ImageId'] = [i for i in range(1, len(predicted_classes.Label)+1)]","metadata":{"execution":{"iopub.status.busy":"2021-08-04T07:12:55.026771Z","iopub.execute_input":"2021-08-04T07:12:55.027191Z","iopub.status.idle":"2021-08-04T07:12:55.049543Z","shell.execute_reply.started":"2021-08-04T07:12:55.027156Z","shell.execute_reply":"2021-08-04T07:12:55.048405Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"columns_titles = [\"ImageId\",\"Label\"]\npredicted_classes = predicted_classes.reindex(columns=columns_titles)","metadata":{"execution":{"iopub.status.busy":"2021-08-04T07:14:28.709230Z","iopub.execute_input":"2021-08-04T07:14:28.709629Z","iopub.status.idle":"2021-08-04T07:14:28.717285Z","shell.execute_reply.started":"2021-08-04T07:14:28.709595Z","shell.execute_reply":"2021-08-04T07:14:28.716110Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted_classes","metadata":{"execution":{"iopub.status.busy":"2021-08-04T07:14:36.228877Z","iopub.execute_input":"2021-08-04T07:14:36.229252Z","iopub.status.idle":"2021-08-04T07:14:36.242821Z","shell.execute_reply.started":"2021-08-04T07:14:36.229222Z","shell.execute_reply":"2021-08-04T07:14:36.241669Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted_classes.to_csv('submission.csv', index = None)","metadata":{"execution":{"iopub.status.busy":"2021-08-04T07:15:45.219844Z","iopub.execute_input":"2021-08-04T07:15:45.220208Z","iopub.status.idle":"2021-08-04T07:15:45.276411Z","shell.execute_reply.started":"2021-08-04T07:15:45.220176Z","shell.execute_reply":"2021-08-04T07:15:45.275599Z"},"trusted":true},"execution_count":null,"outputs":[]}]}