{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-12-20T07:17:40.667407Z","iopub.execute_input":"2022-12-20T07:17:40.667902Z","iopub.status.idle":"2022-12-20T07:17:40.678498Z","shell.execute_reply.started":"2022-12-20T07:17:40.667865Z","shell.execute_reply":"2022-12-20T07:17:40.677491Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"In this notebook, I'm willing to use a Convolutional Neural Network to solve this problem. Convolutional Neural Networks are very powerful at detecting features, like edges, parts of objets, and even complete objects","metadata":{}},{"cell_type":"markdown","source":"# Importing Required Libraries","metadata":{}},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns\nfrom keras.models import Sequential\nimport warnings as w\nw.filterwarnings('ignore')\nimport numpy as np \nimport pandas as pd\nimport tensorflow as tf\nfrom tensorflow import image\nfrom tensorflow import keras\nfrom tensorflow.keras import layers\n#from keras.layers import Dense,Dropout,Flatten,Conv2D,MaxPool2D\n%matplotlib inline\nfrom keras.utils.np_utils import to_categorical\nfrom sklearn.model_selection import train_test_split\nfrom tensorflow.keras.callbacks import EarlyStopping\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom tensorflow.keras.preprocessing import image_dataset_from_directory\nimport warnings\nwarnings.filterwarnings(\"ignore\")","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:17:49.702739Z","iopub.execute_input":"2022-12-20T07:17:49.703508Z","iopub.status.idle":"2022-12-20T07:17:49.718474Z","shell.execute_reply.started":"2022-12-20T07:17:49.703463Z","shell.execute_reply":"2022-12-20T07:17:49.717149Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Loading the dataset","metadata":{}},{"cell_type":"markdown","source":"Let's now load the two csv files ","metadata":{}},{"cell_type":"code","source":"train_df=pd.read_csv(\"/kaggle/input/digit-recognizer/train.csv\")\nprint(\"Training data loaded successfully\")\ntest_df=pd.read_csv(\"/kaggle/input/digit-recognizer/test.csv\")\nprint(\"Test data loaded successfully\")","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:17:58.036379Z","iopub.execute_input":"2022-12-20T07:17:58.036840Z","iopub.status.idle":"2022-12-20T07:18:02.159300Z","shell.execute_reply.started":"2022-12-20T07:17:58.036802Z","shell.execute_reply":"2022-12-20T07:18:02.157966Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:18:08.886448Z","iopub.execute_input":"2022-12-20T07:18:08.886913Z","iopub.status.idle":"2022-12-20T07:18:08.910988Z","shell.execute_reply.started":"2022-12-20T07:18:08.886875Z","shell.execute_reply":"2022-12-20T07:18:08.909723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:18:15.255575Z","iopub.execute_input":"2022-12-20T07:18:15.256452Z","iopub.status.idle":"2022-12-20T07:18:15.277361Z","shell.execute_reply.started":"2022-12-20T07:18:15.256395Z","shell.execute_reply":"2022-12-20T07:18:15.275870Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:18:20.735655Z","iopub.execute_input":"2022-12-20T07:18:20.736117Z","iopub.status.idle":"2022-12-20T07:18:20.743540Z","shell.execute_reply.started":"2022-12-20T07:18:20.736068Z","shell.execute_reply":"2022-12-20T07:18:20.742653Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:18:23.295688Z","iopub.execute_input":"2022-12-20T07:18:23.296163Z","iopub.status.idle":"2022-12-20T07:18:23.304683Z","shell.execute_reply.started":"2022-12-20T07:18:23.296124Z","shell.execute_reply":"2022-12-20T07:18:23.302988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Count for Number of digits present","metadata":{}},{"cell_type":"code","source":"train_df['label'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:18:29.117068Z","iopub.execute_input":"2022-12-20T07:18:29.118317Z","iopub.status.idle":"2022-12-20T07:18:29.128796Z","shell.execute_reply.started":"2022-12-20T07:18:29.118262Z","shell.execute_reply":"2022-12-20T07:18:29.127497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12,6))\nsns.countplot(train_df['label'])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:18:35.016420Z","iopub.execute_input":"2022-12-20T07:18:35.016905Z","iopub.status.idle":"2022-12-20T07:18:35.238699Z","shell.execute_reply.started":"2022-12-20T07:18:35.016865Z","shell.execute_reply":"2022-12-20T07:18:35.237494Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=train_df.drop(labels=['label'],axis=1)\ny=train_df['label']","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:18:41.365592Z","iopub.execute_input":"2022-12-20T07:18:41.366063Z","iopub.status.idle":"2022-12-20T07:18:41.495964Z","shell.execute_reply.started":"2022-12-20T07:18:41.366025Z","shell.execute_reply":"2022-12-20T07:18:41.494410Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x.head(1)","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:18:45.075730Z","iopub.execute_input":"2022-12-20T07:18:45.076705Z","iopub.status.idle":"2022-12-20T07:18:45.094790Z","shell.execute_reply.started":"2022-12-20T07:18:45.076660Z","shell.execute_reply":"2022-12-20T07:18:45.093499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:18:49.955689Z","iopub.execute_input":"2022-12-20T07:18:49.956228Z","iopub.status.idle":"2022-12-20T07:18:49.966188Z","shell.execute_reply.started":"2022-12-20T07:18:49.956185Z","shell.execute_reply":"2022-12-20T07:18:49.965010Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Describing the data","metadata":{}},{"cell_type":"markdown","source":"Let's now see the description of both these two files. Descritption is a method with dataframes, it allows us to see the statistical values of a dataset. Like for example, the mean, the std (standard deviation), the max and min values etc,.","metadata":{}},{"cell_type":"code","source":"print(\"Description of the training : \")\ntrain=x.describe().T\ntrain","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:18:55.136133Z","iopub.execute_input":"2022-12-20T07:18:55.136642Z","iopub.status.idle":"2022-12-20T07:18:57.596193Z","shell.execute_reply.started":"2022-12-20T07:18:55.136602Z","shell.execute_reply":"2022-12-20T07:18:57.594992Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Description of the test data : \")\ntest=test_df.describe().T\ntest","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:19:02.465563Z","iopub.execute_input":"2022-12-20T07:19:02.466059Z","iopub.status.idle":"2022-12-20T07:19:04.714331Z","shell.execute_reply.started":"2022-12-20T07:19:02.466014Z","shell.execute_reply":"2022-12-20T07:19:04.713232Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's visualize the mean of each pixel in a bar plot.","metadata":{}},{"cell_type":"markdown","source":"#### Before Scaling","metadata":{}},{"cell_type":"code","source":"fig, ax_arr = plt.subplots(1, 2, figsize=(14, 4))\nfig.subplots_adjust(wspace=0.25, hspace=0.025)\n\nax_arr = ax_arr.ravel()\n\nsets = iter([(train, \"training\"), (test, \"testing\")])\nfor i, ax in enumerate(ax_arr):\n    set_ = next(sets)\n    ax.plot(set_[0].loc[:, \"mean\"], label=\"Mean\")\n    ax.set_title(\"Mean of the {} features.\".format(set_[1]))\n    ax.set_xlabel('Pixels')\n    ax.set_ylabel('Mean')\n    ax.set_xticks([0, 120, 250, 370, 480, 600, 720])\n    ax.legend(loc=\"upper left\", shadow=True, frameon=True, framealpha=0.9)\n    ax.set_ylim([0, 150])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:19:11.605896Z","iopub.execute_input":"2022-12-20T07:19:11.606366Z","iopub.status.idle":"2022-12-20T07:19:12.196247Z","shell.execute_reply.started":"2022-12-20T07:19:11.606326Z","shell.execute_reply":"2022-12-20T07:19:12.195252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The content in the following plots represents the data before scaling, you can see that the features vary. The first features have 0 in the mean value, that's because all the values in the first features are zero","metadata":{}},{"cell_type":"markdown","source":"### Normalization","metadata":{}},{"cell_type":"markdown","source":"* Normalizing the data helps with converging to the global minima, instead of having a lot of local minima.\n* Similarly, the goal of normalization is to change the values of numeric columns in the dataset to a common scale, without distorting differences in the ranges of values","metadata":{}},{"cell_type":"code","source":"\nx=x/255.0\ntest_df=test_df/255.0\n","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:19:16.885328Z","iopub.execute_input":"2022-12-20T07:19:16.885841Z","iopub.status.idle":"2022-12-20T07:19:17.083976Z","shell.execute_reply.started":"2022-12-20T07:19:16.885798Z","shell.execute_reply":"2022-12-20T07:19:17.081358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Describing the normalized dataset again","metadata":{}},{"cell_type":"code","source":"train = x.describe().T\ntest = test_df.describe().T","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:19:20.005473Z","iopub.execute_input":"2022-12-20T07:19:20.005963Z","iopub.status.idle":"2022-12-20T07:19:25.166959Z","shell.execute_reply.started":"2022-12-20T07:19:20.005917Z","shell.execute_reply":"2022-12-20T07:19:25.165619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax_arr = plt.subplots(1, 2, figsize=(14, 4))\nfig.subplots_adjust(wspace=0.25, hspace=0.025)\n\nax_arr = ax_arr.ravel()\n\nsets = iter([(train, \"training\"), (test, \"testing\")])\nfor i, ax in enumerate(ax_arr):\n    set_ = next(sets)\n    ax.plot(set_[0].loc[:, \"mean\"], label=\"Mean\")\n    ax.set_title(\"Mean of the {} features.\".format(set_[1]))\n    ax.set_xlabel('Pixels')\n    ax.set_ylabel('Mean')\n    ax.set_xticks([0, 120, 250, 370, 480, 600, 720])\n    ax.legend(loc=\"upper left\", shadow=True, frameon=True, framealpha=0.9)\n    ax.set_ylim([0, 150])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:20:45.580775Z","iopub.execute_input":"2022-12-20T07:20:45.581337Z","iopub.status.idle":"2022-12-20T07:20:45.938957Z","shell.execute_reply.started":"2022-12-20T07:20:45.581294Z","shell.execute_reply":"2022-12-20T07:20:45.937935Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=x.values.reshape(-1,28,28,1)\ntest_df=test_df.values.reshape(-1,28,28,1)","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:20:52.856728Z","iopub.execute_input":"2022-12-20T07:20:52.857267Z","iopub.status.idle":"2022-12-20T07:20:52.864162Z","shell.execute_reply.started":"2022-12-20T07:20:52.857221Z","shell.execute_reply":"2022-12-20T07:20:52.862712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:20:56.075560Z","iopub.execute_input":"2022-12-20T07:20:56.076049Z","iopub.status.idle":"2022-12-20T07:20:56.085260Z","shell.execute_reply.started":"2022-12-20T07:20:56.076005Z","shell.execute_reply":"2022-12-20T07:20:56.083608Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(x[3600][:,:,0])","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:21:01.916778Z","iopub.execute_input":"2022-12-20T07:21:01.917397Z","iopub.status.idle":"2022-12-20T07:21:02.153241Z","shell.execute_reply.started":"2022-12-20T07:21:01.917330Z","shell.execute_reply":"2022-12-20T07:21:02.151793Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def visualize_input(img, ax):\n    ax.imshow(img, cmap='gray')\n    width, height = img.shape\n    thresh = img.max()/2.5\n    for x in range(width):\n        for y in range(height):\n            ax.annotate(str(round(img[x][y],2)), xy=(y,x),\n                        horizontalalignment='center',\n                        verticalalignment='center',\n                        color='white' if img[x][y]<thresh else 'black')\n\nfig = plt.figure(figsize = (6,6)) \nax = fig.add_subplot(111)\nvisualize_input(x[3600].reshape(28,28), ax)","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:21:05.915573Z","iopub.execute_input":"2022-12-20T07:21:05.916536Z","iopub.status.idle":"2022-12-20T07:21:10.823587Z","shell.execute_reply.started":"2022-12-20T07:21:05.916486Z","shell.execute_reply":"2022-12-20T07:21:10.822331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, axes = plt.subplots(3,5, figsize=(12,5))\naxes = axes.flatten()\nidx = np.random.randint(0,42000,size=15)\nfor i in range(15):\n    axes[i].imshow(x[idx[i],:].reshape(28,28), cmap='gray')\n    axes[i].axis('off') # hide the axes ticks\n    axes[i].set_title(str(int(y[idx[i]])), color= 'black', fontsize=25)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:21:16.740376Z","iopub.execute_input":"2022-12-20T07:21:16.740850Z","iopub.status.idle":"2022-12-20T07:21:17.386028Z","shell.execute_reply.started":"2022-12-20T07:21:16.740812Z","shell.execute_reply":"2022-12-20T07:21:17.384727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y=to_categorical(y,num_classes=10)","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:21:24.897056Z","iopub.execute_input":"2022-12-20T07:21:24.897860Z","iopub.status.idle":"2022-12-20T07:21:24.904605Z","shell.execute_reply.started":"2022-12-20T07:21:24.897819Z","shell.execute_reply":"2022-12-20T07:21:24.903617Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Splitting Training and validation set","metadata":{}},{"cell_type":"code","source":"x_train,x_val,y_train,y_val=train_test_split(x,y,test_size=0.2,random_state=2)","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:21:28.916046Z","iopub.execute_input":"2022-12-20T07:21:28.917088Z","iopub.status.idle":"2022-12-20T07:21:29.535475Z","shell.execute_reply.started":"2022-12-20T07:21:28.917028Z","shell.execute_reply":"2022-12-20T07:21:29.534185Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"I choosed to split the train set in two parts:a small fraction(20%) beacme the validation set which the model is evaluated and the rest(80%) used to train the model.","metadata":{}},{"cell_type":"markdown","source":"# CNN","metadata":{}},{"cell_type":"markdown","source":"## Define the model","metadata":{}},{"cell_type":"markdown","source":"The first is the convolution(Conv2D) layer.It is like a set of learnable filters. I choosed to set 32 filters for the two firsts conv2D layers and 64 for the last ones.Each filter transforms a part of the image(defined by the kernel size) using the kernel filter.\n\nThe CNN can isolate features that are useful everywhere from transformed images(feature map).\n\nThe second important layer in CNN is the pooling (MaxPool2D) layer. \n\nDropout is a regularization method, where a proportion of nodes in the layer are randomly ignored for each training sample.This technique improves generalization and reduces the overfitting.\n\n'relu' is the rectifier(activation function max(0,x).The rectifier activation is used to add non linearity to the network.\n\nThe flatten layer is used to convert the final feature maps into one single 1D vector.\n\nIn the last layer the net outputs distribution of probability of each class.","metadata":{}},{"cell_type":"code","source":"model = keras.Sequential([\n    # Block One\n    layers.Conv2D(filters=32, kernel_size=5, activation='relu', padding='same',\n                  input_shape=[28, 28, 1]),\n      layers.Conv2D(filters=32, kernel_size=5, activation='relu', padding='same'),\n    layers.MaxPool2D(pool_size=(2,2)),\n    layers.Dropout(0.25),\n\n    # Block Two\n    layers.Conv2D(filters=64, kernel_size=3, activation='relu', padding='same'),\n    layers.MaxPool2D(),\n\n    # Block Three\n    # YOUR CODE HERE\n    layers.Conv2D(filters=64, kernel_size=3, activation='relu', padding='same'),\n    layers.Conv2D(filters=64, kernel_size=3, activation='relu', padding='same'),\n    layers.MaxPool2D(pool_size=(2,2),strides=(2,2)),\n    layers.Dropout(0.25),\n\n\n    # Head\n    layers.Flatten(),\n    layers.Dense(256, activation='relu'),\n    layers.Dropout(0.5),\n    layers.Dense(10, activation='softmax'),\n])","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:21:37.302247Z","iopub.execute_input":"2022-12-20T07:21:37.302687Z","iopub.status.idle":"2022-12-20T07:21:37.756429Z","shell.execute_reply.started":"2022-12-20T07:21:37.302652Z","shell.execute_reply":"2022-12-20T07:21:37.755269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(\n    optimizer=tf.keras.optimizers.Adam(epsilon=0.01),\n     loss='categorical_crossentropy',\n    metrics=['accuracy'],\n)","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:21:45.170728Z","iopub.execute_input":"2022-12-20T07:21:45.171217Z","iopub.status.idle":"2022-12-20T07:21:45.184761Z","shell.execute_reply.started":"2022-12-20T07:21:45.171179Z","shell.execute_reply":"2022-12-20T07:21:45.183683Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"datagen=ImageDataGenerator(rotation_range=10,\n    width_shift_range=0.3,\n    height_shift_range=0.2,\n    shear_range=0.3,\n    zoom_range=0.2,\n    horizontal_flip=False)\ndatagen.fit(x)","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:22:03.496570Z","iopub.execute_input":"2022-12-20T07:22:03.497142Z","iopub.status.idle":"2022-12-20T07:22:03.628613Z","shell.execute_reply.started":"2022-12-20T07:22:03.497078Z","shell.execute_reply":"2022-12-20T07:22:03.627524Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"early_stopping = EarlyStopping(\n    min_delta=0.001, # minimium amount of change to count as an improvement\n    patience=20, # how many epochs to wait before stopping\n    restore_best_weights=True,\n)","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:22:12.876341Z","iopub.execute_input":"2022-12-20T07:22:12.877215Z","iopub.status.idle":"2022-12-20T07:22:12.882821Z","shell.execute_reply.started":"2022-12-20T07:22:12.877166Z","shell.execute_reply":"2022-12-20T07:22:12.881730Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit(\n    x_train, y_train,\n    validation_data = (x_val, y_val),\n    batch_size = 128,\n     epochs = 25,\n   callbacks = [early_stopping],\n    #verbose = 0\n   \n)\n","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:22:16.655443Z","iopub.execute_input":"2022-12-20T07:22:16.655921Z","iopub.status.idle":"2022-12-20T07:46:56.361523Z","shell.execute_reply.started":"2022-12-20T07:22:16.655885Z","shell.execute_reply":"2022-12-20T07:46:56.360499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history_frame = pd.DataFrame(history.history)\nhistory_frame.loc[:, ['loss', 'val_loss']].plot()\nhistory_frame.loc[:, ['accuracy', 'val_accuracy']].plot();","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:47:04.025083Z","iopub.execute_input":"2022-12-20T07:47:04.025487Z","iopub.status.idle":"2022-12-20T07:47:04.481486Z","shell.execute_reply.started":"2022-12-20T07:47:04.025454Z","shell.execute_reply":"2022-12-20T07:47:04.480196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test=model.predict(test_df)","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:47:10.936838Z","iopub.execute_input":"2022-12-20T07:47:10.937851Z","iopub.status.idle":"2022-12-20T07:47:26.664034Z","shell.execute_reply.started":"2022-12-20T07:47:10.937798Z","shell.execute_reply":"2022-12-20T07:47:26.663170Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test=[np.argmax(y_test1) for y_test1 in y_test]","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:47:32.657011Z","iopub.execute_input":"2022-12-20T07:47:32.657843Z","iopub.status.idle":"2022-12-20T07:47:32.718877Z","shell.execute_reply.started":"2022-12-20T07:47:32.657804Z","shell.execute_reply":"2022-12-20T07:47:32.717576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission=pd.DataFrame({'ImageId':[i+1 for i in range(len(y_test))],'Label':y_test})\nsubmission.to_csv(\"submission.csv\", index = False)","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:47:36.476260Z","iopub.execute_input":"2022-12-20T07:47:36.476765Z","iopub.status.idle":"2022-12-20T07:47:36.536240Z","shell.execute_reply.started":"2022-12-20T07:47:36.476711Z","shell.execute_reply":"2022-12-20T07:47:36.534974Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission","metadata":{"execution":{"iopub.status.busy":"2022-12-20T07:47:40.636432Z","iopub.execute_input":"2022-12-20T07:47:40.637345Z","iopub.status.idle":"2022-12-20T07:47:40.651500Z","shell.execute_reply.started":"2022-12-20T07:47:40.637298Z","shell.execute_reply":"2022-12-20T07:47:40.650120Z"},"trusted":true},"execution_count":null,"outputs":[]}]}