Novelty Score
Novelty Score
Novelty measures how surprising or unexpected recommendations are to a user. It is based on the idea that recommending popular items everyone has seen is not very useful, while recommending lesser-known items provides more value. Novelty is computed using self-information: the less popular an item, the more novel it is.
Given a list of recommended item indices, their interaction counts, and the total number of users, compute the average novelty score.
Formula
novelty=∣R∣1i∈R∑−log2(Ncounti)where counti is the number of users who interacted with item i, and N is the total number of users.
Examples
Input:
recommendations = [0, 1], item_counts = [100, 100], n_users = 100
Output:
0.0
Both items were seen by all 100 users. Popularity = 1.0. -log2(1.0) = 0. These items have zero novelty.
Input:
recommendations = [0, 1], item_counts = [1, 1], n_users = 100
Output:
6.6439
Both items were seen by only 1 user. Popularity = 0.01. -log2(0.01) = 6.6439. Very novel items.
Hint 1
For each recommended item, compute popularity = item_counts[item] / n_users. Then compute -math.log2(popularity). Average over all items.
Hint 2
Be careful: use log base 2 (math.log2), not natural log (math.log). Also handle the edge case where the recommendation list is empty.
Requirements
- Compute the popularity of each recommended item as count / n_users
- Use base-2 logarithm for the self-information calculation
- Average the novelty scores across all recommended items
- Return 0.0 if the recommendation list is empty
Constraints
- recommendations contains item indices into item_counts
- item_counts[i] > 0 for all recommended items
- n_users > 0
- Return a float
- Time limit: 300 ms
Log in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number
Novelty Score
Novelty Score
Novelty measures how surprising or unexpected recommendations are to a user. It is based on the idea that recommending popular items everyone has seen is not very useful, while recommending lesser-known items provides more value. Novelty is computed using self-information: the less popular an item, the more novel it is.
Given a list of recommended item indices, their interaction counts, and the total number of users, compute the average novelty score.
Formula
novelty=∣R∣1i∈R∑−log2(Ncounti)where counti is the number of users who interacted with item i, and N is the total number of users.
Examples
Input:
recommendations = [0, 1], item_counts = [100, 100], n_users = 100
Output:
0.0
Both items were seen by all 100 users. Popularity = 1.0. -log2(1.0) = 0. These items have zero novelty.
Input:
recommendations = [0, 1], item_counts = [1, 1], n_users = 100
Output:
6.6439
Both items were seen by only 1 user. Popularity = 0.01. -log2(0.01) = 6.6439. Very novel items.
Hint 1
For each recommended item, compute popularity = item_counts[item] / n_users. Then compute -math.log2(popularity). Average over all items.
Hint 2
Be careful: use log base 2 (math.log2), not natural log (math.log). Also handle the edge case where the recommendation list is empty.
Requirements
- Compute the popularity of each recommended item as count / n_users
- Use base-2 logarithm for the self-information calculation
- Average the novelty scores across all recommended items
- Return 0.0 if the recommendation list is empty
Constraints
- recommendations contains item indices into item_counts
- item_counts[i] > 0 for all recommended items
- n_users > 0
- Return a float
- Time limit: 300 ms
Log in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number