TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Hit Rate at K

Recommender SystemsMetrics & Evaluation
Easy

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⁡=1∣U∣∑u∈U1(Ru(K)∩Gu≠∅)\operatorname{HR@K} = \frac{1}{|U|}\sum_{u \in U}\mathbb{1}(R_u^{(K)} \cap G_u \ne \varnothing)HR@K=∣U∣1​u∈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.

Loading visualization...

Examples

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

Hint 1

Convert each first-k slice and corresponding ground-truth list to sets.

Hint 2

A nonempty set intersection contributes one hit.

Requirements

  • Inspect only the first k recommendations for each user.
  • Count at most one hit per user.
  • Divide the hit count by the number of users.
  • Return 0.0 when there are no users.

Constraints

  • recommendations and ground_truth contain the same number of user lists.
  • k is positive.
  • Time limit: 300 ms.
Try Similar Problems
Precision Recall At KMean Average PrecisionNdcgTop K RecommendationsCatalog Coverage

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

Accepts: number

You must run your code first.
PrevNext

Hit Rate at K

Recommender SystemsMetrics & Evaluation
Easy

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⁡=1∣U∣∑u∈U1(Ru(K)∩Gu≠∅)\operatorname{HR@K} = \frac{1}{|U|}\sum_{u \in U}\mathbb{1}(R_u^{(K)} \cap G_u \ne \varnothing)HR@K=∣U∣1​u∈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.

Loading visualization...

Examples

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

Hint 1

Convert each first-k slice and corresponding ground-truth list to sets.

Hint 2

A nonempty set intersection contributes one hit.

Requirements

  • Inspect only the first k recommendations for each user.
  • Count at most one hit per user.
  • Divide the hit count by the number of users.
  • Return 0.0 when there are no users.

Constraints

  • recommendations and ground_truth contain the same number of user lists.
  • k is positive.
  • Time limit: 300 ms.
Try Similar Problems
Precision Recall At KMean Average PrecisionNdcgTop K RecommendationsCatalog Coverage

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

Accepts: number

You must run your code first.