def evaluate(classes, y_gt, y_pred, threshold_value=0.5):
"""
Arguments:
y_gt (num_bag x L): groud truth
y_pred (num_bag x L): prediction
"""
print("thresh = {:.6f}".format(threshold_value))
y_pred_bin = y_pred >= threshold_value
score_f1_macro = f1_score(y_gt, y_pred_bin, average="macro")
print("Macro f1_socre = {:.6f}".format(score_f1_macro))
score_f1_micro = f1_score(y_gt, y_pred_bin, average="micro")
print("Micro f1_socre = {:.6f}".format(score_f1_micro))
# hamming loss
h_loss = hamming_loss(y_gt, y_pred_bin)
print("Hamming Loss = {:.6f}".format(h_loss))
mAP = average_precision_score(y_gt, y_pred)
print("mAP = {:.2f}%".format(mAP * 100))
# ap_classes = []
# for i, cls in enumerate(classes):
# ap_cls = average_precision_score(y_gt[:, i], y_pred[:, i])
# ap_classes.append(ap_cls)
# print("AP({}) = {:.2f}%".format(cls, ap_cls * 100))
# print("mAP = {:.2f}%".format(np.mean(ap_classes) * 100))
评论列表
文章目录