{"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\nimport pandas as pd\nfrom matplotlib import pyplot as plt\nimport tensorflow as tf\nfrom tensorflow import keras\nimport seaborn as sns\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-22T14:05:25.047130Z","iopub.execute_input":"2022-12-22T14:05:25.047591Z","iopub.status.idle":"2022-12-22T14:05:32.234300Z","shell.execute_reply.started":"2022-12-22T14:05:25.047552Z","shell.execute_reply":"2022-12-22T14:05:32.232744Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')\ntest = pd.read_csv('/kaggle/input/digit-recognizer/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:12:55.806278Z","iopub.execute_input":"2022-12-22T14:12:55.807043Z","iopub.status.idle":"2022-12-22T14:13:02.216768Z","shell.execute_reply.started":"2022-12-22T14:12:55.806996Z","shell.execute_reply":"2022-12-22T14:13:02.215538Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isna().any().describe()","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:13:07.249955Z","iopub.execute_input":"2022-12-22T14:13:07.250425Z","iopub.status.idle":"2022-12-22T14:13:07.283039Z","shell.execute_reply.started":"2022-12-22T14:13:07.250387Z","shell.execute_reply":"2022-12-22T14:13:07.282111Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.isna().any().describe()","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:13:13.407624Z","iopub.execute_input":"2022-12-22T14:13:13.408118Z","iopub.status.idle":"2022-12-22T14:13:13.426759Z","shell.execute_reply.started":"2022-12-22T14:13:13.408079Z","shell.execute_reply":"2022-12-22T14:13:13.425434Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:13:26.175464Z","iopub.execute_input":"2022-12-22T14:13:26.176537Z","iopub.status.idle":"2022-12-22T14:13:26.410915Z","shell.execute_reply.started":"2022-12-22T14:13:26.176497Z","shell.execute_reply":"2022-12-22T14:13:26.409468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = train.iloc[:,1:]\ny = train.iloc[:, 0]\nprint(X.shape, y.shape)","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:13:30.166877Z","iopub.execute_input":"2022-12-22T14:13:30.167315Z","iopub.status.idle":"2022-12-22T14:13:30.174791Z","shell.execute_reply.started":"2022-12-22T14:13:30.167281Z","shell.execute_reply":"2022-12-22T14:13:30.173443Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.barplot(x=y.value_counts().index, y=y.value_counts().values)","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:13:52.323501Z","iopub.execute_input":"2022-12-22T14:13:52.323885Z","iopub.status.idle":"2022-12-22T14:13:52.548951Z","shell.execute_reply.started":"2022-12-22T14:13:52.323854Z","shell.execute_reply":"2022-12-22T14:13:52.548037Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"numimg = np.reshape(X.iloc[25].values, (28,28))\nprint(numimg.shape)\nplt.imshow(numimg, cmap='Greys')","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:14:29.845919Z","iopub.execute_input":"2022-12-22T14:14:29.846394Z","iopub.status.idle":"2022-12-22T14:14:30.075495Z","shell.execute_reply.started":"2022-12-22T14:14:29.846357Z","shell.execute_reply":"2022-12-22T14:14:30.074215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:15:47.963997Z","iopub.execute_input":"2022-12-22T14:15:47.964437Z","iopub.status.idle":"2022-12-22T14:15:48.098304Z","shell.execute_reply.started":"2022-12-22T14:15:47.964399Z","shell.execute_reply":"2022-12-22T14:15:48.096998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2, random_state=0)\nprint(X_train.shape, X_val.shape, y_train.shape, y_val.shape)","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:16:03.364513Z","iopub.execute_input":"2022-12-22T14:16:03.364949Z","iopub.status.idle":"2022-12-22T14:16:03.707803Z","shell.execute_reply.started":"2022-12-22T14:16:03.364896Z","shell.execute_reply":"2022-12-22T14:16:03.706480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.pipeline import Pipeline\nfrom sklearn.compose import ColumnTransformer\nfrom sklearn.preprocessing import StandardScaler, MinMaxScaler","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:16:12.324948Z","iopub.execute_input":"2022-12-22T14:16:12.325420Z","iopub.status.idle":"2022-12-22T14:16:12.331807Z","shell.execute_reply.started":"2022-12-22T14:16:12.325381Z","shell.execute_reply":"2022-12-22T14:16:12.330349Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.base import BaseEstimator, TransformerMixin","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:16:17.283671Z","iopub.execute_input":"2022-12-22T14:16:17.284114Z","iopub.status.idle":"2022-12-22T14:16:17.289656Z","shell.execute_reply.started":"2022-12-22T14:16:17.284078Z","shell.execute_reply":"2022-12-22T14:16:17.288366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class ReshapeFunc(BaseEstimator, TransformerMixin):\n    def __init__(self):\n        pass\n    def fit(self, X, y=None):\n        return self\n    def transform(self, X, y=None):\n        X = X.reshape((-1,28,28,1))\n        return X","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:16:22.643543Z","iopub.execute_input":"2022-12-22T14:16:22.643992Z","iopub.status.idle":"2022-12-22T14:16:22.650910Z","shell.execute_reply.started":"2022-12-22T14:16:22.643957Z","shell.execute_reply":"2022-12-22T14:16:22.649419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"features_pipeline = Pipeline(steps=[\n    ('Normalize', MinMaxScaler()),\n    ('Reshape', ReshapeFunc())\n])","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:16:29.081449Z","iopub.execute_input":"2022-12-22T14:16:29.081872Z","iopub.status.idle":"2022-12-22T14:16:29.088159Z","shell.execute_reply.started":"2022-12-22T14:16:29.081837Z","shell.execute_reply":"2022-12-22T14:16:29.086750Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = features_pipeline.fit_transform(X_train)","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:16:34.125506Z","iopub.execute_input":"2022-12-22T14:16:34.126117Z","iopub.status.idle":"2022-12-22T14:16:34.449279Z","shell.execute_reply.started":"2022-12-22T14:16:34.126063Z","shell.execute_reply":"2022-12-22T14:16:34.447792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import OneHotEncoder\ntarget_pipeline = Pipeline(steps=[\n    ('OneHot', OneHotEncoder())\n])","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:18:11.087225Z","iopub.execute_input":"2022-12-22T14:18:11.087671Z","iopub.status.idle":"2022-12-22T14:18:11.094490Z","shell.execute_reply.started":"2022-12-22T14:18:11.087636Z","shell.execute_reply":"2022-12-22T14:18:11.093050Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train = target_pipeline.fit_transform(y_train.values.reshape(-1,1))","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:18:16.964435Z","iopub.execute_input":"2022-12-22T14:18:16.964846Z","iopub.status.idle":"2022-12-22T14:18:16.976630Z","shell.execute_reply.started":"2022-12-22T14:18:16.964811Z","shell.execute_reply":"2022-12-22T14:18:16.975031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train = y_train.toarray()","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:18:19.844981Z","iopub.execute_input":"2022-12-22T14:18:19.845464Z","iopub.status.idle":"2022-12-22T14:18:19.852107Z","shell.execute_reply.started":"2022-12-22T14:18:19.845424Z","shell.execute_reply":"2022-12-22T14:18:19.850898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(X_train.shape, y_train.shape)","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:18:22.556101Z","iopub.execute_input":"2022-12-22T14:18:22.557109Z","iopub.status.idle":"2022-12-22T14:18:22.562860Z","shell.execute_reply.started":"2022-12-22T14:18:22.557053Z","shell.execute_reply":"2022-12-22T14:18:22.561475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_val = features_pipeline.fit_transform(X_val)","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:18:33.933070Z","iopub.execute_input":"2022-12-22T14:18:33.933492Z","iopub.status.idle":"2022-12-22T14:18:34.033098Z","shell.execute_reply.started":"2022-12-22T14:18:33.933457Z","shell.execute_reply":"2022-12-22T14:18:34.032112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_val = target_pipeline.fit_transform(y_val.values.reshape(-1, 1))","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:18:38.035140Z","iopub.execute_input":"2022-12-22T14:18:38.035528Z","iopub.status.idle":"2022-12-22T14:18:38.044058Z","shell.execute_reply.started":"2022-12-22T14:18:38.035496Z","shell.execute_reply":"2022-12-22T14:18:38.042643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_val = y_val.toarray()","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:18:40.363522Z","iopub.execute_input":"2022-12-22T14:18:40.364085Z","iopub.status.idle":"2022-12-22T14:18:40.370916Z","shell.execute_reply.started":"2022-12-22T14:18:40.364034Z","shell.execute_reply":"2022-12-22T14:18:40.369630Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(X_val.shape, y_val.shape)","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:18:45.163817Z","iopub.execute_input":"2022-12-22T14:18:45.164278Z","iopub.status.idle":"2022-12-22T14:18:45.170888Z","shell.execute_reply.started":"2022-12-22T14:18:45.164240Z","shell.execute_reply":"2022-12-22T14:18:45.169579Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test = features_pipeline.fit_transform(test)","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:19:05.925230Z","iopub.execute_input":"2022-12-22T14:19:05.925671Z","iopub.status.idle":"2022-12-22T14:19:06.195403Z","shell.execute_reply.started":"2022-12-22T14:19:05.925635Z","shell.execute_reply":"2022-12-22T14:19:06.193940Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras import backend as K","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:19:10.163856Z","iopub.execute_input":"2022-12-22T14:19:10.164322Z","iopub.status.idle":"2022-12-22T14:19:10.951212Z","shell.execute_reply.started":"2022-12-22T14:19:10.164283Z","shell.execute_reply":"2022-12-22T14:19:10.949577Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Precision (using keras backend)\ndef precision_metric(y_true, y_pred):\n    threshold = 0.5  # Training threshold 0.5\n    y_pred_y = K.cast(K.greater(K.clip(y_pred, 0, 1), threshold), K.floatx())\n\n    true_positives = K.sum(K.clip(y_true * y_pred, 0, 1))\n    false_negatives = K.sum(K.clip(y_true * (1-y_pred), 0, 1))\n    false_positives = K.sum(K.clip((1-y_true) * y_pred, 0, 1))\n    true_negatives = K.sum(K.clip((1 - y_true) * (1-y_pred), 0, 1))\n\n    precision = true_positives / (true_positives + false_positives + K.epsilon())\n    return precision\n\n# Recall (using keras backend)\ndef recall_metric(y_true, y_pred):\n    threshold = 0.5 #Training threshold 0.5\n    y_pred = K.cast(K.greater(K.clip(y_pred, 0, 1), threshold), K.floatx())\n\n    true_positives = K.sum(K.clip(y_true * y_pred, 0, 1))\n    false_negatives = K.sum(K.clip(y_true * (1-y_pred), 0, 1))\n    false_positives = K.sum(K.clip((1-y_true) * y_pred, 0, 1))\n    true_negatives = K.sum(K.clip((1 - y_true) * (1-y_pred), 0, 1))\n\n    recall = true_positives / (true_positives + false_negatives + K.epsilon())\n    return recall\n\n# F1-score (using keras backend)\ndef f1_metric(y_true, y_pred):\n    precision = precision_metric(y_true, y_pred)\n    recall = recall_metric(y_true, y_pred)\n    f1 = 2 * ((precision * recall) / (recall+precision+K.epsilon()))\n    return f1","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:19:26.046852Z","iopub.execute_input":"2022-12-22T14:19:26.047689Z","iopub.status.idle":"2022-12-22T14:19:26.060309Z","shell.execute_reply.started":"2022-12-22T14:19:26.047645Z","shell.execute_reply":"2022-12-22T14:19:26.059026Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def build_model():\n    inp = keras.Input(shape=(28,28,1))\n    x = keras.layers.Conv2D(filters=32, kernel_size=(3,3), strides=(1,1),padding='SAME', \n                              activation='relu')(inp)\n    x = keras.layers.MaxPool2D(pool_size=(2,2))(x)\n    x = keras.layers.BatchNormalization()(x)\n    x = keras.layers.Dropout(0.25)(x)\n    x = keras.layers.Conv2D(filters=64, kernel_size=(3,3), padding='SAME', activation='relu')(x)\n    x = keras.layers.MaxPool2D(pool_size=(2,2))(x)\n    x = keras.layers.BatchNormalization()(x)\n    x = keras.layers.Dropout(0.25)(x)\n    x = keras.layers.Flatten()(x)\n    x = keras.layers.Dense(256, activation='relu')(x)\n    x = keras.layers.Dropout(0.5)(x)\n    output = keras.layers.Dense(10, activation='softmax')(x)\n\n    model = keras.Model(inputs=inp, outputs=output)\n\n    model.compile(loss=keras.losses.CategoricalCrossentropy(), optimizer=keras.optimizers.Adam(learning_rate=0.001), metrics=['accuracy', f1_metric, recall_metric, precision_metric])\n    return model, inp, output","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:19:31.005173Z","iopub.execute_input":"2022-12-22T14:19:31.005582Z","iopub.status.idle":"2022-12-22T14:19:31.015905Z","shell.execute_reply.started":"2022-12-22T14:19:31.005548Z","shell.execute_reply":"2022-12-22T14:19:31.015018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model, inp, out = build_model()\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:19:37.965772Z","iopub.execute_input":"2022-12-22T14:19:37.966190Z","iopub.status.idle":"2022-12-22T14:19:38.593365Z","shell.execute_reply.started":"2022-12-22T14:19:37.966155Z","shell.execute_reply":"2022-12-22T14:19:38.592407Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.utils.vis_utils import plot_model\nplot_model(model)","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:20:14.098325Z","iopub.execute_input":"2022-12-22T14:20:14.098719Z","iopub.status.idle":"2022-12-22T14:20:15.467735Z","shell.execute_reply.started":"2022-12-22T14:20:14.098687Z","shell.execute_reply":"2022-12-22T14:20:15.466065Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"batch_size=16","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:21:14.569923Z","iopub.execute_input":"2022-12-22T14:21:14.571347Z","iopub.status.idle":"2022-12-22T14:21:14.576918Z","shell.execute_reply.started":"2022-12-22T14:21:14.571300Z","shell.execute_reply":"2022-12-22T14:21:14.575496Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit(X_train, y_train, validation_data=(X_val, y_val), epochs=30, batch_size=batch_size,\n                    callbacks=[keras.callbacks.EarlyStopping(monitor='val_loss',mode='min',patience=10, \n                                                             min_delta=0.005, restore_best_weights=True),\n                              keras.callbacks.ReduceLROnPlateau(monitor = 'val_loss', patience = 3)], shuffle =  True, verbose = 1)","metadata":{"execution":{"iopub.status.busy":"2022-12-22T14:35:33.688490Z","iopub.execute_input":"2022-12-22T14:35:33.688909Z","iopub.status.idle":"2022-12-22T14:42:18.139994Z","shell.execute_reply.started":"2022-12-22T14:35:33.688873Z","shell.execute_reply":"2022-12-22T14:42:18.138623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(history.history['loss'])\nplt.plot(history.history['val_loss'])\nplt.title('Model loss')\nplt.xlabel('Epochs')\nplt.ylabel('Loss')\nplt.legend(['Loss','Val loss'])","metadata":{"execution":{"iopub.status.busy":"2022-12-22T15:04:45.959509Z","iopub.execute_input":"2022-12-22T15:04:45.959907Z","iopub.status.idle":"2022-12-22T15:04:46.233525Z","shell.execute_reply.started":"2022-12-22T15:04:45.959876Z","shell.execute_reply":"2022-12-22T15:04:46.232455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(history.history['f1_metric'])\nplt.plot(history.history['val_f1_metric'])\nplt.title('Model F1')\nplt.xlabel('Epochs')\nplt.ylabel('F1')\nplt.legend(['Training f1','Validation f1'])","metadata":{"execution":{"iopub.status.busy":"2022-12-22T15:05:05.128538Z","iopub.execute_input":"2022-12-22T15:05:05.128965Z","iopub.status.idle":"2022-12-22T15:05:05.639676Z","shell.execute_reply.started":"2022-12-22T15:05:05.128914Z","shell.execute_reply":"2022-12-22T15:05:05.637197Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(history.history['accuracy'])\nplt.plot(history.history['val_accuracy'])\nplt.title('Model accuracy')\nplt.xlabel('Epochs')\nplt.ylabel('Accuracy')\nplt.legend(['Accuracy','Val accuracy'])","metadata":{"execution":{"iopub.status.busy":"2022-12-22T15:05:16.283539Z","iopub.execute_input":"2022-12-22T15:05:16.284238Z","iopub.status.idle":"2022-12-22T15:05:16.542922Z","shell.execute_reply.started":"2022-12-22T15:05:16.284200Z","shell.execute_reply":"2022-12-22T15:05:16.541714Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import confusion_matrix","metadata":{"execution":{"iopub.status.busy":"2022-12-22T15:05:35.093870Z","iopub.execute_input":"2022-12-22T15:05:35.094286Z","iopub.status.idle":"2022-12-22T15:05:35.100236Z","shell.execute_reply.started":"2022-12-22T15:05:35.094252Z","shell.execute_reply":"2022-12-22T15:05:35.098756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_val_pred = np.argmax(model.predict(X_val), axis=1)\ny_val_pred","metadata":{"execution":{"iopub.status.busy":"2022-12-22T15:05:42.808163Z","iopub.execute_input":"2022-12-22T15:05:42.808633Z","iopub.status.idle":"2022-12-22T15:05:46.102087Z","shell.execute_reply.started":"2022-12-22T15:05:42.808595Z","shell.execute_reply":"2022-12-22T15:05:46.100893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cm = confusion_matrix(np.argmax(y_val,axis=1), y_val_pred)\nsns.heatmap(cm, annot=True, cmap='Blues', fmt='g')\nplt.title('Confusion matrix')\nplt.xlabel('Pred')\nplt.ylabel('True')","metadata":{"execution":{"iopub.status.busy":"2022-12-22T15:06:10.176734Z","iopub.execute_input":"2022-12-22T15:06:10.177181Z","iopub.status.idle":"2022-12-22T15:06:10.894005Z","shell.execute_reply.started":"2022-12-22T15:06:10.177143Z","shell.execute_reply":"2022-12-22T15:06:10.893002Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_val_true = np.argmax(y_val,axis=1)\ny_val_true","metadata":{"execution":{"iopub.status.busy":"2022-12-22T15:06:49.367733Z","iopub.execute_input":"2022-12-22T15:06:49.368167Z","iopub.status.idle":"2022-12-22T15:06:49.376114Z","shell.execute_reply.started":"2022-12-22T15:06:49.368129Z","shell.execute_reply":"2022-12-22T15:06:49.375040Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score\naccuracy_score(y_val_true, y_val_pred)","metadata":{"execution":{"iopub.status.busy":"2022-12-22T15:06:59.847416Z","iopub.execute_input":"2022-12-22T15:06:59.847854Z","iopub.status.idle":"2022-12-22T15:06:59.856284Z","shell.execute_reply.started":"2022-12-22T15:06:59.847816Z","shell.execute_reply":"2022-12-22T15:06:59.854987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test_pred = model.predict(X_test)\ny_test_pred = np.argmax(y_test_pred,axis=1)\ntest_results = pd.DataFrame({'ImageID': np.arange(1,28001,1), 'Label': y_test_pred})","metadata":{"execution":{"iopub.status.busy":"2022-12-22T15:07:29.680493Z","iopub.execute_input":"2022-12-22T15:07:29.680998Z","iopub.status.idle":"2022-12-22T15:07:37.820777Z","shell.execute_reply.started":"2022-12-22T15:07:29.680957Z","shell.execute_reply":"2022-12-22T15:07:37.819315Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_results.to_csv(\"/kaggle/working/submission.csv\",index=False)","metadata":{},"execution_count":null,"outputs":[]}]}