{"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":3004,"databundleVersionId":861823,"sourceType":"competition"}],"dockerImageVersionId":30788,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"<div style=\"background-color: Black;  padding: 10px; border-radius: 10px; text-align: center;\">\n  <span style=\"color: white; font-size: 35px; font-weight: bold;\">\n      Digit Recognizer Using CNN - Accuracy 98.76 %\n</div>\n","metadata":{}},{"cell_type":"markdown","source":"## **By/Eng.Ahmed Almohamdy**\n\norignal Notebook link : https://www.kaggle.com/code/ahmedalmohamdy/digit-recognizer-using-cnn-accuracy-98-76\n\n* **1. Data preparation**\n    * 1.1 Load data\n    * 1.2 Check for null and missing values\n    * 1.3 Normalization\n    * 1.4 Reshape\n    * 1.5 Label encoding\n    * 1.6 Split training and valdiation set\n* **2. CNN**\n    * 2.1 Define the model\n    * 2.2 Set the optimizer\n    * 2.3 Data Augmentation\n* **3. Evaluate the model**\n    * 3.1 Training and validation curves\n    * 3.2 Confusion matrix\n* **4.Prediction and submition**\n    * 4.1 Predict and Submit results","metadata":{"_cell_guid":"d4c08f48-fe23-4ddb-ac46-d97f05397514","_uuid":"f2156d1dd26a1243e18512002e10872c5bd7271e"}},{"cell_type":"markdown","source":"<div style=\"background-color: Green;  padding: 10px; border-radius: 10px; text-align: center;\">\n  <span style=\"color: white; font-size: 15px; font-weight: bold;\">\n      Importing\n</div>\n","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.image as mpimg\nimport seaborn as sns\n%matplotlib inline\n\nnp.random.seed(3)  # To Produce same random values each run Time\n\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import confusion_matrix\nimport itertools\n\nfrom keras.utils import to_categorical # convert to one-hot-encoding\nfrom keras.models import Sequential\nfrom keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPool2D , BatchNormalization\nfrom keras.optimizers import RMSprop\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom keras.callbacks import ReduceLROnPlateau\n\n\nsns.set(style='white', context='notebook', palette='deep')","metadata":{"_cell_guid":"f67b9393-8ea1-4e23-b856-2ce149cfe421","_execution_state":"idle","_uuid":"72334cb006d02a4bcfc2a2fe622524eba824c6f8","execution":{"iopub.status.busy":"2024-10-11T23:17:27.633991Z","iopub.execute_input":"2024-10-11T23:17:27.634691Z","iopub.status.idle":"2024-10-11T23:17:49.301295Z","shell.execute_reply.started":"2024-10-11T23:17:27.634651Z","shell.execute_reply":"2024-10-11T23:17:49.300303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"background-color: Green;  padding: 10px; border-radius: 10px; text-align: center;\">\n  <span style=\"color: white; font-size: 15px; font-weight: bold;\">\n      Data Preparation\n</div>\n","metadata":{}},{"cell_type":"markdown","source":"# 1. Data preparation\n## 1.1 Load data","metadata":{"_cell_guid":"6d2fb3e6-ab71-4974-b5a2-4af1ebdb99f4","_execution_state":"idle","_uuid":"86061d98eccaa02efe0dab0fa3884e71fcf4c310"}},{"cell_type":"code","source":"# Load the data\ntrain = pd.read_csv(\"/kaggle/input/digit-recognizer/train.csv\")\ntest = pd.read_csv(\"/kaggle/input/digit-recognizer/test.csv\")","metadata":{"_cell_guid":"5e51d00e-62fd-4141-bf73-50ac4f2da7d0","_execution_state":"idle","_uuid":"84bbd5ab8d7895bd430d5ecfe2f7ddf77baa7b74","execution":{"iopub.status.busy":"2024-10-11T23:17:49.302946Z","iopub.execute_input":"2024-10-11T23:17:49.303516Z","iopub.status.idle":"2024-10-11T23:17:54.893044Z","shell.execute_reply.started":"2024-10-11T23:17:49.303478Z","shell.execute_reply":"2024-10-11T23:17:54.892162Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.shape","metadata":{"execution":{"iopub.status.busy":"2024-10-11T23:17:54.894261Z","iopub.execute_input":"2024-10-11T23:17:54.894635Z","iopub.status.idle":"2024-10-11T23:17:54.902236Z","shell.execute_reply.started":"2024-10-11T23:17:54.894590Z","shell.execute_reply":"2024-10-11T23:17:54.901142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2024-10-11T23:17:54.904368Z","iopub.execute_input":"2024-10-11T23:17:54.904950Z","iopub.status.idle":"2024-10-11T23:17:54.936860Z","shell.execute_reply.started":"2024-10-11T23:17:54.904916Z","shell.execute_reply":"2024-10-11T23:17:54.936010Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.describe()","metadata":{"execution":{"iopub.status.busy":"2024-10-11T23:17:54.937977Z","iopub.execute_input":"2024-10-11T23:17:54.938343Z","iopub.status.idle":"2024-10-11T23:17:56.800238Z","shell.execute_reply.started":"2024-10-11T23:17:54.938302Z","shell.execute_reply":"2024-10-11T23:17:56.799038Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## check missing Data","metadata":{}},{"cell_type":"code","source":"train.isna().sum().sum()","metadata":{"execution":{"iopub.status.busy":"2024-10-11T23:17:56.801636Z","iopub.execute_input":"2024-10-11T23:17:56.802018Z","iopub.status.idle":"2024-10-11T23:17:56.835844Z","shell.execute_reply.started":"2024-10-11T23:17:56.801976Z","shell.execute_reply":"2024-10-11T23:17:56.834654Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = train.drop(columns=['label'])\nY_train = train['label']\ndel train","metadata":{"execution":{"iopub.status.busy":"2024-10-11T23:17:56.837735Z","iopub.execute_input":"2024-10-11T23:17:56.838137Z","iopub.status.idle":"2024-10-11T23:17:56.923714Z","shell.execute_reply.started":"2024-10-11T23:17:56.838078Z","shell.execute_reply":"2024-10-11T23:17:56.922896Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.bar( x= Y_train.value_counts().keys() , height = Y_train.value_counts().values)","metadata":{"execution":{"iopub.status.busy":"2024-10-11T23:17:56.924811Z","iopub.execute_input":"2024-10-11T23:17:56.925097Z","iopub.status.idle":"2024-10-11T23:17:57.283442Z","shell.execute_reply.started":"2024-10-11T23:17:56.925054Z","shell.execute_reply":"2024-10-11T23:17:57.282578Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 1.3 Normalization","metadata":{"_cell_guid":"6812040d-80ad-43d2-a571-275f4f20067b","_uuid":"2954681f25f0dcbe986e6914396cdbce61db591f"}},{"cell_type":"code","source":"# Normalize the data\nX_train = X_train / 255.0\ntest = test / 255.0","metadata":{"_cell_guid":"cdc4340b-6e24-4e12-be99-ac806098ff17","_execution_state":"idle","_uuid":"b5d4f8fcf2a967e2c7d57daedf95aa8c5ab7f8cb","execution":{"iopub.status.busy":"2024-10-11T23:17:57.284821Z","iopub.execute_input":"2024-10-11T23:17:57.285291Z","iopub.status.idle":"2024-10-11T23:17:57.376682Z","shell.execute_reply.started":"2024-10-11T23:17:57.285246Z","shell.execute_reply":"2024-10-11T23:17:57.375866Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 1.4 Reshape","metadata":{"_cell_guid":"7413df94-bcb9-4f75-b174-c127d4445766","_uuid":"a66741bf1ac597094f3a3166877008feef27c519"}},{"cell_type":"code","source":"# Reshape image in 3 dimensions (height = 28px, width = 28px , chanal = 1)\nX_train = X_train.values.reshape(-1,28,28,1)\ntest = test.values.reshape(-1,28,28,1)","metadata":{"_cell_guid":"34b6a5f7-8fd2-4387-8ef4-c9dc19584fed","_execution_state":"idle","_uuid":"f0a6ad80dab8e0f2c2e46165ccd9cd82dd162bc3","execution":{"iopub.status.busy":"2024-10-11T23:17:57.379538Z","iopub.execute_input":"2024-10-11T23:17:57.379853Z","iopub.status.idle":"2024-10-11T23:17:57.384607Z","shell.execute_reply.started":"2024-10-11T23:17:57.379820Z","shell.execute_reply":"2024-10-11T23:17:57.383588Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig , ax = plt.subplots(5,5 , figsize=(20,20))\nax = ax.flatten()\ni=0\nr_nums = np.random.randint(0,len(X_train),25)\nfor n in  r_nums:\n    ax[i].imshow(X_train[n] , cmap = 'gray')\n    ax[i].axis('off')\n    ax[i].grid(False)\n    ax[i].set_title(Y_train[n])\n    i+=1","metadata":{"execution":{"iopub.status.busy":"2024-10-11T23:17:57.385617Z","iopub.execute_input":"2024-10-11T23:17:57.385901Z","iopub.status.idle":"2024-10-11T23:18:01.371526Z","shell.execute_reply.started":"2024-10-11T23:17:57.385870Z","shell.execute_reply":"2024-10-11T23:18:01.370518Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 1.5 Label encoding","metadata":{"_cell_guid":"bdb422e2-bdec-444f-97a5-283a1e54bf2c","_uuid":"39b7a31e843bac6b705461bcce89da216b91799e"}},{"cell_type":"code","source":"# Encode labels to one hot vectors (ex : 2 -> [0,0,1,0,0,0,0,0,0,0])\nY_train = to_categorical(Y_train, num_classes = 10)","metadata":{"_cell_guid":"4b7f3e78-44dc-4561-b1f0-9429ee024cf4","_execution_state":"idle","_uuid":"cabefd1478d5c1bdfe57fd6a34395340916a854c","execution":{"iopub.status.busy":"2024-10-11T23:18:01.372654Z","iopub.execute_input":"2024-10-11T23:18:01.373013Z","iopub.status.idle":"2024-10-11T23:18:01.378354Z","shell.execute_reply.started":"2024-10-11T23:18:01.372977Z","shell.execute_reply":"2024-10-11T23:18:01.377414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 1.6 Split training and valdiation set ","metadata":{"_cell_guid":"32152fc3-a570-4d64-8a7d-6c689a4acd33","_uuid":"d8abbbf31483b94e1b29d07c4c8253d1311648a7"}},{"cell_type":"code","source":"# Split the train and the validation set for the fitting\nX_train, X_val, Y_train, Y_val = train_test_split(X_train, Y_train, test_size = 0.2, random_state=2,stratify=Y_train)","metadata":{"_cell_guid":"dcd25ebb-d845-4d32-9867-082e352b1396","_execution_state":"idle","_uuid":"b779ac76d8317647db92d5a88b4098d212d72884","execution":{"iopub.status.busy":"2024-10-11T23:18:01.379751Z","iopub.execute_input":"2024-10-11T23:18:01.380155Z","iopub.status.idle":"2024-10-11T23:18:02.377954Z","shell.execute_reply.started":"2024-10-11T23:18:01.380071Z","shell.execute_reply":"2024-10-11T23:18:02.377138Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(X_train.shape)\nprint(Y_train.shape)\nprint(X_val.shape)\nprint(Y_val.shape)","metadata":{"execution":{"iopub.status.busy":"2024-10-11T23:18:02.379029Z","iopub.execute_input":"2024-10-11T23:18:02.379327Z","iopub.status.idle":"2024-10-11T23:18:02.384945Z","shell.execute_reply.started":"2024-10-11T23:18:02.379296Z","shell.execute_reply":"2024-10-11T23:18:02.383967Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"background-color: Green;  padding: 10px; border-radius: 10px; text-align: center;\">\n  <span style=\"color: white; font-size: 15px; font-weight: bold;\">\n      CNN Model\n</div>\n","metadata":{}},{"cell_type":"markdown","source":"# 2. CNN\n## 2.1 Define the model","metadata":{"_cell_guid":"d5265777-aeb3-449d-b171-d88cad74c0a4","_uuid":"5fa18b37a9acd9e098bac1d12264b0dd4310fdd3"}},{"cell_type":"code","source":"# Set the CNN model \n\nmodel = Sequential([\n\n        Conv2D(filters = 32, kernel_size = (5,5),padding = 'Same', activation ='relu', input_shape = (28,28,1)),\n        Conv2D(filters = 32, kernel_size = (5,5),padding = 'Same', activation ='relu'),\n        BatchNormalization(),\n        MaxPool2D(pool_size=(2,2)),\n        Dropout(0.25),\n\n\n        Conv2D(filters = 64, kernel_size = (3,3),padding = 'Same', activation ='relu'),\n        Conv2D(filters = 64, kernel_size = (3,3),padding = 'Same', activation ='relu'),\n        BatchNormalization()  ,  \n        MaxPool2D(pool_size=(2,2)),\n        Dropout(0.25),\n\n\n        Flatten(),\n        Dense(256, activation = \"relu\"),\n        Dropout(0.5),\n        Dense(10, activation = \"softmax\"),\n    ])\n    \n    \n# categorical_crossentropy with one hot encoded labels    \nmodel.compile(optimizer = 'adam', loss = 'categorical_crossentropy', metrics = ['accuracy'])\n\nprint(model.summary()) \n","metadata":{"_cell_guid":"1e0f3f88-2ad7-459e-8e02-aecc5f3511ae","_execution_state":"idle","_uuid":"f7991ef6871a26f9fa57acdcd460a69bab53e804","execution":{"iopub.status.busy":"2024-10-11T23:37:02.159259Z","iopub.execute_input":"2024-10-11T23:37:02.159664Z","iopub.status.idle":"2024-10-11T23:37:02.265628Z","shell.execute_reply.started":"2024-10-11T23:37:02.159626Z","shell.execute_reply":"2024-10-11T23:37:02.264781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"background-color: Green;  padding: 10px; border-radius: 10px; text-align: center;\">\n  <span style=\"color: white; font-size: 15px; font-weight: bold;\">\n      Data Augmentation\n</div>\n","metadata":{}},{"cell_type":"markdown","source":"## 2.3 Data augmentation ","metadata":{"_cell_guid":"241a0f4f-13f5-4b13-be1e-4e3e4a714c06","_uuid":"f24df64b223e0177c94025b6767ab19b722c5386"}},{"cell_type":"code","source":"datagen = ImageDataGenerator(\n        rotation_range=10,      # randomly rotate images in the range 5 degrees\n        zoom_range = 0.1,       # Randomly zoom image 10%\n        width_shift_range=0.1,  # randomly shift images horizontally 10%\n        height_shift_range=0.1,  # randomly shift images vertically 10%\n)\n\ndatagen.fit(X_train)","metadata":{"_cell_guid":"b342befe-1a6f-44bf-8dab-28033a729122","_execution_state":"idle","_uuid":"21d6192c87d92d497c797656474bccd9cefc5647","execution":{"iopub.status.busy":"2024-10-11T23:18:03.341325Z","iopub.execute_input":"2024-10-11T23:18:03.341596Z","iopub.status.idle":"2024-10-11T23:18:03.424952Z","shell.execute_reply.started":"2024-10-11T23:18:03.341566Z","shell.execute_reply":"2024-10-11T23:18:03.424134Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.shape","metadata":{"execution":{"iopub.status.busy":"2024-10-11T23:18:03.425979Z","iopub.execute_input":"2024-10-11T23:18:03.426273Z","iopub.status.idle":"2024-10-11T23:18:03.432210Z","shell.execute_reply.started":"2024-10-11T23:18:03.426242Z","shell.execute_reply":"2024-10-11T23:18:03.431380Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Fit the model\nbatch_size=128\nepochs = 12\n\nhistory = model.fit(datagen.flow(X_train,Y_train, batch_size=batch_size),\n                              epochs = epochs, validation_data = (X_val,Y_val),\n                              verbose = 2, steps_per_epoch=X_train.shape[0] // batch_size )","metadata":{"_cell_guid":"b453af8d-9736-43e3-b486-7a1cd7dd8909","_execution_state":"idle","_uuid":"cf36b3d029f95b553be02d612e097a9769ee8252","execution":{"iopub.status.busy":"2024-10-11T23:37:24.920322Z","iopub.execute_input":"2024-10-11T23:37:24.921043Z","iopub.status.idle":"2024-10-11T23:38:47.449842Z","shell.execute_reply.started":"2024-10-11T23:37:24.920999Z","shell.execute_reply":"2024-10-11T23:38:47.448924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"background-color: Green;  padding: 10px; border-radius: 10px; text-align: center;\">\n  <span style=\"color: white; font-size: 20px; font-weight: bold;\">\n      Evaluting\n</div>\n","metadata":{}},{"cell_type":"markdown","source":"# 3. Evaluate the model\n## 3.1 Training and validation curves","metadata":{"_cell_guid":"e758621d-b27b-40ff-a93f-bebd2e0e5243","_uuid":"0a1834f2a9f2db15dcaba4a84004b9627d714469"}},{"cell_type":"code","source":"history.history.keys()","metadata":{"execution":{"iopub.status.busy":"2024-10-11T23:39:20.286858Z","iopub.execute_input":"2024-10-11T23:39:20.287293Z","iopub.status.idle":"2024-10-11T23:39:20.294156Z","shell.execute_reply.started":"2024-10-11T23:39:20.287253Z","shell.execute_reply":"2024-10-11T23:39:20.293154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(history.history['accuracy'], color = 'b', label = 'Training Accuracy')\nplt.plot(history.history['val_accuracy'], color = 'r', label = 'Validation Accuracy')\nplt.title('Traning Accuracy Vs Validation Accuracy')\nplt.legend()\nplt.xlabel('Epoch')\nplt.ylabel('Accuracy')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-11T23:39:23.052954Z","iopub.execute_input":"2024-10-11T23:39:23.053943Z","iopub.status.idle":"2024-10-11T23:39:23.400406Z","shell.execute_reply.started":"2024-10-11T23:39:23.053901Z","shell.execute_reply":"2024-10-11T23:39:23.399460Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(history.history['loss'], color = 'b', label = 'Training Loss')\nplt.plot(history.history['val_loss'], color = 'r', label = 'Validation Loss')\nplt.title('Traning Loss Vs Validation Loss')\nplt.legend()\nplt.xlabel('Loss')\nplt.ylabel('Accuracy')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-10-11T23:40:05.503004Z","iopub.execute_input":"2024-10-11T23:40:05.503401Z","iopub.status.idle":"2024-10-11T23:40:05.789125Z","shell.execute_reply.started":"2024-10-11T23:40:05.503361Z","shell.execute_reply":"2024-10-11T23:40:05.788227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 3.2 Confusion matrix","metadata":{"_cell_guid":"de1c65bd-4a88-4351-9f4b-562e72e7e0fd","_uuid":"63698d7d51381b33892ce164b0f21930abb3e937"}},{"cell_type":"code","source":"def plot_confusion_matrix(true_labels, pred_labels, class_names):\n    \n    cm = confusion_matrix(true_labels, pred_labels)\n\n    plt.figure(figsize=(6, 6))\n    sns.heatmap(cm, annot=True, fmt=\"d\", cmap=\"Blues\", xticklabels=class_names, yticklabels=class_names)\n    \n    plt.title(\"Confusion Matrix\", fontsize=16)\n    plt.xlabel(\"Predicted Labels\", fontsize=12)\n    plt.ylabel(\"True Labels\", fontsize=12)\n    plt.tight_layout()\n    plt.show()\n    \n# -------------------------------------------------------------\n\ny_val_pred = model.predict(X_val)\nclass_names = list(np.arange(0, 10))\npred_labels = np.argmax(y_val_pred, axis=1)  \nplot_confusion_matrix(np.argmax(Y_val, axis = 1), pred_labels, class_names)","metadata":{"_cell_guid":"11361e73-8250-4bf5-a353-b0f8ea83e659","_execution_state":"idle","_uuid":"16e161179bf1b51ba66c39b2cead883f1db3a9c7","execution":{"iopub.status.busy":"2024-10-11T23:52:19.059588Z","iopub.execute_input":"2024-10-11T23:52:19.060007Z","iopub.status.idle":"2024-10-11T23:52:20.230024Z","shell.execute_reply.started":"2024-10-11T23:52:19.059968Z","shell.execute_reply":"2024-10-11T23:52:20.229035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"background-color: Green;  padding: 10px; border-radius: 10px; text-align: center;\">\n  <span style=\"color: white; font-size: 15px; font-weight: bold;\">\n      Predicting and Submission\n</div>\n","metadata":{}},{"cell_type":"code","source":"# predict results\nresults = model.predict(test)\nresults = np.argmax(results,axis = 1)\nresults.shape","metadata":{"_cell_guid":"05ff3b9f-c3bb-4cec-a8c2-2c128e8f15b3","_execution_state":"idle","_uuid":"7f17e7bf0a54a01a52fef2d554780f6bc6580dc6","execution":{"iopub.status.busy":"2024-10-12T00:03:28.199448Z","iopub.execute_input":"2024-10-12T00:03:28.200207Z","iopub.status.idle":"2024-10-12T00:03:30.066761Z","shell.execute_reply.started":"2024-10-12T00:03:28.200167Z","shell.execute_reply":"2024-10-12T00:03:30.065798Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig , ax = plt.subplots(5,5, figsize=(20,20))\nax = ax.flatten()\ni=0\nr_nums = np.random.randint(0,len(test), 25)\nfor n in  r_nums:\n    ax[i].imshow(test[n] , cmap = 'gray')\n    ax[i].axis('off')\n    ax[i].grid(False)\n    ax[i].set_title(results[n])\n    i+=1","metadata":{"execution":{"iopub.status.busy":"2024-10-12T00:13:40.441053Z","iopub.execute_input":"2024-10-12T00:13:40.441459Z","iopub.status.idle":"2024-10-12T00:13:44.324192Z","shell.execute_reply.started":"2024-10-12T00:13:40.441421Z","shell.execute_reply":"2024-10-12T00:13:44.323062Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.read_csv('/kaggle/input/digit-recognizer/sample_submission.csv')\nsubmission['Label'] = results\nsubmission","metadata":{"execution":{"iopub.status.busy":"2024-10-12T00:04:26.666955Z","iopub.execute_input":"2024-10-12T00:04:26.667857Z","iopub.status.idle":"2024-10-12T00:04:26.690275Z","shell.execute_reply.started":"2024-10-12T00:04:26.667814Z","shell.execute_reply":"2024-10-12T00:04:26.689280Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv(\"/kaggle/working/submission.csv\",index=False)","metadata":{"_cell_guid":"b5f1f39f-13b8-439a-8913-0f120e3d47a9","_execution_state":"idle","_uuid":"369dfaab09240f3f12bcff91953ffd315ab84985","execution":{"iopub.status.busy":"2024-10-12T00:07:45.159109Z","iopub.execute_input":"2024-10-12T00:07:45.159502Z","iopub.status.idle":"2024-10-12T00:07:45.198105Z","shell.execute_reply.started":"2024-10-12T00:07:45.159464Z","shell.execute_reply":"2024-10-12T00:07:45.197314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.save('model.h5')","metadata":{"execution":{"iopub.status.busy":"2024-10-12T00:10:08.649425Z","iopub.execute_input":"2024-10-12T00:10:08.650225Z","iopub.status.idle":"2024-10-12T00:10:08.743615Z","shell.execute_reply.started":"2024-10-12T00:10:08.650186Z","shell.execute_reply":"2024-10-12T00:10:08.742617Z"},"trusted":true},"execution_count":null,"outputs":[]}]}