GNNRecom/gnnrec/kgrec/utils/metrics.py

11 lines
277 B
Python
Raw Normal View History

2021-11-16 07:04:52 +00:00
def precision_at_k(y_true, y_pred, k):
y_true = set(y_true)
y_pred = set(y_pred[:k])
return len(set(y_true & y_pred)) / k
def recall_at_k(y_true, y_pred, k):
y_true = set(y_true)
y_pred = set(y_pred[:k])
return len(set(y_true & y_pred)) / len(y_true)