I'm working on a multiclass classification problem using Keras and I'm using binary accuracy and categorical accuracy as metrics. When I evaluate my model I get a really high value for the binary accuracy and quite a low one in for the categorical accuracy. I tried to recreate the binary accuracy metric in my own code but I am not having much luck. My understanding is that this is the process I need to recreate:
def binary_accuracy(y_true, y_pred):
return K.mean(K.equal(y_true, K.round(y_pred)), axis=-1)
Here is my code:
from keras import backend as K
preds = model.predict(X_test, batch_size = 128)
print preds
pos = 0.00
neg = 0.00
for i, val in enumerate(roundpreds):
if val.tolist() == y_test[i]:
pos += 1.0
else:
neg += 1.0
print pos/(pos + neg)
But this gives a much lower value than the one given by binary accuracy. Is binary accuracy even an appropriate metric to be using in a multi-class problem? If so does anyone know where I am going wrong?