How to use Keras' multi layer perceptron for multi-class classification

This is a pretty common beginner's mistake with Keras. Unlike other Deep Learning frameworks, Keras does not use integer labels for the usual crossentropy loss, instead it expects a binary vector (called "one-hot"), where the vector is just 0's and a 1 over the index of the right class.

You can easily convert your labels to this format with the following code:

from keras.utils.np_utils import to_categorical
y_train = to_categorical(y_train)
y_test = to_categorical(y_test)

Before model.fit. An alternative is to change the loss to "sparse_categorical_crossentropy", which does expect integer labels.