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

from tensorflow.keras.models import Sequential

from tensorflow.keras.preprocessing.image import ImageDataGenerator

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

train_data = pd.read_csv('../input/digit-recognizer/train.csv')
test_data = pd.read_csv('../input/digit-recognizer/test.csv')
submission = pd.read_csv('../input/digit-recognizer/sample_submission.csv')

X = train_data.drop(columns='label')

X = X / 255
X_test = test_data.values.reshape(-1, 28, 28, 1)

X = X.values.reshape(-1, 28, 28, 1)
X_test = X_test / 255

(X_train.shape, X_val.shape, y_train.shape, y_val.shape)

datagen = ImageDataGenerator(featurewise_center=False, samplewise_center=False, featurewise_std_normalization=False, samplewise_std_normalization=False, zca_whitening=False, rotation_range=15, zoom_range=0.01, width_shift_range=0.1, height_shift_range=0.1, horizontal_flip=False, vertical_flip=False)
datagen.fit(X_train)

model = Sequential([Conv2D(16, (3, 3), padding='same', activation='relu', input_shape=(28, 28, 1)), BatchNormalization(), Conv2D(32, (3, 3), padding='same', activation='relu'), BatchNormalization(), MaxPooling2D(2, 2), Dropout(0.25), Conv2D(64, (3, 3), padding='same', activation='relu'), BatchNormalization(), MaxPooling2D(2, 2), Conv2D(128, (3, 3), padding='same', activation='relu'), BatchNormalization(), MaxPooling2D(2, 2), Flatten(), Dense(256, activation='relu'), BatchNormalization(), Dropout(0.25), Dense(10, activation='softmax')])
model.summary()

model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

callbacks = MyCallback(monitor='val_accuracy')

history = model.fit(datagen.flow(X_train, y_train, batch_size=100), steps_per_epoch=len(X_train) / 100, epochs=20, validation_data=(X_val, y_val), callbacks=[callbacks])

predictions = model.predict(X_test)