Problems
Loading...
1 / 1

Popularity Ranking

Recommender Systems
Easy

A naive popularity ranking simply sorts items by average rating, but this unfairly favors items with very few ratings. An item with a single 10/10 rating would outrank a consistently 9.5-rated item with thousands of reviews. The Bayesian weighted rating (used by IMDB's Top 250) solves this by blending the item's average with the global mean, weighted by the number of votes.

Given a list of items with their average rating and vote count, a minimum vote threshold m, and the global mean rating C, compute the weighted rating for each item.

Algorithm

WR=vv+mR+mv+mCWR = \frac{v}{v + m} \cdot R + \frac{m}{v + m} \cdot C

where R is the item's average rating, v is its vote count, m is the minimum vote threshold, and C is the global mean rating.

Loading visualization...

Examples

Input:

items = [(8.5, 1000), (9.2, 50)], min_votes = 100, global_mean = 7.5

Output:

[8.409, 8.067]

Item 0 has many votes so its WR stays close to 8.5. Item 1 has few votes (50 < 100) so it is pulled strongly toward the global mean of 7.5, dropping from 9.2 to 8.067.

Input:

items = [(10.0, 1)], min_votes = 100, global_mean = 5.0

Output:

[5.0495]

With only 1 vote against a threshold of 100, the weighted rating is almost entirely the global mean: (1/101)*10 + (100/101)*5 = 5.0495.

Hint 1

For each (avg_rating, num_votes) pair, compute: (num_votes / (num_votes + min_votes)) * avg_rating + (min_votes / (num_votes + min_votes)) * global_mean.

Hint 2

When num_votes is 0, the formula gives (0/(0+m))*R + (m/m)*C = C, which is exactly the global mean. This is the correct behavior - no votes means we fall back to the prior.

Requirements

  • For each item, blend its average rating with the global mean using vote counts
  • Items with more votes should stay closer to their own average
  • Items with fewer votes should be pulled toward the global mean
  • Return a list of floats

Constraints

  • items is a list of (average_rating, num_votes) tuples
  • min_votes > 0
  • Return a list of floats
  • Time limit: 300 ms
Try Similar Problems