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

from keras.models import Sequential

from keras.utils import np_utils

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

import pandas as pd

import pandas as pd
import numpy as np
df_train = pd.read_csv('../input/train.csv', encoding='big5')
df_train[:5]

from sklearn.model_selection import train_test_split
from keras.utils import np_utils
X_train = df_train[df_train.columns[1:]].values
y_train = df_train['label'].values
X_train = X_train.reshape(X_train.shape[0], 28, 28, 1) / 255
y_train_oneHot = np_utils.to_categorical(y_train, num_classes=10)

from keras.models import Sequential
from keras.layers import Dense, Activation, Conv2D, MaxPooling2D, Dropout, Flatten, BatchNormalization
model = Sequential()
model.add(Conv2D(filters=16, kernel_size=(3, 3), input_shape=(28, 28, 1), activation='relu'))
model.add(BatchNormalization())
model.add(Conv2D(filters=16, kernel_size=(3, 3), activation='relu'))
model.add(BatchNormalization())
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Conv2D(filters=32, kernel_size=(3, 3), activation='relu'))
model.add(BatchNormalization())
model.add(Conv2D(filters=32, kernel_size=(3, 3), activation='relu'))
model.add(BatchNormalization())
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(512, activation='relu', kernel_initializer='normal'))
model.add(Dropout(0.25))
model.add(Dense(1024, activation='relu', kernel_initializer='normal'))
model.add(Dropout(0.5))
model.add(Dense(10, activation='softmax'))
model.summary()

model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
history = model.fit(X_train, y_train_oneHot, validation_split=0.2, epochs=20, batch_size=250, verbose=1)

plt.figure(figsize=(12, 4))
plt.subplot(1, 2, 1)
plot_train_history(history, 'loss', 'val_loss')
plt.subplot(1, 2, 2)
plot_train_history(history, 'acc', 'val_acc')