# How does keras calculate accuracy for multi label classification?

I am using this code for a multilabel problem classification.

from __future__ import print_function

from keras.preprocessing import sequence
from keras.models import Sequential
from keras.layers import Dense, Embedding
from keras.layers import LSTM
from keras.models import Model
from keras.datasets import imdb

max_features = len(vocabDic)
maxlen = 500  # cut texts after this number of words (among top max_features most common words)
batch_size = 32

print('train_set shape:', train_set.shape)
print('test_set shape:', test_set.shape)

print('Build model...')
model = Sequential()

# try using different optimizers and different optimizer configs
model.compile(loss='binary_crossentropy',
metrics=['accuracy'])

print('Train...')
model.fit(train_set, train_labels,
batch_size=batch_size,
epochs=15,
validation_data=(test_set, test_labels))
score, acc = model.evaluate(test_set, test_labels,
batch_size=batch_size)
print('Test score:', score)
print('Test accuracy:', acc)


My problem is there are 90 classes and the accuracy is too high from the second epoch. I suspect keras is computing something incorrectly. Any clues?

Edit: I calculated the total recall of the model. It is barely 5%( 5 times better than random). Is it a normal behavior for such a problem?

• It may happen and is not strange. depending on your data you may have even better results in first epoch. I've seen the similar thing in mnist – Media Dec 17 '17 at 21:21
• I see you're using binary cross-entropy for your cost function. For multi-class classification you could look into categorical cross-entropy and categorical accuracy for your loss and metric, and troubleshoot with sklearn.metrics.classification_report on your test set – redhqs Dec 18 '17 at 11:07
• Just to clarify: are you talking about multi-label (individual samples may belong to more than one classes) or multi-class (individual samples belong to one and only one class) classification here? – desertnaut Dec 19 '17 at 16:20