text_plain_output_1.png
from tensorflow.keras.layers import Dense, Flatten, BatchNormalization, Dropout, Conv2D, MaxPooling2D, Input, AveragePooling2D

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import tensorflow as tf

data = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')
data_sub = pd.read_csv('/kaggle/input/digit-recognizer/test.csv')

X = data.iloc[:, 1:]
y = data.iloc[:, 0]
X = np.array(X).reshape(-1, 28, 28, 1)

model = tf.keras.models.Sequential([Input(shape=X_train.shape[1:]), Conv2D(32, 5, activation='relu', padding='same'), Conv2D(32, 5, activation='relu', padding='same'), MaxPooling2D(pool_size=(2, 2)), BatchNormalization(), Dropout(0.3), Conv2D(64, 5, activation='relu', padding='same'), Conv2D(64, 5, activation='relu', padding='same'), MaxPooling2D(pool_size=(2, 2)), BatchNormalization(), Dropout(0.3), Flatten(), Dense(256, activation='selu', kernel_initializer='lecun_normal'), BatchNormalization(), Dropout(0.4), Dense(10, activation='softmax', kernel_initializer='glorot_normal')])
checkpoint = tf.keras.callbacks.ModelCheckpoint('model.h5', save_best_only=True)
early_stopping = tf.keras.callbacks.EarlyStopping(patience=20)
model.compile(optimizer='nadam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
history = model.fit(X_train, y_train, epochs=200, validation_data=(X_valid, y_valid), callbacks=[checkpoint, early_stopping])

model = tf.keras.models.load_model('model.h5')
model.evaluate(X_test, y_test)

data_sub = np.array(data_sub).reshape(-1, 28, 28, 1) / 255.0

preds = model.predict(data_sub)

np.argmax(preds[0])