Ranking orders a candidate set by a final score and selects the items to recommend. It can balance multiple objectives, such as similarity and popularity. section 2.2.5
Within a recommender pipeline, ranking:
- Makes final ordering decisions after retrieval, filtering, and scoring. section 2.2.8
- Can trade off similarity and popularity by changing their weights; more advanced rankers may also account for diversity, business rules, position bias, and exploration versus exploitation. section 2.2.5
- Needs room to work: retrieving 2–10 times the desired final list size leaves candidates available after filtering. section 2.2.5
Changing the weights
For a movie recommender, rank candidates using a weighted combination of similarity and popularity. Comparing similarity weights of 1.0, 0.5, and 0.0 shows how the balance changes the top-five results. section 2.2.5
Listing 2.9 Ranking by weighted scores
def rank_candidates(candidates, similarity_weight=0.7, k=10):
for item in candidates:
item['final_score'] = (
similarity_weight * item['similarity'] +
(1 - similarity_weight) * item['popularity']
) #A
ranked = sorted(
candidates,
key=lambda x: x['final_score'],
reverse=True
) #B
return ranked[:k] #CThe Python example calculates each candidate’s weighted score, sorts by that score, and returns the top k. section 2.2.5








