{"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-19T03:49:53.411547Z","iopub.execute_input":"2022-12-19T03:49:53.412091Z","iopub.status.idle":"2022-12-19T03:49:53.429951Z","shell.execute_reply.started":"2022-12-19T03:49:53.411973Z","shell.execute_reply":"2022-12-19T03:49:53.428769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n%matplotlib inline\n\n# from keras.datasets import mnist\nimport tensorflow as tf\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, Dropout, Activation\nfrom tensorflow.keras.callbacks import EarlyStopping\nfrom tensorflow.keras.utils import to_categorical\nfrom tensorflow.keras.layers import BatchNormalization\n\nfrom keras.regularizers import l2\n\nfrom sklearn.metrics import classification_report, confusion_matrix, accuracy_score, precision_score, recall_score","metadata":{"execution":{"iopub.status.busy":"2022-12-19T03:49:53.431707Z","iopub.execute_input":"2022-12-19T03:49:53.432061Z","iopub.status.idle":"2022-12-19T03:50:01.074524Z","shell.execute_reply.started":"2022-12-19T03:49:53.432028Z","shell.execute_reply":"2022-12-19T03:50:01.073188Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')\ndf_train","metadata":{"execution":{"iopub.status.busy":"2022-12-19T03:50:01.076842Z","iopub.execute_input":"2022-12-19T03:50:01.077275Z","iopub.status.idle":"2022-12-19T03:50:05.159137Z","shell.execute_reply.started":"2022-12-19T03:50:01.077229Z","shell.execute_reply":"2022-12-19T03:50:05.158061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = pd.read_csv('/kaggle/input/digit-recognizer/test.csv')\ndf_test","metadata":{"execution":{"iopub.status.busy":"2022-12-19T03:50:05.160869Z","iopub.execute_input":"2022-12-19T03:50:05.161194Z","iopub.status.idle":"2022-12-19T03:50:07.469342Z","shell.execute_reply.started":"2022-12-19T03:50:05.161160Z","shell.execute_reply":"2022-12-19T03:50:07.468293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.shape, df_test.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-19T03:50:07.470810Z","iopub.execute_input":"2022-12-19T03:50:07.471431Z","iopub.status.idle":"2022-12-19T03:50:07.478675Z","shell.execute_reply.started":"2022-12-19T03:50:07.471384Z","shell.execute_reply":"2022-12-19T03:50:07.477620Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(x=\"label\", data=df_train)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-19T03:50:07.479910Z","iopub.execute_input":"2022-12-19T03:50:07.480226Z","iopub.status.idle":"2022-12-19T03:50:07.672611Z","shell.execute_reply.started":"2022-12-19T03:50:07.480196Z","shell.execute_reply":"2022-12-19T03:50:07.671580Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(12,12))\nfor i in range(36):\n    img = np.asarray(df_train.iloc[i,1:].values.reshape((28,28)))\n    plt.subplot(6,6, i+1)\n    plt.imshow(img, cmap='gray')\n    plt.title(df_train['label'][i], color=\"red\")\n# print(img)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-19T03:50:07.673870Z","iopub.execute_input":"2022-12-19T03:50:07.674161Z","iopub.status.idle":"2022-12-19T03:50:10.651727Z","shell.execute_reply.started":"2022-12-19T03:50:07.674133Z","shell.execute_reply":"2022-12-19T03:50:10.651008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train test split\nX = df_train.drop(['label'],1)\ny = df_train['label']\nX_test = df_test.copy()\n\nX_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.3, random_state=23)\nX_train.shape, X_val.shape, y_train.shape, y_val.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-19T03:50:10.653713Z","iopub.execute_input":"2022-12-19T03:50:10.654115Z","iopub.status.idle":"2022-12-19T03:50:11.189103Z","shell.execute_reply.started":"2022-12-19T03:50:10.654083Z","shell.execute_reply":"2022-12-19T03:50:11.188092Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_rows, img_cols = 28, 28\ninput_shape = (img_rows, img_cols, 1)","metadata":{"execution":{"iopub.status.busy":"2022-12-19T03:50:11.190916Z","iopub.execute_input":"2022-12-19T03:50:11.191238Z","iopub.status.idle":"2022-12-19T03:50:11.195724Z","shell.execute_reply.started":"2022-12-19T03:50:11.191203Z","shell.execute_reply":"2022-12-19T03:50:11.194644Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = X_train.values.reshape(X_train.shape[0], img_rows, img_cols, 1)\nX_train.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-19T03:50:11.197068Z","iopub.execute_input":"2022-12-19T03:50:11.197417Z","iopub.status.idle":"2022-12-19T03:50:11.210279Z","shell.execute_reply.started":"2022-12-19T03:50:11.197375Z","shell.execute_reply":"2022-12-19T03:50:11.209294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test = X_test.values.reshape(X_test.shape[0], img_rows, img_cols, 1)\nX_test.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-19T03:50:11.212134Z","iopub.execute_input":"2022-12-19T03:50:11.212848Z","iopub.status.idle":"2022-12-19T03:50:11.225667Z","shell.execute_reply.started":"2022-12-19T03:50:11.212797Z","shell.execute_reply":"2022-12-19T03:50:11.224159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_val = X_val.values.reshape(X_val.shape[0], img_rows, img_cols, 1)\nX_val.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-19T03:50:11.227236Z","iopub.execute_input":"2022-12-19T03:50:11.227611Z","iopub.status.idle":"2022-12-19T03:50:11.237560Z","shell.execute_reply.started":"2022-12-19T03:50:11.227577Z","shell.execute_reply":"2022-12-19T03:50:11.236456Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train[0:11]","metadata":{"execution":{"iopub.status.busy":"2022-12-19T03:50:11.238862Z","iopub.execute_input":"2022-12-19T03:50:11.239360Z","iopub.status.idle":"2022-12-19T03:50:11.252887Z","shell.execute_reply.started":"2022-12-19T03:50:11.239282Z","shell.execute_reply":"2022-12-19T03:50:11.251752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_classes = 10","metadata":{"execution":{"iopub.status.busy":"2022-12-19T03:50:11.254234Z","iopub.execute_input":"2022-12-19T03:50:11.254589Z","iopub.status.idle":"2022-12-19T03:50:11.263989Z","shell.execute_reply.started":"2022-12-19T03:50:11.254556Z","shell.execute_reply":"2022-12-19T03:50:11.263109Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train_cat = to_categorical(y_train, num_classes)\ny_val_cat = to_categorical(y_val, num_classes)\n# y_test_cat = to_categorical(y_test, 10)\nprint(y_train_cat.shape, y_val_cat.shape)","metadata":{"execution":{"iopub.status.busy":"2022-12-19T03:50:11.265283Z","iopub.execute_input":"2022-12-19T03:50:11.265885Z","iopub.status.idle":"2022-12-19T03:50:11.277774Z","shell.execute_reply.started":"2022-12-19T03:50:11.265848Z","shell.execute_reply":"2022-12-19T03:50:11.276777Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train_cat[0:11]","metadata":{"execution":{"iopub.status.busy":"2022-12-19T03:50:11.279283Z","iopub.execute_input":"2022-12-19T03:50:11.279879Z","iopub.status.idle":"2022-12-19T03:50:11.291604Z","shell.execute_reply.started":"2022-12-19T03:50:11.279840Z","shell.execute_reply":"2022-12-19T03:50:11.290464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# X_train[0]","metadata":{"execution":{"iopub.status.busy":"2022-12-19T03:50:11.293156Z","iopub.execute_input":"2022-12-19T03:50:11.293495Z","iopub.status.idle":"2022-12-19T03:50:11.299985Z","shell.execute_reply.started":"2022-12-19T03:50:11.293464Z","shell.execute_reply":"2022-12-19T03:50:11.299111Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# for i in range(6, 9):\n#     plt.subplot(330 + (i+1))\n#     plt.imshow(X_train[i], cmap=plt.get_cmap('gray'))\n#     plt.title(y_train[i]);","metadata":{"execution":{"iopub.status.busy":"2022-12-19T03:50:11.301450Z","iopub.execute_input":"2022-12-19T03:50:11.301770Z","iopub.status.idle":"2022-12-19T03:50:11.310636Z","shell.execute_reply.started":"2022-12-19T03:50:11.301738Z","shell.execute_reply":"2022-12-19T03:50:11.309733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# model = keras.Sequential([\n#     layers.Dense(512, activation='relu', input_shape=[784]),\n#     layers.Dropout(0.3),\n#     layers.BatchNormalization(),\n#     layers.Dense(512, activation='relu'),\n#     layers.Dropout(0.3),\n#     layers.BatchNormalization(),\n#     layers.Dense(512, activation='relu'),\n#     layers.Dropout(0.3),\n#     layers.BatchNormalization(),\n#     layers.Dense(1, activation='softmax')\n# ])","metadata":{"execution":{"iopub.status.busy":"2022-12-19T03:50:11.311831Z","iopub.execute_input":"2022-12-19T03:50:11.312180Z","iopub.status.idle":"2022-12-19T03:50:11.323508Z","shell.execute_reply.started":"2022-12-19T03:50:11.312148Z","shell.execute_reply":"2022-12-19T03:50:11.322507Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = Sequential()\nmodel.add(Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=input_shape)) \n\nmodel.add(BatchNormalization())\nmodel.add(Conv2D(64, kernel_size=(3, 3), activation='relu'))\nmodel.add(BatchNormalization())\nmodel.add(MaxPooling2D(pool_size=(2, 2)))\nmodel.add(Dropout(0.25))\n\nmodel.add(BatchNormalization())\nmodel.add(Conv2D(128, kernel_size=(3, 3), activation='relu'))\nmodel.add(BatchNormalization())\n# model.add(MaxPooling2D(pool_size=(2, 2)))\nmodel.add(Dropout(0.5))\n\nmodel.add(Flatten())\nmodel.add(Dense(256,kernel_regularizer=l2(0.01)))\nmodel.add(Activation('relu'))\nmodel.add(Dropout(0.25))\nmodel.add(Dense(num_classes, activation='softmax'))","metadata":{"execution":{"iopub.status.busy":"2022-12-19T03:50:11.324753Z","iopub.execute_input":"2022-12-19T03:50:11.325114Z","iopub.status.idle":"2022-12-19T03:50:11.540968Z","shell.execute_reply.started":"2022-12-19T03:50:11.325063Z","shell.execute_reply":"2022-12-19T03:50:11.540094Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(optimizer=\"adam\", loss=\"categorical_crossentropy\", metrics=['categorical_accuracy'])","metadata":{"execution":{"iopub.status.busy":"2022-12-19T03:50:11.542098Z","iopub.execute_input":"2022-12-19T03:50:11.542410Z","iopub.status.idle":"2022-12-19T03:50:11.556783Z","shell.execute_reply.started":"2022-12-19T03:50:11.542375Z","shell.execute_reply":"2022-12-19T03:50:11.556004Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"early_stopping = EarlyStopping(min_delta = 0.001, monitor='val_loss', patience=10, restore_best_weights=True)","metadata":{"execution":{"iopub.status.busy":"2022-12-19T03:50:11.557921Z","iopub.execute_input":"2022-12-19T03:50:11.558451Z","iopub.status.idle":"2022-12-19T03:50:11.566349Z","shell.execute_reply.started":"2022-12-19T03:50:11.558418Z","shell.execute_reply":"2022-12-19T03:50:11.565253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit(X_train, y_train_cat,validation_data=(X_val, y_val_cat),batch_size=100,epochs=50,callbacks=[early_stopping])","metadata":{"execution":{"iopub.status.busy":"2022-12-19T03:50:11.569894Z","iopub.execute_input":"2022-12-19T03:50:11.570211Z","iopub.status.idle":"2022-12-19T04:56:49.431161Z","shell.execute_reply.started":"2022-12-19T03:50:11.570183Z","shell.execute_reply":"2022-12-19T04:56:49.430375Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history_df = pd.DataFrame(history.history)\nhistory_df.columns","metadata":{"execution":{"iopub.status.busy":"2022-12-19T04:56:49.433417Z","iopub.execute_input":"2022-12-19T04:56:49.433728Z","iopub.status.idle":"2022-12-19T04:56:49.443028Z","shell.execute_reply.started":"2022-12-19T04:56:49.433696Z","shell.execute_reply":"2022-12-19T04:56:49.441870Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history_df.loc[:, ['loss', 'val_loss']].plot()","metadata":{"execution":{"iopub.status.busy":"2022-12-19T04:56:49.444626Z","iopub.execute_input":"2022-12-19T04:56:49.445230Z","iopub.status.idle":"2022-12-19T04:56:49.650043Z","shell.execute_reply.started":"2022-12-19T04:56:49.445185Z","shell.execute_reply":"2022-12-19T04:56:49.649273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history_df.loc[:, ['categorical_accuracy','val_categorical_accuracy']].plot()","metadata":{"execution":{"iopub.status.busy":"2022-12-19T04:56:49.651144Z","iopub.execute_input":"2022-12-19T04:56:49.651574Z","iopub.status.idle":"2022-12-19T04:56:49.843215Z","shell.execute_reply.started":"2022-12-19T04:56:49.651528Z","shell.execute_reply":"2022-12-19T04:56:49.842442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"score = model.evaluate(X_train, y_train_cat, verbose=1)\nprint('Train loss:', score[0])\nprint('Train accuracy:', score[1])","metadata":{"execution":{"iopub.status.busy":"2022-12-19T04:56:49.844506Z","iopub.execute_input":"2022-12-19T04:56:49.845071Z","iopub.status.idle":"2022-12-19T04:57:10.869291Z","shell.execute_reply.started":"2022-12-19T04:56:49.845026Z","shell.execute_reply":"2022-12-19T04:57:10.868449Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"score = model.evaluate(X_val, y_val_cat, verbose=1)\nprint('Val loss:', score[0])\nprint('Val accuracy:', score[1])","metadata":{"execution":{"iopub.status.busy":"2022-12-19T04:57:10.870558Z","iopub.execute_input":"2022-12-19T04:57:10.870962Z","iopub.status.idle":"2022-12-19T04:57:19.514056Z","shell.execute_reply.started":"2022-12-19T04:57:10.870928Z","shell.execute_reply":"2022-12-19T04:57:19.513250Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Fix these to be fit again with X,y for X_test, y_test","metadata":{}},{"cell_type":"code","source":"X = X.values.reshape(X.shape[0], img_rows, img_cols, 1)\nX.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-19T04:57:19.515306Z","iopub.execute_input":"2022-12-19T04:57:19.515722Z","iopub.status.idle":"2022-12-19T04:57:19.521394Z","shell.execute_reply.started":"2022-12-19T04:57:19.515685Z","shell.execute_reply":"2022-12-19T04:57:19.520736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_cat = to_categorical(y, 10)\ny_cat.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-19T04:57:19.522363Z","iopub.execute_input":"2022-12-19T04:57:19.522784Z","iopub.status.idle":"2022-12-19T04:57:19.535519Z","shell.execute_reply.started":"2022-12-19T04:57:19.522754Z","shell.execute_reply":"2022-12-19T04:57:19.534593Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#history\nhistory = model.fit(X, y_cat,batch_size=100,epochs=50,callbacks=[early_stopping])","metadata":{"execution":{"iopub.status.busy":"2022-12-19T04:57:19.536912Z","iopub.execute_input":"2022-12-19T04:57:19.537343Z","iopub.status.idle":"2022-12-19T06:17:52.693148Z","shell.execute_reply.started":"2022-12-19T04:57:19.537280Z","shell.execute_reply":"2022-12-19T06:17:52.692092Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history_df = pd.DataFrame(history.history)\nhistory_df.columns","metadata":{"execution":{"iopub.status.busy":"2022-12-19T06:17:52.694823Z","iopub.execute_input":"2022-12-19T06:17:52.695227Z","iopub.status.idle":"2022-12-19T06:17:52.703496Z","shell.execute_reply.started":"2022-12-19T06:17:52.695186Z","shell.execute_reply":"2022-12-19T06:17:52.702431Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#score","metadata":{"execution":{"iopub.status.busy":"2022-12-19T06:17:52.705112Z","iopub.execute_input":"2022-12-19T06:17:52.705523Z","iopub.status.idle":"2022-12-19T06:17:52.713601Z","shell.execute_reply.started":"2022-12-19T06:17:52.705482Z","shell.execute_reply":"2022-12-19T06:17:52.712687Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# score = model.evaluate(X, y_cat, verbose=1)\n# print('Test loss:', score[0])\n# print('Test accuracy:', score[1])","metadata":{"execution":{"iopub.status.busy":"2022-12-19T06:17:52.715013Z","iopub.execute_input":"2022-12-19T06:17:52.715601Z","iopub.status.idle":"2022-12-19T06:17:52.724864Z","shell.execute_reply.started":"2022-12-19T06:17:52.715560Z","shell.execute_reply":"2022-12-19T06:17:52.724085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions = np.argmax(model.predict(X_test), axis=-1)","metadata":{"execution":{"iopub.status.busy":"2022-12-19T06:17:52.726096Z","iopub.execute_input":"2022-12-19T06:17:52.726694Z","iopub.status.idle":"2022-12-19T06:18:11.024876Z","shell.execute_reply.started":"2022-12-19T06:17:52.726651Z","shell.execute_reply":"2022-12-19T06:18:11.023861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# print(classification_report(y_test,predictions))","metadata":{"execution":{"iopub.status.busy":"2022-12-19T06:18:39.987484Z","iopub.execute_input":"2022-12-19T06:18:39.987937Z","iopub.status.idle":"2022-12-19T06:18:39.994422Z","shell.execute_reply.started":"2022-12-19T06:18:39.987893Z","shell.execute_reply":"2022-12-19T06:18:39.992969Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# print(confusion_matrix(y_cat, predictions))","metadata":{"execution":{"iopub.status.busy":"2022-12-19T06:19:31.515514Z","iopub.execute_input":"2022-12-19T06:19:31.515995Z","iopub.status.idle":"2022-12-19T06:19:31.521271Z","shell.execute_reply.started":"2022-12-19T06:19:31.515951Z","shell.execute_reply":"2022-12-19T06:19:31.519924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# plt.figure(figsize=(15,7))\n# sns.heatmap(confusion_matrix(y_cat, predictions),annot=True)","metadata":{"execution":{"iopub.status.busy":"2022-12-19T06:19:47.091773Z","iopub.execute_input":"2022-12-19T06:19:47.092123Z","iopub.status.idle":"2022-12-19T06:19:47.096763Z","shell.execute_reply.started":"2022-12-19T06:19:47.092091Z","shell.execute_reply":"2022-12-19T06:19:47.095452Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# new_img = X_test[95]\n# plt.imshow(new_img)","metadata":{"execution":{"iopub.status.busy":"2022-12-19T06:18:11.059386Z","iopub.status.idle":"2022-12-19T06:18:11.059876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# y_test[95]","metadata":{"execution":{"iopub.status.busy":"2022-12-19T06:18:11.061229Z","iopub.status.idle":"2022-12-19T06:18:11.061802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# np.argmax(model.predict(new_img.reshape(1,28,28,1)), axis=-1)","metadata":{"execution":{"iopub.status.busy":"2022-12-19T06:18:11.063022Z","iopub.status.idle":"2022-12-19T06:18:11.063519Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-19T06:22:43.119509Z","iopub.execute_input":"2022-12-19T06:22:43.120201Z","iopub.status.idle":"2022-12-19T06:22:43.126692Z","shell.execute_reply.started":"2022-12-19T06:22:43.120160Z","shell.execute_reply":"2022-12-19T06:22:43.125761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-19T06:20:49.075868Z","iopub.execute_input":"2022-12-19T06:20:49.076282Z","iopub.status.idle":"2022-12-19T06:20:49.083593Z","shell.execute_reply.started":"2022-12-19T06:20:49.076245Z","shell.execute_reply":"2022-12-19T06:20:49.082372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample = pd.read_csv('/kaggle/input/digit-recognizer/sample_submission.csv')\nsample","metadata":{"execution":{"iopub.status.busy":"2022-12-19T06:20:34.269201Z","iopub.execute_input":"2022-12-19T06:20:34.269921Z","iopub.status.idle":"2022-12-19T06:20:34.314558Z","shell.execute_reply.started":"2022-12-19T06:20:34.269878Z","shell.execute_reply":"2022-12-19T06:20:34.313181Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Submission line from https://www.kaggle.com/code/poonaml/deep-neural-network-keras-way","metadata":{}},{"cell_type":"code","source":"submission = pd.DataFrame({\"ImageId\": list(range(1,len(predictions)+1)),\"Label\": predictions})\nsubmission","metadata":{"execution":{"iopub.status.busy":"2022-12-19T06:25:00.254349Z","iopub.execute_input":"2022-12-19T06:25:00.254720Z","iopub.status.idle":"2022-12-19T06:25:00.277960Z","shell.execute_reply.started":"2022-12-19T06:25:00.254687Z","shell.execute_reply":"2022-12-19T06:25:00.277038Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv(\"submission.csv\", index=False, header=True)","metadata":{"execution":{"iopub.status.busy":"2022-12-19T06:26:34.681386Z","iopub.execute_input":"2022-12-19T06:26:34.681793Z","iopub.status.idle":"2022-12-19T06:26:34.726145Z","shell.execute_reply.started":"2022-12-19T06:26:34.681757Z","shell.execute_reply":"2022-12-19T06:26:34.724918Z"},"trusted":true},"execution_count":null,"outputs":[]}]}