Hit rate at K measures the fraction of users whose first k recommendations contain at least one relevant item. A user contributes one hit regardless of how many relevant items appear.
HR@K=∣U∣1u∈U∑1(Ru(K)∩Gu=∅)The sum examines every user. For each user, the indicator contributes 1 when the first k recommendations share at least one item with that user's ground-truth relevant items; otherwise it contributes 0. Divide the total hits by the number of users. Return 0.0 when there are no users.
Input: recommendations = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], ground_truth = [[1], [10], [7]], k = 3
Output: 0.6667
Explanation: Users 0 and 2 have at least one relevant item in their first three recommendations.
Input: recommendations = [[10, 1, 2, 3], [10, 4, 5, 6]], ground_truth = [[1], [4]], k = 1
Output: 0.0000
Convert each first-k slice and corresponding ground-truth list to sets.
A nonempty set intersection contributes one hit.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number
Hit rate at K measures the fraction of users whose first k recommendations contain at least one relevant item. A user contributes one hit regardless of how many relevant items appear.
HR@K=∣U∣1u∈U∑1(Ru(K)∩Gu=∅)The sum examines every user. For each user, the indicator contributes 1 when the first k recommendations share at least one item with that user's ground-truth relevant items; otherwise it contributes 0. Divide the total hits by the number of users. Return 0.0 when there are no users.
Input: recommendations = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], ground_truth = [[1], [10], [7]], k = 3
Output: 0.6667
Explanation: Users 0 and 2 have at least one relevant item in their first three recommendations.
Input: recommendations = [[10, 1, 2, 3], [10, 4, 5, 6]], ground_truth = [[1], [4]], k = 1
Output: 0.0000
Convert each first-k slice and corresponding ground-truth list to sets.
A nonempty set intersection contributes one hit.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number