{"metadata":{"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":3004,"databundleVersionId":861823,"sourceType":"competition"}],"dockerImageVersionId":30587,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport tensorflow\n","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:11.493254Z","iopub.execute_input":"2023-11-26T17:29:11.493721Z","iopub.status.idle":"2023-11-26T17:29:11.500460Z","shell.execute_reply.started":"2023-11-26T17:29:11.493688Z","shell.execute_reply":"2023-11-26T17:29:11.499108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_raw = pd.read_csv(\"/kaggle/input/digit-recognizer/train.csv\")\ntest_raw = pd.read_csv(\"/kaggle/input/digit-recognizer/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:11.502346Z","iopub.execute_input":"2023-11-26T17:29:11.502705Z","iopub.status.idle":"2023-11-26T17:29:17.276494Z","shell.execute_reply.started":"2023-11-26T17:29:11.502675Z","shell.execute_reply":"2023-11-26T17:29:17.275149Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_raw.head()","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:17.279194Z","iopub.execute_input":"2023-11-26T17:29:17.279723Z","iopub.status.idle":"2023-11-26T17:29:17.305059Z","shell.execute_reply.started":"2023-11-26T17:29:17.279677Z","shell.execute_reply":"2023-11-26T17:29:17.303770Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_raw.head()","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:17.306403Z","iopub.execute_input":"2023-11-26T17:29:17.307324Z","iopub.status.idle":"2023-11-26T17:29:17.328779Z","shell.execute_reply.started":"2023-11-26T17:29:17.307287Z","shell.execute_reply":"2023-11-26T17:29:17.327766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_raw.describe()","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:17.331215Z","iopub.execute_input":"2023-11-26T17:29:17.332338Z","iopub.status.idle":"2023-11-26T17:29:20.009597Z","shell.execute_reply.started":"2023-11-26T17:29:17.332295Z","shell.execute_reply":"2023-11-26T17:29:20.008321Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_raw.shape","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:20.011509Z","iopub.execute_input":"2023-11-26T17:29:20.012095Z","iopub.status.idle":"2023-11-26T17:29:20.022392Z","shell.execute_reply.started":"2023-11-26T17:29:20.012035Z","shell.execute_reply":"2023-11-26T17:29:20.020563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"To visualize the image i have to unfold the array","metadata":{}},{"cell_type":"code","source":"X_train = (train_raw.iloc[:,1:].values).astype('float32') # all pixel values\ny_train = train_raw.iloc[:,0].values.astype('int32') # only labels i.e targets digits\nX_test = test_raw.values.astype('float32')","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:20.024156Z","iopub.execute_input":"2023-11-26T17:29:20.024538Z","iopub.status.idle":"2023-11-26T17:29:20.146715Z","shell.execute_reply.started":"2023-11-26T17:29:20.024496Z","shell.execute_reply":"2023-11-26T17:29:20.145343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = X_train.reshape(X_train.shape[0],28,28)\n\nfig, axes = plt.subplots(1,3)\n\nfor i,index in enumerate(range(6,9)):\n    \n    axes[i].imshow(X_train[index])\n    axes[i].set_title(y_train[index])\n","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:20.148624Z","iopub.execute_input":"2023-11-26T17:29:20.149638Z","iopub.status.idle":"2023-11-26T17:29:20.775677Z","shell.execute_reply.started":"2023-11-26T17:29:20.149597Z","shell.execute_reply":"2023-11-26T17:29:20.774374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test = X_test.reshape(X_test.shape[0],28,28)\n\n","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:20.777470Z","iopub.execute_input":"2023-11-26T17:29:20.777844Z","iopub.status.idle":"2023-11-26T17:29:20.783275Z","shell.execute_reply.started":"2023-11-26T17:29:20.777811Z","shell.execute_reply":"2023-11-26T17:29:20.781934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mean_px = X_train.mean().astype(np.float32)\nstd_px = X_train.std().astype(np.float32)\n\ndef standardize(x): \n    return (x-mean_px)/std_px","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:20.785170Z","iopub.execute_input":"2023-11-26T17:29:20.785569Z","iopub.status.idle":"2023-11-26T17:29:20.894596Z","shell.execute_reply.started":"2023-11-26T17:29:20.785520Z","shell.execute_reply":"2023-11-26T17:29:20.893363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Preprocessing","metadata":{}},{"cell_type":"code","source":"from tensorflow.keras.utils import to_categorical\ny_train = to_categorical(y_train)\n","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:20.899711Z","iopub.execute_input":"2023-11-26T17:29:20.900152Z","iopub.status.idle":"2023-11-26T17:29:20.907263Z","shell.execute_reply.started":"2023-11-26T17:29:20.900114Z","shell.execute_reply":"2023-11-26T17:29:20.905949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.Figure()\nplt.plot(y_train[9])\nplt.title(y_train[9])","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:20.908795Z","iopub.execute_input":"2023-11-26T17:29:20.909259Z","iopub.status.idle":"2023-11-26T17:29:21.235639Z","shell.execute_reply.started":"2023-11-26T17:29:20.909229Z","shell.execute_reply":"2023-11-26T17:29:21.234418Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Neural network setup","metadata":{}},{"cell_type":"code","source":"seed = 43\nnp.random.seed(seed)","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:21.237000Z","iopub.execute_input":"2023-11-26T17:29:21.237347Z","iopub.status.idle":"2023-11-26T17:29:21.243304Z","shell.execute_reply.started":"2023-11-26T17:29:21.237319Z","shell.execute_reply":"2023-11-26T17:29:21.242156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.models import  Sequential\nfrom keras.layers import  Lambda , Dense, Flatten, Dropout\n\n\nNN  = Sequential()\nNN.add(Lambda(standardize,input_shape=(28,28,1)))\nNN.add(Flatten())\nNN.add(Dense(10, activation='softmax'))\n\nprint(\"input shape \",NN.input_shape)\nprint(\"output shape \",NN.output_shape)","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:21.244769Z","iopub.execute_input":"2023-11-26T17:29:21.245256Z","iopub.status.idle":"2023-11-26T17:29:21.285650Z","shell.execute_reply.started":"2023-11-26T17:29:21.245226Z","shell.execute_reply":"2023-11-26T17:29:21.284546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"NN.summary()","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:21.287157Z","iopub.execute_input":"2023-11-26T17:29:21.287484Z","iopub.status.idle":"2023-11-26T17:29:21.307869Z","shell.execute_reply.started":"2023-11-26T17:29:21.287456Z","shell.execute_reply":"2023-11-26T17:29:21.306677Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.optimizers import RMSprop\n\nNN.compile(optimizer=RMSprop(lr=0.001),\n loss='categorical_crossentropy',\n metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:21.309304Z","iopub.execute_input":"2023-11-26T17:29:21.309694Z","iopub.status.idle":"2023-11-26T17:29:21.329172Z","shell.execute_reply.started":"2023-11-26T17:29:21.309655Z","shell.execute_reply":"2023-11-26T17:29:21.327737Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nX = X_train\ny = y_train\nX_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size=0.10, random_state=42)\n\n\n","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:21.330749Z","iopub.execute_input":"2023-11-26T17:29:21.331487Z","iopub.status.idle":"2023-11-26T17:29:21.705176Z","shell.execute_reply.started":"2023-11-26T17:29:21.331447Z","shell.execute_reply":"2023-11-26T17:29:21.704033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history1=NN.fit(x=X_train,y=y_train, epochs=3,batch_size=64,validation_data=(X_val,y_val))\n","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:21.707013Z","iopub.execute_input":"2023-11-26T17:29:21.707408Z","iopub.status.idle":"2023-11-26T17:29:26.859093Z","shell.execute_reply.started":"2023-11-26T17:29:21.707373Z","shell.execute_reply":"2023-11-26T17:29:26.857668Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history_dict1 = history1.history\nhistory_dict1.keys()","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:26.862448Z","iopub.execute_input":"2023-11-26T17:29:26.865246Z","iopub.status.idle":"2023-11-26T17:29:26.878229Z","shell.execute_reply.started":"2023-11-26T17:29:26.865188Z","shell.execute_reply":"2023-11-26T17:29:26.876272Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.Figure()\nepochs = range(1,len(history_dict1[\"loss\"])+1)\nplt.plot(epochs,history_dict1[\"loss\"],\"bo\")\nplt.plot(epochs,history_dict1[\"val_loss\"],\"b+\")\nplt.xlabel(\"epochs\")\nplt.ylabel(\"loss\")","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:26.883253Z","iopub.execute_input":"2023-11-26T17:29:26.883801Z","iopub.status.idle":"2023-11-26T17:29:27.224730Z","shell.execute_reply.started":"2023-11-26T17:29:26.883753Z","shell.execute_reply":"2023-11-26T17:29:27.223616Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.Figure()\nepochs = range(1,len(history_dict1[\"accuracy\"])+1)\nplt.plot(epochs,history_dict1[\"accuracy\"],\"bo\")\nplt.plot(epochs,history_dict1[\"val_accuracy\"],\"b+\")\nplt.xlabel(\"epochs\")\nplt.ylabel(\"accuracy\")","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:27.226017Z","iopub.execute_input":"2023-11-26T17:29:27.226664Z","iopub.status.idle":"2023-11-26T17:29:27.549870Z","shell.execute_reply.started":"2023-11-26T17:29:27.226630Z","shell.execute_reply":"2023-11-26T17:29:27.548556Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def NN_dense_model():\n    model = Sequential()\n    model.add(Lambda(standardize,input_shape=(28,28,1)))\n    model.add(Flatten())\n    model.add(Dense(512, activation='relu'))\n    model.add(Dense(10,activation=\"softmax\"))\n    \n    model.compile(optimizer=\"adam\",metrics=[\"accuracy\"],loss=\"categorical_crossentropy\")\n    \n    return model\n","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:27.551600Z","iopub.execute_input":"2023-11-26T17:29:27.552565Z","iopub.status.idle":"2023-11-26T17:29:27.561835Z","shell.execute_reply.started":"2023-11-26T17:29:27.552518Z","shell.execute_reply":"2023-11-26T17:29:27.560625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dense_model = NN_dense_model()\ndense_model.optimizer.lr=0.01\n","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:27.563274Z","iopub.execute_input":"2023-11-26T17:29:27.563654Z","iopub.status.idle":"2023-11-26T17:29:27.628402Z","shell.execute_reply.started":"2023-11-26T17:29:27.563595Z","shell.execute_reply":"2023-11-26T17:29:27.627338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"hystory2 = dense_model.fit(x=X_train,y=y_train,batch_size=64,validation_data=(X_val,y_val),epochs=3)","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:27.630135Z","iopub.execute_input":"2023-11-26T17:29:27.630540Z","iopub.status.idle":"2023-11-26T17:29:48.970426Z","shell.execute_reply.started":"2023-11-26T17:29:27.630508Z","shell.execute_reply":"2023-11-26T17:29:48.969260Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history_dict2 = hystory2.history\nhistory_dict2.keys()","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:48.972515Z","iopub.execute_input":"2023-11-26T17:29:48.973407Z","iopub.status.idle":"2023-11-26T17:29:48.981380Z","shell.execute_reply.started":"2023-11-26T17:29:48.973365Z","shell.execute_reply":"2023-11-26T17:29:48.980155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.Figure()\nepochs = range(1,len(history_dict2[\"loss\"])+1)\nplt.plot(epochs,history_dict2[\"loss\"],\"bo\")\nplt.plot(epochs,history_dict2[\"val_loss\"],\"b+\")\nplt.xlabel(\"epochs\")\nplt.ylabel(\"loss\")","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:48.983323Z","iopub.execute_input":"2023-11-26T17:29:48.983755Z","iopub.status.idle":"2023-11-26T17:29:49.316535Z","shell.execute_reply.started":"2023-11-26T17:29:48.983720Z","shell.execute_reply":"2023-11-26T17:29:49.315263Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.Figure()\nepochs = range(1,len(history_dict2[\"accuracy\"])+1)\nplt.plot(epochs,history_dict2[\"accuracy\"],\"bo\")\nplt.plot(epochs,history_dict2[\"val_accuracy\"],\"b+\")\nplt.xlabel(\"epochs\")\nplt.ylabel(\"accuracy\")","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:49.318205Z","iopub.execute_input":"2023-11-26T17:29:49.318547Z","iopub.status.idle":"2023-11-26T17:29:49.663189Z","shell.execute_reply.started":"2023-11-26T17:29:49.318519Z","shell.execute_reply":"2023-11-26T17:29:49.661913Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.layers import Convolution2D,MaxPooling2D\nfrom keras.optimizers import Adam\n\ndef conv_model():\n    conv_model = Sequential([\n                Lambda(standardize,input_shape=(28,28,1)),\n                Convolution2D(32,(3,3),activation=\"relu\"),\n                Convolution2D(32,(3,3),activation=\"relu\"),\n                MaxPooling2D(),\n                Convolution2D(64,(3,3),activation=\"relu\"),\n                Convolution2D(64,(3,3),activation=\"relu\"),\n                MaxPooling2D(),\n                Flatten(),\n                Dense(512,activation=\"relu\"),\n                Dense(10,activation=\"softmax\")              \n                ])\n    \n    \n    \n    conv_model.compile(optimizer=\"adam\",metrics=[\"accuracy\"],loss=\"categorical_crossentropy\")\n    \n    return conv_model\n    \n    ","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:49.664274Z","iopub.execute_input":"2023-11-26T17:29:49.664619Z","iopub.status.idle":"2023-11-26T17:29:49.673672Z","shell.execute_reply.started":"2023-11-26T17:29:49.664590Z","shell.execute_reply":"2023-11-26T17:29:49.672648Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"conv = conv_model()\nconv.optimizer.lr = 0.01\nconv.summary()","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:49.681406Z","iopub.execute_input":"2023-11-26T17:29:49.681800Z","iopub.status.idle":"2023-11-26T17:29:49.844624Z","shell.execute_reply.started":"2023-11-26T17:29:49.681769Z","shell.execute_reply":"2023-11-26T17:29:49.843411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"hystory3 = conv.fit(x=X_train,y=y_train,batch_size=64,epochs=3,validation_data=(X_val,y_val))\n","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:29:49.845934Z","iopub.execute_input":"2023-11-26T17:29:49.846263Z","iopub.status.idle":"2023-11-26T17:32:13.350035Z","shell.execute_reply.started":"2023-11-26T17:29:49.846236Z","shell.execute_reply":"2023-11-26T17:32:13.349091Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history_dict3 = hystory3.history\nhistory_dict3.keys()","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:32:13.351505Z","iopub.execute_input":"2023-11-26T17:32:13.351999Z","iopub.status.idle":"2023-11-26T17:32:13.360440Z","shell.execute_reply.started":"2023-11-26T17:32:13.351945Z","shell.execute_reply":"2023-11-26T17:32:13.359134Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.Figure()\nepochs = range(1,len(history_dict3[\"loss\"])+1)\nplt.plot(epochs,history_dict3[\"loss\"],\"bo\")\nplt.plot(epochs,history_dict3[\"val_loss\"],\"b+\")\nplt.xlabel(\"epochs\")\nplt.ylabel(\"loss\")","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:32:13.362062Z","iopub.execute_input":"2023-11-26T17:32:13.362524Z","iopub.status.idle":"2023-11-26T17:32:13.703053Z","shell.execute_reply.started":"2023-11-26T17:32:13.362480Z","shell.execute_reply":"2023-11-26T17:32:13.701719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.Figure()\nepochs = range(1,len(history_dict3[\"accuracy\"])+1)\nplt.plot(epochs,history_dict3[\"accuracy\"],\"bo\")\nplt.plot(epochs,history_dict3[\"val_accuracy\"],\"b+\")\nplt.xlabel(\"epochs\")\nplt.ylabel(\"accuracy\")","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:32:13.704453Z","iopub.execute_input":"2023-11-26T17:32:13.704812Z","iopub.status.idle":"2023-11-26T17:32:14.026578Z","shell.execute_reply.started":"2023-11-26T17:32:13.704782Z","shell.execute_reply":"2023-11-26T17:32:14.025279Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.layers import BatchNormalization\n\ndef get_bn_model():\n    model = Sequential([\n        Lambda(standardize, input_shape=(28,28,1)),\n        Convolution2D(32,(3,3), activation='relu'),\n        BatchNormalization(axis=3),\n        Convolution2D(32,(3,3), activation='relu'),\n        MaxPooling2D(),\n        BatchNormalization(axis=3),\n        Convolution2D(64,(3,3), activation='relu'),\n        BatchNormalization(axis=3),\n        Convolution2D(64,(3,3), activation='relu'),\n        MaxPooling2D(),\n        Flatten(),\n        BatchNormalization(),\n        Dense(512, activation='relu'),\n        BatchNormalization(),\n        Dense(10, activation='softmax')\n        ])\n    model.compile(Adam(), loss='categorical_crossentropy', metrics=['accuracy'])\n    return model","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:32:14.028192Z","iopub.execute_input":"2023-11-26T17:32:14.028596Z","iopub.status.idle":"2023-11-26T17:32:14.038241Z","shell.execute_reply.started":"2023-11-26T17:32:14.028566Z","shell.execute_reply":"2023-11-26T17:32:14.036802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_bn= get_bn_model()\nmodel_bn.optimizer.lr=0.01\nhistory4 = model_bn.fit(x=X_train,y=y_train,batch_size=64,epochs=3,validation_data=(X_val,y_val))","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:32:14.039750Z","iopub.execute_input":"2023-11-26T17:32:14.040203Z","iopub.status.idle":"2023-11-26T17:35:38.960728Z","shell.execute_reply.started":"2023-11-26T17:32:14.040168Z","shell.execute_reply":"2023-11-26T17:35:38.959588Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history_dict4 = history4.history\nhistory_dict4.keys()","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:35:38.962118Z","iopub.execute_input":"2023-11-26T17:35:38.962487Z","iopub.status.idle":"2023-11-26T17:35:38.970123Z","shell.execute_reply.started":"2023-11-26T17:35:38.962457Z","shell.execute_reply":"2023-11-26T17:35:38.968844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.Figure()\nepochs = range(1,len(history_dict4[\"loss\"])+1)\nplt.plot(epochs,history_dict4[\"loss\"],\"bo\")\nplt.plot(epochs,history_dict4[\"val_loss\"],\"b+\")\nplt.xlabel(\"epochs\")\nplt.ylabel(\"loss\")","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:35:38.971740Z","iopub.execute_input":"2023-11-26T17:35:38.972240Z","iopub.status.idle":"2023-11-26T17:35:39.296085Z","shell.execute_reply.started":"2023-11-26T17:35:38.972198Z","shell.execute_reply":"2023-11-26T17:35:39.294942Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.Figure()\nepochs = range(1,len(history_dict4[\"accuracy\"])+1)\nplt.plot(epochs,history_dict4[\"accuracy\"],\"bo\")\nplt.plot(epochs,history_dict4[\"val_accuracy\"],\"b+\")\nplt.xlabel(\"epochs\")\nplt.ylabel(\"accuracy\")","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:35:39.297834Z","iopub.execute_input":"2023-11-26T17:35:39.298254Z","iopub.status.idle":"2023-11-26T17:35:39.607969Z","shell.execute_reply.started":"2023-11-26T17:35:39.298221Z","shell.execute_reply":"2023-11-26T17:35:39.606670Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.Figure()\n\nplt.plot(epochs,history_dict1[\"val_accuracy\"],\"b\",label=\"base model\")\nplt.plot(epochs,history_dict2[\"val_accuracy\"],\"r\",label=\"dense model\")\nplt.plot(epochs,history_dict3[\"val_accuracy\"],\"g\",label=\"conv model\")\nplt.plot(epochs,history_dict4[\"val_accuracy\"],\"k\",label=\"bn model\")\nplt.grid(True)\n\nplt.legend()","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:35:39.609607Z","iopub.execute_input":"2023-11-26T17:35:39.610178Z","iopub.status.idle":"2023-11-26T17:35:40.010243Z","shell.execute_reply.started":"2023-11-26T17:35:39.610132Z","shell.execute_reply":"2023-11-26T17:35:40.008976Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = model_bn.predict(X_test,verbose=0)\npredictions = np.argmax(pred,axis=1)\nsubmissions=pd.DataFrame({\"ImageId\": list(range(1,len(predictions)+1)),\n                         \"Label\": predictions})\nsubmissions.to_csv(\"DR.csv\", index=False, header=True)","metadata":{"execution":{"iopub.status.busy":"2023-11-26T17:36:01.078652Z","iopub.execute_input":"2023-11-26T17:36:01.079098Z","iopub.status.idle":"2023-11-26T17:36:21.974314Z","shell.execute_reply.started":"2023-11-26T17:36:01.079065Z","shell.execute_reply":"2023-11-26T17:36:21.973150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}