massquantity / LibRecommender

Versatile End-to-End Recommender System
https://librecommender.readthedocs.io/
MIT License
353 stars 62 forks source link

Consider Recall Computation #71

Open apdullahyayik opened 3 years ago

apdullahyayik commented 3 years ago

Computation of recall at evaluation/metric.py does not consider "k" value which is passed as an arg. Whereas at the same module computation of precision uses "k" value. I think, there may be smthg wrong here.

def recall_at_k(y_true_list, y_reco_list, users, k):
    recall_all = list()
    for u in users:
        y_true = y_true_list[u]
        y_reco = y_reco_list[u]
        common_items = set(y_reco).intersection(y_true)
        recall = len(common_items) / len(y_true)
        recall_all.append(recall)
    return np.mean(recall_all)
massquantity commented 3 years ago

Yep, k of recall in evaluation/metric.py is redundant, but for the sake of consistency with other metrics, I still add it into the recall function. In my opinion, the k of recall_at_k is already included in y_reco, since it has length of k. But I'm not sure about this, any suggestions?

apdullahyayik commented 3 years ago

No I don't have since it is cool. Two more questions here. (1) Computation of recall looks like hit rate: "computation of intersections by discarding the order". Is it true? I may be wrong, maybe hit rate needs considering the order. (2) Where is the difference between precision and recall on the code?

def precision_at_k(y_true_list, y_reco_list, users, k):
    precision_all = list()
    for u in users:
        y_true = y_true_list[u]
        y_reco = y_reco_list[u]
        common_items = set(y_reco).intersection(y_true)
        precision = len(common_items) / k
        precision_all.append(precision)
    return np.mean(precision_all)

Answer is appreciated.

massquantity commented 3 years ago
  1. I don't know about hit rate before. After searching on the web, they does look similar.
  2. There is only one difference. The denominator in precision is k, whereas that of recall is len(y_true)