keras中自定义了MRR,结果训练集和预测集中出现 - MRR: 0.0000e+00 -- val_MRR: 0.0000e+00
def MRR(y_true, y_pred):
c = tf.argsort(y_pred, direction='DESCENDING')
c = tf.cast(c, dtype=tf.float32)
d = tf.cast(tf.argmax(y_true, -1), dtype=tf.float32)
e = len(c)
h = 0
for i in range(e):
for j in range(5):
if d[i] == c[i][j]:
h += 1 / (j + 1)
return h / e
''''''
model.compile(
loss='categorical_crossentropy',
#loss='binary_crossentropy',
optimizer=keras.optimizers.Adam(config.learning_rate),
metrics=['top_k_categorical_accuracy',MRR]
)