我使用自己的最高K精度指标进行多标签分类:
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))
但它始终显示出比Keras top_k_categorical_accuracy
更高的准确度。我做错了什么?