Skip to content

Commit

Permalink
added recall@k
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Maksimov committed Jun 4, 2020
1 parent df89619 commit 2a662c8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ def recall(recommended_list, bought_list):


def recall_at_k(recommended_list, bought_list, k=5):
# your_code

bought_list = np.array(bought_list)
recommended_list = np.array(recommended_list)

if k < len(recommended_list):
recommended_list = recommended_list[:k]

flags = np.isin(bought_list, recommended_list)
recall = flags.sum() / len(bought_list)

return recall

Expand Down

0 comments on commit 2a662c8

Please sign in to comment.