{"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":"# 1. Artificial Neural Network","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\n\nimport matplotlib.pyplot as plt\n%matplotlib inline\n\nfrom sklearn.model_selection import train_test_split\n\n\ntrain = pd.read_csv(\"/kaggle/input/digit-recognizer/train.csv\")\ntest = pd.read_csv(\"/kaggle/input/digit-recognizer/test.csv\")\n\nprint(train.shape)\nprint(test.shape)\n\nX = train.drop('label', axis=1)\ny = train.label\n\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1, random_state=42)","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:37:15.783165Z","iopub.execute_input":"2023-02-07T13:37:15.783543Z","iopub.status.idle":"2023-02-07T13:37:19.228970Z","shell.execute_reply.started":"2023-02-07T13:37:15.783511Z","shell.execute_reply":"2023-02-07T13:37:19.227971Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Explore the data\n\nLet's explore the format of the dataset before training the model. The following shows there are 60,000 images in the training set, with each image represented as 28 x 28 pixels:","metadata":{}},{"cell_type":"code","source":"X_train = X_train.values.reshape(-1,28, 28)\nX_test = X_test.values.reshape(-1, 28, 28)\n\nX_test = np.array(X_test)\ny_test = np.array(y_test)\n\nprint(\"Train shape:\")\nprint(X_train.shape)\nprint(y_train.shape)\n\nprint(\"Test shape:\")\nprint(X_test.shape)\nprint(y_test.shape)","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:37:19.231106Z","iopub.execute_input":"2023-02-07T13:37:19.231477Z","iopub.status.idle":"2023-02-07T13:37:19.245204Z","shell.execute_reply.started":"2023-02-07T13:37:19.231443Z","shell.execute_reply":"2023-02-07T13:37:19.243950Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Preprocess the data\n\nThe data must be preprocessed before training the network. If you inspect the first image in the training set, you will see that the pixel values fall in the range of 0 to 255:","metadata":{}},{"cell_type":"code","source":"plt.figure()\nplt.imshow(X_train[0])\nplt.colorbar()\nplt.grid(False)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:37:19.246805Z","iopub.execute_input":"2023-02-07T13:37:19.247183Z","iopub.status.idle":"2023-02-07T13:37:19.485338Z","shell.execute_reply.started":"2023-02-07T13:37:19.247148Z","shell.execute_reply":"2023-02-07T13:37:19.484465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Scale these values to a range of 0 to 1 before feeding them to the neural network model. To do so, divide the values by 255. It's important that the training set and the testing set be preprocessed in the same way:","metadata":{}},{"cell_type":"code","source":"X_train = X_train / 255.0\nX_test = X_test / 255.0","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:37:19.487939Z","iopub.execute_input":"2023-02-07T13:37:19.488292Z","iopub.status.idle":"2023-02-07T13:37:19.590716Z","shell.execute_reply.started":"2023-02-07T13:37:19.488257Z","shell.execute_reply":"2023-02-07T13:37:19.589720Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"To verify that the data is in the correct format and that you're ready to build and train the network, let's display the first 25 images from the training set and display the class name below each image.","metadata":{}},{"cell_type":"code","source":"y_train.iloc[1]","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:37:19.592375Z","iopub.execute_input":"2023-02-07T13:37:19.592810Z","iopub.status.idle":"2023-02-07T13:37:19.600226Z","shell.execute_reply.started":"2023-02-07T13:37:19.592769Z","shell.execute_reply":"2023-02-07T13:37:19.598897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10, 15))\nfor i in range(25):\n    plt.subplot(5, 5, i + 1)\n    plt.grid(False)\n    plt.imshow(X_train[i], cmap=plt.cm.binary)\n    plt.xlabel(y_train.iloc[i])\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:37:19.601825Z","iopub.execute_input":"2023-02-07T13:37:19.602286Z","iopub.status.idle":"2023-02-07T13:37:21.568158Z","shell.execute_reply.started":"2023-02-07T13:37:19.602252Z","shell.execute_reply":"2023-02-07T13:37:21.566844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Build the model\nBuilding the neural network requires configuring the layers of the model, then compiling the model.\n\n## Set up the layers\nThe basic building block of a neural network is the *layer*. Layers extract representations from the data fed into them. Hopefully, these representations are meaningful for the problem at hand.\n\n\nMost of deep learning consists of chaining together simple layers. Most layers, such as `tf.keras.layers.Dense`, have parameters that are learned during training.","metadata":{}},{"cell_type":"code","source":"from tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Dense, Dropout, Flatten\nfrom tensorflow.keras.optimizers import Adam\n\nmodel = Sequential(\n    [\n        Flatten(input_shape=(28, 28)), \n        Dense(128, activation='relu'), \n        Dropout(0.2),\n        Dense(10, activation='softmax')\n    ]\n)","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:37:21.569743Z","iopub.execute_input":"2023-02-07T13:37:21.570354Z","iopub.status.idle":"2023-02-07T13:37:21.599524Z","shell.execute_reply.started":"2023-02-07T13:37:21.570315Z","shell.execute_reply":"2023-02-07T13:37:21.598698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The first layer in this network, `tf.keras.layers.Flatten`, transforms the format of the images from a two-dimensional array (of 28 by 28 pixels) to a one-dimensional array (of 28 * 28 = 784 pixels). Think of this layer as unstacking rows of pixels in the image and lining them up. This layer has no parameters to learn; it only reformats the data.\n\nAfter the pixels are flattened, the network consists of a sequence of two `tf.keras.layers.Dense` layers. These are densely connected, or fully connected, neural layers. The first Dense layer has 128 nodes (or neurons). The second (and last) layer is a 10-node softmax layer that returns an array of 10 probability scores that sum to 1. Each node contains a score that indicates the probability that the current image belongs to one of the 10 classes.\n****","metadata":{}},{"cell_type":"markdown","source":"## Compile the model\nBefore the model is ready for training, it needs a few more settings. These are added during the model's compile step:\n\n- *Loss function* —This measures how accurate the model is during training. You want to minimize this function to \"steer\" the model in the right direction.\n- *Optimizer* —This is how the model is updated based on the data it sees and its loss function.\n- *Metrics* —Used to monitor the training and testing steps. The following example uses *accuracy*, the fraction of the images that are correctly classified.","metadata":{}},{"cell_type":"code","source":"model.compile(\n    optimizer=Adam(0.001), \n    loss='sparse_categorical_crossentropy', \n    metrics=['accuracy']\n)","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:37:21.601003Z","iopub.execute_input":"2023-02-07T13:37:21.601352Z","iopub.status.idle":"2023-02-07T13:37:21.610096Z","shell.execute_reply.started":"2023-02-07T13:37:21.601317Z","shell.execute_reply":"2023-02-07T13:37:21.609066Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Train the model\n\nTraining the neural network model requires the following steps:\n\n1. Feed the training data to the model. In this example, the training data is in the `X_train` and `y_train` arrays.\n2. The model learns to associate images and labels.\n3. You ask the model to make predictions about a test set—in this example, the `X_test` array. Verify that the predictions match the labels from the `y_test` array.\n\nTo start training, call the `model.fit` method—so called because it \"fits\" the model to the training data:","metadata":{}},{"cell_type":"code","source":"r = model.fit(\n    X_train, y_train, \n    validation_data=(X_test, y_test),\n    epochs=20\n)","metadata":{"scrolled":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2023-02-07T13:37:21.611290Z","iopub.execute_input":"2023-02-07T13:37:21.611858Z","iopub.status.idle":"2023-02-07T13:38:13.623624Z","shell.execute_reply.started":"2023-02-07T13:37:21.611812Z","shell.execute_reply":"2023-02-07T13:38:13.622676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"As the model trains, the loss and accuracy metrics are displayed. This model reaches an accuracy of about 0.99 (or 99%) on the training data.","metadata":{}},{"cell_type":"markdown","source":"## Evaluate accuracy\nNext, compare how the model performs on the test dataset:","metadata":{}},{"cell_type":"code","source":"train_loss, train_acc = model.evaluate(X_train, y_train, verbose=2)\nprint(f'Train accuracy: {train_acc}\\n')\n\ntest_loss, test_acc = model.evaluate(X_test, y_test, verbose=2)\nprint(f'Test accuracy: {test_acc}\\n')","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:38:13.628033Z","iopub.execute_input":"2023-02-07T13:38:13.628319Z","iopub.status.idle":"2023-02-07T13:38:15.947561Z","shell.execute_reply.started":"2023-02-07T13:38:13.628287Z","shell.execute_reply":"2023-02-07T13:38:15.946228Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12, 8))\n\nplt.subplot(2, 2, 1)\nplt.plot(r.history['loss'], label='loss')\nplt.plot(r.history['val_loss'], label='val_loss')\nplt.xlabel(\"Epochs\")\nplt.ylabel(\"Loss function\")\nplt.legend()\n\nplt.subplot(2, 2, 2)\nplt.plot(r.history['accuracy'], label='accuracy')\nplt.plot(r.history['val_accuracy'], label='val_accuracy')\nplt.xlabel(\"Epochs\")\nplt.ylabel(\"Accuracy\")\nplt.legend()","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:38:15.948935Z","iopub.execute_input":"2023-02-07T13:38:15.949331Z","iopub.status.idle":"2023-02-07T13:38:16.287399Z","shell.execute_reply.started":"2023-02-07T13:38:15.949293Z","shell.execute_reply":"2023-02-07T13:38:16.286465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"It turns out that the accuracy on the test dataset is a little less than the accuracy on the training dataset. This gap between training accuracy and test accuracy represents overfitting. Overfitting is when a machine learning model performs worse on new, previously unseen inputs than on the training data.","metadata":{}},{"cell_type":"markdown","source":"## Makes predictions\n\nWith the model trained, you can use it to make predictions about some images.","metadata":{}},{"cell_type":"code","source":"predictions = model.predict(X_test)\npredictions[0]","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:38:16.288927Z","iopub.execute_input":"2023-02-07T13:38:16.289522Z","iopub.status.idle":"2023-02-07T13:38:16.508646Z","shell.execute_reply.started":"2023-02-07T13:38:16.289482Z","shell.execute_reply":"2023-02-07T13:38:16.507506Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Here, the model has predicted the label for each image in the testing set. Let's take a look at the first prediction:\n\nA prediction is an array of 10 numbers. They represent the model's \"confidence\" that the image corresponds to each of the 10 different articles of clothing. You can see which label has the highest confidence value:","metadata":{}},{"cell_type":"code","source":"np.argmax(predictions[0])","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:38:16.510296Z","iopub.execute_input":"2023-02-07T13:38:16.510799Z","iopub.status.idle":"2023-02-07T13:38:16.520491Z","shell.execute_reply.started":"2023-02-07T13:38:16.510721Z","shell.execute_reply":"2023-02-07T13:38:16.519207Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"So, the model is most confident that the number on this image is a 7. Examining the test label shows that this classification is correct:","metadata":{}},{"cell_type":"code","source":"y_test[0]","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:38:16.522193Z","iopub.execute_input":"2023-02-07T13:38:16.522719Z","iopub.status.idle":"2023-02-07T13:38:16.529457Z","shell.execute_reply.started":"2023-02-07T13:38:16.522683Z","shell.execute_reply":"2023-02-07T13:38:16.528489Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Graph this to look at the full set of 10 class predictions.","metadata":{}},{"cell_type":"code","source":"def plot_image(i, predictions_array, true_label, img):\n    predictions_array, true_label, img = predictions_array, true_label[i], img[i]\n    plt.grid(False)\n    plt.xticks([])\n    plt.yticks([])\n\n    plt.imshow(img, cmap=plt.cm.binary)\n\n    predicted_label = np.argmax(predictions_array)\n    if predicted_label == true_label:\n        color = 'blue'\n    else:\n        color = 'red'\n\n    plt.xlabel(f\"{predicted_label} {100*np.max(predictions_array):2.0f}% ({true_label})\", \n               color=color)\n\ndef plot_value_array(i, predictions_array, true_label):\n    predictions_array, true_label = predictions_array, true_label[i]\n    plt.grid(False)\n    plt.xticks(range(10))\n    plt.yticks([])\n    thisplot = plt.bar(range(10), predictions_array, color=\"#777777\")\n    plt.ylim([0, 1])\n    predicted_label = np.argmax(predictions_array)\n\n    thisplot[predicted_label].set_color('red')\n    thisplot[true_label].set_color('blue')","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:38:16.530582Z","iopub.execute_input":"2023-02-07T13:38:16.531193Z","iopub.status.idle":"2023-02-07T13:38:16.541487Z","shell.execute_reply.started":"2023-02-07T13:38:16.531159Z","shell.execute_reply":"2023-02-07T13:38:16.540423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's look at the 0th image, predictions, and prediction array. Correct prediction labels are blue and incorrect prediction labels are red. The number gives the percentage (out of 100) for the predicted label.","metadata":{}},{"cell_type":"code","source":"i = 0\nplt.figure(figsize=(6,3))\nplt.subplot(1,2,1)\nplot_image(i, predictions[i], y_test, X_test)\nplt.subplot(1,2,2)\nplot_value_array(i, predictions[i],  y_test)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:38:16.542821Z","iopub.execute_input":"2023-02-07T13:38:16.543321Z","iopub.status.idle":"2023-02-07T13:38:16.701320Z","shell.execute_reply.started":"2023-02-07T13:38:16.543288Z","shell.execute_reply":"2023-02-07T13:38:16.700107Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"i = 12\nplt.figure(figsize=(6,3))\nplt.subplot(1,2,1)\nplot_image(i, predictions[i], y_test, X_test)\nplt.subplot(1,2,2)\nplot_value_array(i, predictions[i],  y_test)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:38:16.703145Z","iopub.execute_input":"2023-02-07T13:38:16.703504Z","iopub.status.idle":"2023-02-07T13:38:16.889625Z","shell.execute_reply.started":"2023-02-07T13:38:16.703468Z","shell.execute_reply":"2023-02-07T13:38:16.888494Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's plot several images with their predictions. Note that the model can be wrong even when very confident.","metadata":{}},{"cell_type":"code","source":"# Plot the first X test images, their predicted labels, and the true labels.\n# Color correct predictions in blue and incorrect predictions in red.\nnum_rows = 5\nnum_cols = 3\nnum_images = num_rows * num_cols\nplt.figure(figsize=(2 * 2 * num_cols, 2 * num_rows))\nfor i in range(num_images):\n    plt.subplot(num_rows, 2 * num_cols, 2 * i + 1)\n    plot_image(i, predictions[i], y_test, X_test)\n    plt.subplot(num_rows, 2*num_cols, 2*i+2)\n    plot_value_array(i, predictions[i], y_test)\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:38:16.891301Z","iopub.execute_input":"2023-02-07T13:38:16.891645Z","iopub.status.idle":"2023-02-07T13:38:19.046452Z","shell.execute_reply.started":"2023-02-07T13:38:16.891611Z","shell.execute_reply":"2023-02-07T13:38:19.045493Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 2. Convolutional Neural Networks (CNNs)","metadata":{}},{"cell_type":"markdown","source":"## Reshaping the data","metadata":{}},{"cell_type":"code","source":"X_train = np.expand_dims(X_train, -1)\nX_test = np.expand_dims(X_test, -1)","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:38:19.047774Z","iopub.execute_input":"2023-02-07T13:38:19.048151Z","iopub.status.idle":"2023-02-07T13:38:19.053813Z","shell.execute_reply.started":"2023-02-07T13:38:19.048112Z","shell.execute_reply":"2023-02-07T13:38:19.052544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.layers import Conv2D, MaxPool2D\nfrom keras.callbacks import EarlyStopping","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:38:19.055246Z","iopub.execute_input":"2023-02-07T13:38:19.055508Z","iopub.status.idle":"2023-02-07T13:38:19.062914Z","shell.execute_reply.started":"2023-02-07T13:38:19.055485Z","shell.execute_reply":"2023-02-07T13:38:19.061659Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = Sequential()\n\nmodel.add(Conv2D(filters=32, kernel_size=(5, 5), activation='relu', padding='same', \n                 input_shape=X_train[0].shape))\nmodel.add(Conv2D(filters=32, kernel_size=(5, 5), activation='relu', padding='same'))\nmodel.add(MaxPool2D(pool_size=(2, 2)))\nmodel.add(Dropout(0.25))\n\nmodel.add(Conv2D(filters=32, kernel_size=(3, 3), activation='relu', padding='same', \n                 input_shape=X_train[0].shape))\nmodel.add(Conv2D(filters=32, kernel_size=(3, 3), activation='relu', padding='same'))\nmodel.add(MaxPool2D(pool_size=(2, 2), strides=(2, 2)))\nmodel.add(Dropout(0.25))\n\nmodel.add(Flatten())\nmodel.add(Dense(256, activation='relu'))\nmodel.add(Dropout(0.5))\n\nmodel.add(Dense(10, activation='softmax'))\n\nmodel.compile(\n    loss='sparse_categorical_crossentropy', \n    optimizer=Adam(0.0001), \n    metrics=['accuracy']\n)","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:38:19.064529Z","iopub.execute_input":"2023-02-07T13:38:19.065264Z","iopub.status.idle":"2023-02-07T13:38:19.138423Z","shell.execute_reply.started":"2023-02-07T13:38:19.065229Z","shell.execute_reply":"2023-02-07T13:38:19.137588Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"early_stop = EarlyStopping(monitor='val_loss', patience=2)","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:38:19.139650Z","iopub.execute_input":"2023-02-07T13:38:19.140069Z","iopub.status.idle":"2023-02-07T13:38:19.145478Z","shell.execute_reply.started":"2023-02-07T13:38:19.140035Z","shell.execute_reply":"2023-02-07T13:38:19.144344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"r = model.fit(\n    X_train, y_train, epochs=10, \n    validation_data=(X_test, y_test), \n    callbacks=[early_stop]\n)","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2023-02-07T13:38:19.146998Z","iopub.execute_input":"2023-02-07T13:38:19.147355Z","iopub.status.idle":"2023-02-07T13:39:05.458440Z","shell.execute_reply.started":"2023-02-07T13:38:19.147318Z","shell.execute_reply":"2023-02-07T13:39:05.457471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_loss, train_acc = model.evaluate(X_train, y_train, verbose=2)\nprint(f'\\nTrain accuracy: {train_acc}')\n\ntest_loss, test_acc = model.evaluate(X_test, y_test, verbose=2)\nprint(f'\\nTest accuracy: {test_acc}')","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:39:05.460267Z","iopub.execute_input":"2023-02-07T13:39:05.460666Z","iopub.status.idle":"2023-02-07T13:39:08.124729Z","shell.execute_reply.started":"2023-02-07T13:39:05.460628Z","shell.execute_reply":"2023-02-07T13:39:08.123823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"r = model.fit(X_test, y_test, epochs=10)","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2023-02-07T13:39:08.127806Z","iopub.execute_input":"2023-02-07T13:39:08.128099Z","iopub.status.idle":"2023-02-07T13:39:13.289556Z","shell.execute_reply.started":"2023-02-07T13:39:08.128072Z","shell.execute_reply":"2023-02-07T13:39:13.288603Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 3. Predict the test images","metadata":{}},{"cell_type":"code","source":"test = test / 255","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:39:13.292715Z","iopub.execute_input":"2023-02-07T13:39:13.293610Z","iopub.status.idle":"2023-02-07T13:39:13.372948Z","shell.execute_reply.started":"2023-02-07T13:39:13.293570Z","shell.execute_reply":"2023-02-07T13:39:13.371902Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = test.values.reshape(-1, 28, 28, 1)\ntest.shape","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:39:13.374565Z","iopub.execute_input":"2023-02-07T13:39:13.374952Z","iopub.status.idle":"2023-02-07T13:39:13.382934Z","shell.execute_reply.started":"2023-02-07T13:39:13.374905Z","shell.execute_reply":"2023-02-07T13:39:13.381899Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions = model.predict(test)","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:39:13.388767Z","iopub.execute_input":"2023-02-07T13:39:13.389664Z","iopub.status.idle":"2023-02-07T13:39:14.961080Z","shell.execute_reply.started":"2023-02-07T13:39:13.389629Z","shell.execute_reply":"2023-02-07T13:39:14.960081Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions = np.argmax(predictions, axis=1)\npredictions","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:39:14.962858Z","iopub.execute_input":"2023-02-07T13:39:14.963246Z","iopub.status.idle":"2023-02-07T13:39:14.973949Z","shell.execute_reply.started":"2023-02-07T13:39:14.963206Z","shell.execute_reply":"2023-02-07T13:39:14.972723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.read_csv('/kaggle/input/digit-recognizer/sample_submission.csv')\nsubmission['Label'] = predictions\nsubmission.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2023-02-07T13:39:14.975412Z","iopub.execute_input":"2023-02-07T13:39:14.975759Z","iopub.status.idle":"2023-02-07T13:39:15.012293Z","shell.execute_reply.started":"2023-02-07T13:39:14.975727Z","shell.execute_reply":"2023-02-07T13:39:15.011469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}