0

I am using my own top K accuracy metric for multi label classification:

def top_K_acc(y_true, y_pred, k):
    assert y_true.shape == y_pred.shape
    top_k_indx = np.argsort(y_pred, axis=1)[:,::-1][:,:k]
    n_guessed = 0
    for i in range(len(y_true)):
        if np.any(y_true[i,top_k_indx[i]]):
            n_guessed += 1
    print(n_guessed / len(y_true))

but it's always shows higher accuracy than top_k_categorical_accuracy from Keras. What am I doing wrong?

0x1337
  • 1,074
  • 1
  • 14
  • 33

0 Answers0