def calc_metric(score_label_u): score_label_u = sorted(score_label_u, key=lambda d: d[0], reverse=True) precision = np.array( [eval.precision_k(score_label_u, k) for k in range(1, 21)]) ndcg = np.array([eval.ndcg_k(score_label_u, k) for k in range(1, 21)]) auc = eval.auc(score_label_u) mae = eval.mae(score_label_u) mrse = eval.mrse(score_label_u) return precision, ndcg, auc, mae, mrse
def calc_metric(score_label_u): score_label_u = sorted(score_label_u, key=lambda d: d[0], reverse=True) precision = eval.precision_k(score_label_u, 3) recall = eval.recall_k(score_label_u, 3) try: f1 = 2 * precision * recall / (precision + recall) except: f1 = 0 auc = eval.auc(score_label_u) ndcg = eval.ndcg_k(score_label_u, 3) return precision, recall, f1, auc, ndcg