{"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":"# **Deep Learning**\n\n\n---\n\n","metadata":{"id":"LVpAJ7EcFNr4","papermill":{"duration":0.021493,"end_time":"2022-04-25T16:45:25.279837","exception":false,"start_time":"2022-04-25T16:45:25.258344","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":">## Kaggle: Digit Recognizer (Digit Recognizer )\n\n---","metadata":{"id":"iITRqUNHFZAA","papermill":{"duration":0.019505,"end_time":"2022-04-25T16:45:25.319337","exception":false,"start_time":"2022-04-25T16:45:25.299832","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"> **Enrollment Number**: 19BCE024\n\n> **Batch**: E1","metadata":{"id":"rgr9JDE6Fg_2","papermill":{"duration":0.021298,"end_time":"2022-04-25T16:45:25.360535","exception":false,"start_time":"2022-04-25T16:45:25.339237","status":"completed"},"tags":[]}},{"cell_type":"code","source":"# Importing Basic libraries for Data Handling & Manipulations \nimport numpy as np \nimport pandas as pd\nimport tensorflow as tf\nimport sklearn as sk\n# For Sequential Model we use keras from tensor flow\nfrom tensorflow import keras\nfrom keras import Sequential\n\n# For Learning rate change and callback function at accuracy\nfrom keras.callbacks import ReduceLROnPlateau\nfrom keras.utils.np_utils import to_categorical                                                   # For one hot encoding vector\nfrom sklearn.model_selection import train_test_split                                              # Spliting train test\nfrom keras.preprocessing.image import ImageDataGenerator                                          # For Image Augmentaion, Rotation, strip\nfrom keras.layers import Dense, Conv2D, Flatten, BatchNormalization, Activation, MaxPooling2D     # All important Layer fuction/of model","metadata":{"id":"CVktl6G4RNcO","papermill":{"duration":5.975142,"end_time":"2022-04-25T16:45:31.356072","exception":false,"start_time":"2022-04-25T16:45:25.38093","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-05-04T20:12:34.208374Z","iopub.execute_input":"2022-05-04T20:12:34.208685Z","iopub.status.idle":"2022-05-04T20:12:36.611287Z","shell.execute_reply.started":"2022-05-04T20:12:34.208652Z","shell.execute_reply":"2022-05-04T20:12:36.610552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Load MNIST data set of handwritten numbers from 0 to 9 (10 classes)\ntrain = pd.read_csv('../input/digit-recognizer/train.csv')\ntest  = pd.read_csv('../input/digit-recognizer/test.csv')\nX_Train,y_train=train.drop('label',axis=1),train['label']\nX_Test=test\n","metadata":{"id":"IaUV0Pi2RT8z","papermill":{"duration":1.589495,"end_time":"2022-04-25T16:45:32.966064","exception":false,"start_time":"2022-04-25T16:45:31.376569","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-05-04T20:12:36.612860Z","iopub.execute_input":"2022-05-04T20:12:36.613105Z","iopub.status.idle":"2022-05-04T20:12:41.329526Z","shell.execute_reply.started":"2022-05-04T20:12:36.613072Z","shell.execute_reply":"2022-05-04T20:12:41.328794Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t=lambda x:x.shape\na,b,c=t(X_Train),t(X_Test),t(y_train),\nprint('',f'X_train: {a}                X_test: {b}',f'Y_train: {c}                  ','',sep='\\n'+(30*'-'+(5*' ')+'='*30)+'\\n')","metadata":{"id":"hITIjBtVRWCc","outputId":"69d9dc4f-4542-46f6-8539-56053eb5329f","papermill":{"duration":0.033171,"end_time":"2022-04-25T16:45:33.02291","exception":false,"start_time":"2022-04-25T16:45:32.989739","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-05-04T20:12:41.331071Z","iopub.execute_input":"2022-05-04T20:12:41.331479Z","iopub.status.idle":"2022-05-04T20:12:41.338799Z","shell.execute_reply.started":"2022-05-04T20:12:41.331442Z","shell.execute_reply":"2022-05-04T20:12:41.337904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from matplotlib import pyplot\nfor i in range(5):  \n    pyplot.subplot(330 + 1 + i)\n    pyplot.imshow(np.reshape(np.array(X_Train.iloc[i]),(28,28)))\n    pyplot.show()","metadata":{"id":"tIrRVRiUTIsG","outputId":"84a6f983-0ab1-4df8-e62b-602b4a2d2324","papermill":{"duration":0.54469,"end_time":"2022-04-25T16:45:33.590617","exception":false,"start_time":"2022-04-25T16:45:33.045927","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-05-04T20:12:41.340095Z","iopub.execute_input":"2022-05-04T20:12:41.340460Z","iopub.status.idle":"2022-05-04T20:12:41.948830Z","shell.execute_reply.started":"2022-05-04T20:12:41.340415Z","shell.execute_reply":"2022-05-04T20:12:41.948109Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Reshaping Format of inner pixel matrix size\nX_train = np.array(X_Train).reshape(X_Train.shape[0],28,28,1)\nX_test = np.array(X_Test).reshape(X_Test.shape[0],28,28,1)\n# Convert pixel values into float 32-bit type\nX_train = X_train.astype('float32')\nX_test = X_test.astype('float32')\n# Simple Normalize pixel value\nX_train/=255.0\nX_test/=255.0","metadata":{"execution":{"iopub.status.busy":"2022-05-04T20:12:41.953939Z","iopub.execute_input":"2022-05-04T20:12:41.954298Z","iopub.status.idle":"2022-05-04T20:12:42.240926Z","shell.execute_reply.started":"2022-05-04T20:12:41.954265Z","shell.execute_reply":"2022-05-04T20:12:42.240170Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Convert Ground Truth to one hot encode vector \nY_train = tf.keras.utils.to_categorical(y_train)\nprint(Y_train)","metadata":{"id":"UzuEhTmdSD76","outputId":"50e0c617-0d35-4006-b9c9-01a03d98520b","papermill":{"duration":0.038818,"end_time":"2022-04-25T16:45:33.815008","exception":false,"start_time":"2022-04-25T16:45:33.77619","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-05-04T20:12:42.243290Z","iopub.execute_input":"2022-05-04T20:12:42.243723Z","iopub.status.idle":"2022-05-04T20:12:42.557068Z","shell.execute_reply.started":"2022-05-04T20:12:42.243683Z","shell.execute_reply":"2022-05-04T20:12:42.556333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Lets create Simple CNN Model using keras's Sequential model\nmodel=Sequential()\n\n# 1st layer of input and 2nd, 3rd of Convolution and Normalization Layer respectively\nmodel.add(Conv2D(filters=32, kernel_size=(3,3), strides=(1,1), padding='valid', activation=None, use_bias=False, input_shape=(X_train.shape[1:])))\nmodel.add(BatchNormalization())\nmodel.add(Activation('relu'))\n\n# Some for filter layers of convolution and normalization\nmodel.add(Conv2D(filters=64, kernel_size=(3,3), strides=(1,1), padding='valid', activation=None, use_bias=False))\nmodel.add(BatchNormalization())\nmodel.add(Activation('relu'))\nmodel.add(MaxPooling2D(pool_size=(2,2)))\n\n# This time with different no. of filters\nmodel.add(Conv2D(filters=96, kernel_size=(3,3), strides=(1,1), padding='valid', activation=None, use_bias=False))\nmodel.add(BatchNormalization())\nmodel.add(Activation('relu'))\nmodel.add(MaxPooling2D(pool_size=(2,2)))\n\n# Last convolution and normalization layer\nmodel.add(Conv2D(filters=128, kernel_size=(3,3), strides=(1,1), padding='valid', activation=None, use_bias=False))\nmodel.add(BatchNormalization())\nmodel.add(Activation('relu'))\n\n# Lets flatten (2d to 1d nerons) layer for fully connected layer in next\nmodel.add(Flatten())\n\n# Dense/Fully Connected Layer\nmodel.add(Dense(units=10))\nmodel.add(BatchNormalization())\n# Softmax for all 10 classes outputs \nmodel.add(Activation('softmax'))","metadata":{"id":"HOcQSD-1S2Up","papermill":{"duration":0.242496,"end_time":"2022-04-25T16:45:34.084174","exception":false,"start_time":"2022-04-25T16:45:33.841678","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-05-04T20:12:42.558476Z","iopub.execute_input":"2022-05-04T20:12:42.558719Z","iopub.status.idle":"2022-05-04T20:12:44.902445Z","shell.execute_reply.started":"2022-05-04T20:12:42.558685Z","shell.execute_reply":"2022-05-04T20:12:44.900591Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Complie it with Loss function of categorical crossentropy and Score as accuracy\nmodel.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])","metadata":{"id":"hv60kOWEv7wi","papermill":{"duration":0.046073,"end_time":"2022-04-25T16:45:34.158216","exception":false,"start_time":"2022-04-25T16:45:34.112143","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-05-04T20:12:44.903758Z","iopub.execute_input":"2022-05-04T20:12:44.904004Z","iopub.status.idle":"2022-05-04T20:12:44.917674Z","shell.execute_reply.started":"2022-05-04T20:12:44.903969Z","shell.execute_reply":"2022-05-04T20:12:44.916989Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Let preprocess the images by manipluating their values at pixel space ..\ntrain_datagen = ImageDataGenerator( featurewise_center=False,\n                                    samplewise_center=False,\n                                    featurewise_std_normalization=False,\n                                    samplewise_std_normalization=False,\n                                    zca_whitening=False,\n                                    rotation_range=10,\n                                    zoom_range=0.1,\n                                    width_shift_range=0.1,\n                                    height_shift_range=0.1,\n                                    horizontal_flip=False,\n                                    vertical_flip=False)\n","metadata":{"execution":{"iopub.status.busy":"2022-05-04T20:12:44.919091Z","iopub.execute_input":"2022-05-04T20:12:44.919480Z","iopub.status.idle":"2022-05-04T20:12:44.924326Z","shell.execute_reply.started":"2022-05-04T20:12:44.919435Z","shell.execute_reply":"2022-05-04T20:12:44.923631Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Generating new input images\ntrain_generator = train_datagen.flow(X_train, Y_train,batch_size=120,shuffle=True)","metadata":{"execution":{"iopub.status.busy":"2022-05-04T20:12:44.925490Z","iopub.execute_input":"2022-05-04T20:12:44.925945Z","iopub.status.idle":"2022-05-04T20:12:44.936068Z","shell.execute_reply.started":"2022-05-04T20:12:44.925911Z","shell.execute_reply":"2022-05-04T20:12:44.935413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Set how we plan to reduce learning rate on plateau i,e. when we reach almost at convergence (decrease lr is 10e-5)\nreduceLROnPlateau = ReduceLROnPlateau(monitor='val_accuracy',       # Checking criteria is accuracy\n                                      patience=3,                   # Check after every 3 epochs to early stoping\n                                      verbose=1, \n                                      factor=0.1,                   # Changing factor\n                                      min_lr=0.00001,)              # Minimium amount of change to count as an improvement(lower bound on the learning rate)","metadata":{"id":"oMG80wEZOC4k","papermill":{"duration":0.035135,"end_time":"2022-04-25T16:45:34.348147","exception":false,"start_time":"2022-04-25T16:45:34.313012","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-05-04T20:12:44.937915Z","iopub.execute_input":"2022-05-04T20:12:44.938134Z","iopub.status.idle":"2022-05-04T20:12:44.946087Z","shell.execute_reply.started":"2022-05-04T20:12:44.938090Z","shell.execute_reply":"2022-05-04T20:12:44.945048Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()\n# Layer 1 Input I = 28 x 28 x 1  so Output O = 28-3+0 / 1 + 1 =  26 x 26 parameter = (3x3+0)*32\n# Layer 2 Input I = 26 x 26 x 32 so Output O = 26 x 26 x 32 parameter = (4)*32 [gamma weights, beta weights, moving_mean(non-trainable), moving_variance(non-trainable)]\n# Layer 2 Input I = 26 x 26 x 32 so Output O = 26 x 26 x 32 parameter = 0 (activation relu)\n\n# Layer 3 Input I = 26 x 26 x 32 so Output O = 26-3+0 / 1 + 1 =  24 x 24 x 64 parameter = (3x3+0)*32*64\n# Layer 4 Input I = 24 x 24 x 64 so Output O = 26 x 26 x 32 parameter = (4)*64 [gamma weights, beta weights, moving_mean(non-trainable), moving_variance(non-trainable)]\n# Layer 4 Input I = 24 x 24 x 64 so Output O = 24 x 24 x 64 parameter = 0 (activation relu)\n\n# Layer 5 Input I = 24 x 24 x 64 so Output O = 24-2 / 2 + 1 =  12 x 12 x 64 parameter = 0 (we take no values but use max input value of filter size space in it)\n\n# Layer 6 Input I = 12 x 12 x 64 so Output O = 12-3+0 / 1 + 1 =  10 x 10 x 96 parameter = (3x3+0)*64*96\n# Layer 7 Input I = 10 x 10 x 96 so Output O = 10 x 10 x 96 parameter = (4)*96 [gamma weights, beta weights, moving_mean(non-trainable), moving_variance(non-trainable)]\n# Layer 7 Input I = 10 x 10 x 96 so Output O = 10 x 10 x 96 parameter = 0 (activation relu)\n\n# Layer 8 Input I = 10 x 10 x 96 so Output O = 10-2 / 2 + 1 =  5 x 5 x 96 parameter = 0 (we take no values but use max input value of filter size space in it)\n\n# Layer 9  Input I = 05 x 05 x 96 so Output O = 5-3+0 /1 + 1 =  3 x 3 x 128 parameter = (3*3+0)*128*96\n# Layer 10 Input I = 3  x 3 x 128 so Output O = 3 x 3 x 128 parameter = (4)*128 [gamma weights, beta weights, moving_mean(non-trainable), moving_variance(non-trainable)]\n# Layer 10 Input I = 3  x 3 x 128 so Output O = 3 x 3 x 128 parameter = 0 (activation relu)\n\n# Layer 11 Input I = 3 x 3 x 128 so Output O = 3 x 3 x 128 parameter = 0\n# Layer 12 Input I = 1152 neuron so Output O =10 (pre decided) parameter = (1152 + 1)*10\n# Layer 13 Input I = 10 so Output O = 10 parameter = (4)*10 [gamma weights, beta weights, moving_mean(non-trainable), moving_variance(non-trainable)]\n# Layer 13 Input I = 10 so Output O = 10 parameter = 0 (activation softmax)\n\n# Total = 228+128+0+18432+256+0+0+55296+384+0+0+110592+512+0+0+11530+40+0 =  197458","metadata":{"id":"ruRrpciqrSwV","outputId":"4a5a6b1e-467b-40e1-832a-52fa4f1ec597","papermill":{"duration":0.046545,"end_time":"2022-04-25T16:45:34.424086","exception":false,"start_time":"2022-04-25T16:45:34.377541","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-05-04T20:12:44.947301Z","iopub.execute_input":"2022-05-04T20:12:44.947976Z","iopub.status.idle":"2022-05-04T20:12:44.965082Z","shell.execute_reply.started":"2022-05-04T20:12:44.947906Z","shell.execute_reply":"2022-05-04T20:12:44.964441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tf.keras.utils.plot_model(model)","metadata":{"id":"IAfSo9JIDpio","outputId":"d997952e-2bfb-4d04-b8d0-b2c564b3c520","papermill":{"duration":0.897773,"end_time":"2022-04-25T16:45:35.350246","exception":false,"start_time":"2022-04-25T16:45:34.452473","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-05-04T20:12:44.967728Z","iopub.execute_input":"2022-05-04T20:12:44.967903Z","iopub.status.idle":"2022-05-04T20:12:45.735413Z","shell.execute_reply.started":"2022-05-04T20:12:44.967882Z","shell.execute_reply":"2022-05-04T20:12:45.734636Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Lets Train model over 100 epoche/iterations with stoping callback fuction as reducing learning rates\nhistory=model.fit(train_generator, epochs=100, callbacks=[reduceLROnPlateau])","metadata":{"id":"dLsPu0aPrVlk","outputId":"21d91a10-0baf-4b78-c23f-d6a3ff2a9e0e","papermill":{"duration":13682.974239,"end_time":"2022-04-25T20:33:38.355286","exception":false,"start_time":"2022-04-25T16:45:35.381047","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-05-04T20:12:45.739038Z","iopub.execute_input":"2022-05-04T20:12:45.739314Z","iopub.status.idle":"2022-05-04T20:32:15.474459Z","shell.execute_reply.started":"2022-05-04T20:12:45.739277Z","shell.execute_reply":"2022-05-04T20:32:15.473752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.models import load_model\nmodel.save(\"network.h5\")\nloaded_model = load_model(\"network.h5\")","metadata":{"execution":{"iopub.status.busy":"2022-05-04T20:32:15.475936Z","iopub.execute_input":"2022-05-04T20:32:15.476131Z","iopub.status.idle":"2022-05-04T20:32:15.706723Z","shell.execute_reply.started":"2022-05-04T20:32:15.476107Z","shell.execute_reply":"2022-05-04T20:32:15.706054Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from matplotlib import pyplot\nfor i in range(4):  \n    pyplot.subplot(330 + 1 + i)\n    pyplot.imshow(np.reshape(np.array(X_Test.iloc[i]),(28,28)))\n    pyplot.show()","metadata":{"id":"gPfru06bej1n","outputId":"e05a8de2-bd7f-43c5-b31c-8be0b4b9c3b6","papermill":{"duration":19.225713,"end_time":"2022-04-25T20:34:16.195722","exception":false,"start_time":"2022-04-25T20:33:56.970009","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-05-04T20:51:59.983721Z","iopub.execute_input":"2022-05-04T20:51:59.984656Z","iopub.status.idle":"2022-05-04T20:52:00.432138Z","shell.execute_reply.started":"2022-05-04T20:51:59.984610Z","shell.execute_reply":"2022-05-04T20:52:00.431438Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Predict on test images, 10 probabilities for each test image as there are 10 classes.\nprediction_vectors=model.predict(X_test)","metadata":{"id":"Kuwva2yEVWs9","papermill":{"duration":22.502211,"end_time":"2022-04-25T20:34:57.326469","exception":false,"start_time":"2022-04-25T20:34:34.824258","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-05-04T20:52:04.876851Z","iopub.execute_input":"2022-05-04T20:52:04.877110Z","iopub.status.idle":"2022-05-04T20:52:07.750201Z","shell.execute_reply.started":"2022-05-04T20:52:04.877080Z","shell.execute_reply":"2022-05-04T20:52:07.749433Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prediction_vectors.argmax(axis=1)[:4]","metadata":{"id":"YlXarOZ2f8LH","outputId":"1f89ba15-2c4e-4b5f-c97b-f3708cae4173","papermill":{"duration":18.40633,"end_time":"2022-04-25T20:35:34.399913","exception":false,"start_time":"2022-04-25T20:35:15.993583","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-05-04T20:52:10.935240Z","iopub.execute_input":"2022-05-04T20:52:10.935547Z","iopub.status.idle":"2022-05-04T20:52:10.942418Z","shell.execute_reply.started":"2022-05-04T20:52:10.935514Z","shell.execute_reply":"2022-05-04T20:52:10.941703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history_df = pd.DataFrame(history.history)\nhistory_df[['loss']].plot()","metadata":{"id":"SOk3coveW_7k","outputId":"74fe77fb-ff67-463f-bb22-8e52d4e564d6","papermill":{"duration":18.753894,"end_time":"2022-04-25T20:36:11.559465","exception":false,"start_time":"2022-04-25T20:35:52.805571","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-05-04T20:52:27.736229Z","iopub.execute_input":"2022-05-04T20:52:27.736816Z","iopub.status.idle":"2022-05-04T20:52:27.940410Z","shell.execute_reply.started":"2022-05-04T20:52:27.736776Z","shell.execute_reply":"2022-05-04T20:52:27.939745Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history_df[['accuracy']].plot()","metadata":{"id":"TXs_qhPgZjc_","outputId":"ceda579e-26d2-4ef8-cb21-e9310d33064f","papermill":{"duration":18.720268,"end_time":"2022-04-25T20:36:48.718863","exception":false,"start_time":"2022-04-25T20:36:29.998595","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-05-04T20:52:36.724722Z","iopub.execute_input":"2022-05-04T20:52:36.724976Z","iopub.status.idle":"2022-05-04T20:52:36.918978Z","shell.execute_reply.started":"2022-05-04T20:52:36.724941Z","shell.execute_reply":"2022-05-04T20:52:36.918314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accy=np.mean(history.history['accuracy'])*100","metadata":{"id":"fwGyNiMYha1f","papermill":{"duration":18.504045,"end_time":"2022-04-25T20:37:25.572033","exception":false,"start_time":"2022-04-25T20:37:07.067988","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-05-04T20:52:39.405628Z","iopub.execute_input":"2022-05-04T20:52:39.406211Z","iopub.status.idle":"2022-05-04T20:52:39.410307Z","shell.execute_reply.started":"2022-05-04T20:52:39.406172Z","shell.execute_reply":"2022-05-04T20:52:39.409314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('',f'Mean Accuracy : {accy}%  ','',sep='\\n'+('='*35)+'\\n')","metadata":{"id":"FrABKaWfhlEc","outputId":"c9e09af2-c62f-49af-e44d-8e746016c363","papermill":{"duration":18.390335,"end_time":"2022-04-25T20:38:02.374941","exception":false,"start_time":"2022-04-25T20:37:43.984606","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-05-04T20:52:42.910553Z","iopub.execute_input":"2022-05-04T20:52:42.910802Z","iopub.status.idle":"2022-05-04T20:52:42.916283Z","shell.execute_reply.started":"2022-05-04T20:52:42.910774Z","shell.execute_reply":"2022-05-04T20:52:42.915510Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"results = np.zeros((X_test.shape[0], 10))\nresults = np.argmax(results, axis=1)\nresults = pd.Series(prediction_vectors.argmax(axis=1)[:], name=\"Label\")\nsubmission = pd.concat([pd.Series(range(1,28001), name=\"ImageId\"), results], axis=1)\nsubmission.to_csv('submission.csv', index=False) # creating the submission file\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-04T21:32:11.033571Z","iopub.execute_input":"2022-05-04T21:32:11.033988Z","iopub.status.idle":"2022-05-04T21:32:11.085596Z","shell.execute_reply.started":"2022-05-04T21:32:11.033951Z","shell.execute_reply":"2022-05-04T21:32:11.084801Z"},"trusted":true},"execution_count":null,"outputs":[]}]}