text_plain_output_1.png
from keras.callbacks import ModelCheckpoint

from keras.layers import Dense, Dropout

from keras.models import Sequential

from keras.utils import np_utils

X_train_matrix = X_train_matrix.astype('float32') / 255
X_test_matrix = X_test_matrix.astype('float32') / 255

from keras.utils import np_utils
y_train_matrix = np_utils.to_categorical(y_train_matrix, 10)
y_test_matrix = np_utils.to_categorical(y_test_matrix, 10)

from keras.models import Sequential
from keras.layers import Dense, Dropout
model = Sequential()
model.add(Dense(784, input_shape=(len(X_train_matrix[0]),)))
model.add(Dense(392, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(196, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(10, activation='softmax'))
model.summary()

model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
score = model.evaluate(X_test_matrix, y_test_matrix, verbose=0)
accuracy = score[1] * 100

history = model.fit(X_train_matrix, y_train_matrix, batch_size=100, epochs=6, verbose=1)

from keras.callbacks import ModelCheckpoint
cb_checkpoint = ModelCheckpoint(filepath='best-model.hdf5', verbose=1, save_best_only=True)
history = model.fit(X_train_matrix, y_train_matrix, batch_size=400, epochs=6, validation_split=0.2, shuffle=True, callbacks=[cb_checkpoint], verbose=1)