BLOGLLM Logo
Go Pro
Guest
Not signed in
所有博客课程练习面试准备系列标签书签价格
Log in
All BlogsCoursesPracticeTagsBookmarksPricing
My PrepProblemsStudy PlansResearch PapersRoadmapInterviewContestsLeaderboard游戏
Articles
练习 / Recommender systems6 of 22 in topic

199. 为冷启动用户融合个人与热门评分

EasyRecommender systems

重要性 向流行度收缩是信息流、电商和流媒体应用中解决冷启动用户的标准方案。

一个只有两次交互的用户其个人画像具有噪声。推荐系统会将此类用户向全局流行度评分进行收缩,并随着历史数据的增长更加信任个人模型。

编写 blend_scores(personal, popular, n, shrink, k)。personal 和 popular 是长度为 I 的评分列表(对于全新的用户,personal 可能为 None)。信任权重为 w = n / (n + shrink),如果 personal 为 None,则 w = 0。Score = w * personal + (1 - w) * popular。返回 (作为 numpy array 的 scores,以及按 score 排序的前 k 个 item 索引列表,若分数相同则取较小的索引)。

函数def blend_scores(personal, popular, n, shrink, k)

示例 1

输入: blend_scores([1, 0, 0], [0, 1, 0.5], 1, 3, 2)

输出: (array([0.25, 0.75, 0.375]), [1, 2])

示例 2

输入: personal = [0.9, 0.1, 0.2, 0.0], popular = [0.1, 0.8, 0.5, 0.3], n = 97, shrink = 3, k = 2

输出: ([0.876, 0.121, 0.209, 0.009], [0, 2])

示例 3

输入: personal = None, popular = [0.2, 0.9, 0.9], n = 0, shrink = 5, k = 3

输出: ([0.2, 0.9, 0.9], [1, 2, 0])

约束条件

  • Python 3 with NumPy. Code runs in your browser.
  • Your code must pass all 4 tests to be accepted.
提示 1

历史数据越多,个人评分的权重就越大。

提示 2

先处理 personal is None 的情况。

提示 3

w = n / (n + shrink)。

提示 4

按 (-score, index) 对索引进行排序。

常见错误
  • 颠倒了 w 和 1 - w。
  • 当 personal 为 None 时程序崩溃。
  • 在某个 n 值处使用硬切换,导致推荐结果发生跳变。
理解思路

新用户的个人模型是基于极少量数据构建的,因此大多是噪声。热门项目对任何人来说都是一个安全的猜测。解决方法是将两者融合,并随着证据的积累将融合重心向个人评分移动,就像你在朋友经常外出就餐后会更信任他们的餐厅建议一样。

Worked example

shrink 为 3,用户有 n = 1 次交互。w = 1 / (1 + 3) = 0.25。一个个人模型非常喜欢 (1.0) 但其他人都不看的项目 (0) 会得到 0.25。一个个人模型忽略 (0) 但很热门 (1.0) 的项目会得到 0.75。当 n = 97 时,w = 0.97,个人模型开始占据主导地位。

w = n / (n + shrink); score = w * personal + (1 - w) * popular

shrink 常数是在线下调整的;它等于两种来源获得相等权重时的交互次数。

主题
Recommender systems
相似题目
  • 衡量推荐系统的 hit rate 和 recall at kEasy
  • 计算隐式反馈的 BPR ranking loss 并防止溢出Easy
  • 推荐最热门的未见过的物品Easy
  • 衡量推荐系统的目录覆盖率Easy
所有 Recommender systems 道题目
反馈
199 / 903
Python 3solution.pyPython 空闲
1
2
3
4
5
6
import numpy as np
​
def blend_scores(personal, popular, n, shrink, k):
# your code here
pass
​

Run 会在浏览器中检查这些用例,无需登录。 Submit 会检查所有 4 个测试。

Ctrl/按 + 回车 运行
© BlogLLM, Bengaluru, India关于条款隐私退款DMCA联系我们RSS