推荐算法主要分为基于内容的算法和协同过滤. 协同过滤的两种基本方法是基于邻居的方法(基于内容/物品的协同过滤)和隐语义模型. 矩阵分解乃是实现隐语义模型的基石.
矩阵分解依据用户对物品的评分, 判断出用户和物品的隐语义向量, 然后依据用户和物品的隐语义向量来进行推荐.
推荐系统用到的数据能够有显式评分和隐式评分. 显式评分时用户对物品的打分, 显式评分矩阵通常很稀疏. 隐式评分是指用户的浏览, 购买, 搜索等历史记录, 表示的是用户行为的有无, 所以是一个密集矩阵.
矩阵分解方法会将用户和物品映射到
维的隐向量空间,
用户对物品的评分表示为两个向量的内积. 亦即, 每一个物品
表示为向量
,
每一个用户表示成向量
.
对于物品
,
向量
的元素表示的是物品
具有这些隐因子的程度,
对于用户
,
向量
表示的是用户对各个隐因子的兴趣,
元素的值可正可负. 两个向量的内积
![hat{r_{ui}}=q_i^Tp_u ag{1}](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_f1842165e1bfbc01652f06a406b78d39.gif)
表示的就是预计的用户对物品的评分. 所以基本的挑战就是计算用户和物品到隐向量的映射.
最简单的就是神秘值分解(Singular value decomposition, SVD), 使用SVD须要分解用户物品评分矩阵, 可是通常该矩阵中有非常多值是缺失的, 这样的情况下的SVD是不可行的. 另外, 仅仅处理已知的这些评分easy导致过拟合. 能够通过填充数据来使得矩阵变得稠密, 可是填充数据的准确性非常是问题.
最主流的做法是仅仅对那些已观測到的评分进行建模, 而且通过使用正则化项来避免过拟合, 亦即求解下面问题:
![min_{q, p}sum_{(u,i)inmathcal{k}}(r_{ui}-q_i^Tp_u)^2 + lambda(|p_u|^2 + |q_i|^2) ag{2}](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_0c410ed91a264b2e39a14c4345cf7eb7.gif)
当中
是所以已知评分的用户-物品对,
控制着正则化的程度.
两种经常使用的求解上式的算法为随机梯度下降(SGD)和ALS(Alternating Least Square).
对于每一个用户-物品评分, 计算预測误差
![e_{ui} = r_{ui} - q_i^Tp_u](http://www.kemaswill.com/wp-content/plugins/latex/cache/tex_94d3ec96ceaac5b3756a2a4accb28afa.gif)
然后依照梯度下降的方向更新用户和物品的隐向量:
![q_i leftarrow q_i + gammacdot(e_{ui}cdotp_{u}-lambdacdot q_i)](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_fe70976f9bb0f2d65c2f7ab8b2789941.gif)
![p_u leftarrow p_u + gammacdot(e_{ui}cdot q_{i}-lambdacdotp_u)](http://ju.outofmemory.cn/imgr?</p><p>src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_c5fda757cead5d73fad7a7d1743ef7c1.gif)
由于
和
都是未知的,
所以公式2不是凸的. 可是, 当我们固定当中一个变量, 则2式变成一个二次函数, 可以被最优的求解. 所以ALS算法的思想就是交替的固定
和
,
然后求解另外一个变量的二次函数的最优值.
通常SGD都会比ALS要简单并且高速, 可是ALS的并行性比較好, 并且能够较好地处理稀疏数据(?).
矩阵分解方法的一个优点就是能够灵活的加入很多面向应用的要求. 比方, 通常来说, 不同用户的评分倾向不同, 用的用户的打分普遍较高, 有的普遍较低, 物品亦然. 所以只使用用户和物品之间的交互
来对评分进行建模不是非常好,
还须要加上一些偏置项. 一种一阶偏置项近似为:
![b_{ui}=mu+b_i+b_u](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_fecd850b519ac15cb3bda0c112e2a08a.gif)
当中
描写叙述的是全部评分的平均值,
描写叙述的是用户和物品相对于
的偏差.
评分模型为:
![hat{r_{ui}}=mu + b_i | b_u + q_i^Tp_u](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_18bc3666f4b22add2eaa5c6279c232cd.gif)
转化为最优化问题为:
![min_{pcdot,qcdot,bcdot}sum_{(u,i)inmathcal{k}}(r_{ui}-mu-b_u-b_i-p_u^Tq_i)^2 + lambda(|p_u|^2 + |q_i|^2 +b_u^2+ b_i^2)](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_04d35408c8fb1aba54eece2afa180dce.gif)
当解决冷启动问题时, 用户的评分信息非常少, 这时候就须要使用用户的其它输入信息, 比方用户隐式反馈(浏览, 购买历史等). 令
表示用户有隐反馈的物品.
系统能够通过这些物品来对用户建模, 亦即把每一个物品表示成一个隐向量
,
则用户能够通过下式来描写叙述:
![sum_{iin N(u)}x_i](http://ju.outofmemory.cn/imgr?</p><p>src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_4fad5c905d6e355f3daafbffab7a00e7.gif)
能够对上式进行正则化:
![|N(u)|^{-0.5}sum_{iin N(u)}x_i](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_911ec8c0604bc13af71e7b589e04e365.gif)
也能够使用用户的一些其它属性(性别, 年龄, 收入等)来对用户建模, 令
表示用户的一些布尔属性,则隐向量
表示用户的某个属性,
用户的全部属性能够通过下式来描写叙述:
![sum_{ain A(u)}y_a](http://ju.outofmemory.cn/imgr?</p><p>src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_736d555e98da6d653ec58b60b91f5af2.gif)
用户对物品的评分能够表示为:
![hat{r_{ui}}=mu + b_i | b_u + q_i^T[p_u + |N(u)|^{-0.5}sum_{iin N(u)}x_i +sum_{ain A(u)}y_a]](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_23f02ffc32483e5eb712707ff785a043.gif)
到如今为止, 模型是静态的, 可是实际中物品的流行程度会随着时间变化, 用户的评分倾向也会变化, 用户的隐向量也会随时间变化. 所以能够将这些变量表示成时间的函数来更好地描写叙述这些现象:
![hat{r}_{ui}=mu + b_i(t) + b_u(t) + q_i^Tp_u(t)](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_686c0f90c139cee061b24d0722820dcf.gif)
不同的评分的可信度不同. 比方广告会影响某个物品的评分, 另外, 有些作弊的用户会对某些物品恶意的打高分或者低分. 另外, 在使用隐式反馈时, 能够使用某些行为(比方浏览)等得次数来表示用户喜欢某个物品的程度. 能够通过为某个评分
设置权重
来解决上述问题:
![min_{pcdot,qcdot,bcdot}sum_{(u,i)inmathcal{k}}(c_{ui}(r_{ui}-mu-b_u-b_i-p_u^Tq_i)^2 + lambda(|p_u|^2 + |q_i|^2 +b_u^2+ b_i^2)](http://ju.outofmemory.cn/imgr?</p><p>src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_abe5557497eb4023e0211116028b4b6a.gif)
參考文献:
[1]. Yuhuda Koren, Robert Bell and Chris Volinsky. Matrix Factorization Techniques for Recommender Systems.
矩阵分解依据用户对物品的评分, 判断出用户和物品的隐语义向量, 然后依据用户和物品的隐语义向量来进行推荐.
推荐系统用到的数据能够有显式评分和隐式评分. 显式评分时用户对物品的打分, 显式评分矩阵通常很稀疏. 隐式评分是指用户的浏览, 购买, 搜索等历史记录, 表示的是用户行为的有无, 所以是一个密集矩阵.
1. 基本矩阵分解
矩阵分解方法会将用户和物品映射到
![f](http://ju.outofmemory.cn/imgr?</p><p>src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_8fa14cdd754f91cc6554c9e71929cce7.gif)
![i](http://www.kemaswill.com/wp-content/plugins/latex/cache/tex_865c0c0b4ab0e063e5caa3387c1a8741.gif)
![q_iinmathbb{R}^f](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_d79f24e0a07cae1309a3ad421191e412.gif)
![p_uinmathbb{R}^f](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_a33d84d635a246c17ea6d9278af14f49.gif)
![i](http://www.kemaswill.com/wp-content/plugins/latex/cache/tex_865c0c0b4ab0e063e5caa3387c1a8741.gif)
![q_i](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_da326f7200e158a864695985b2e2f095.gif)
![i](http://www.kemaswill.com/wp-content/plugins/latex/cache/tex_865c0c0b4ab0e063e5caa3387c1a8741.gif)
![u](http://www.kemaswill.com/wp-content/plugins/latex/cache/tex_7b774effe4a349c6dd82ad4f4f21d34c.gif)
![p_u](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_742d6853edfafaca8ffd726cd8457162.gif)
![hat{r_{ui}}=q_i^Tp_u ag{1}](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_f1842165e1bfbc01652f06a406b78d39.gif)
表示的就是预计的用户对物品的评分. 所以基本的挑战就是计算用户和物品到隐向量的映射.
最简单的就是神秘值分解(Singular value decomposition, SVD), 使用SVD须要分解用户物品评分矩阵, 可是通常该矩阵中有非常多值是缺失的, 这样的情况下的SVD是不可行的. 另外, 仅仅处理已知的这些评分easy导致过拟合. 能够通过填充数据来使得矩阵变得稠密, 可是填充数据的准确性非常是问题.
最主流的做法是仅仅对那些已观測到的评分进行建模, 而且通过使用正则化项来避免过拟合, 亦即求解下面问题:
![min_{q, p}sum_{(u,i)inmathcal{k}}(r_{ui}-q_i^Tp_u)^2 + lambda(|p_u|^2 + |q_i|^2) ag{2}](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_0c410ed91a264b2e39a14c4345cf7eb7.gif)
当中
![mathcal{k}](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_5ca2232dd8907417b5e33cbca27797fb.gif)
![lambda](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_c6a6eb61fd9c6c913da73b3642ca147d.gif)
2. 学习算法
两种经常使用的求解上式的算法为随机梯度下降(SGD)和ALS(Alternating Least Square).
2.1 随机梯度下降
对于每一个用户-物品评分, 计算预測误差
![e_{ui} = r_{ui} - q_i^Tp_u](http://www.kemaswill.com/wp-content/plugins/latex/cache/tex_94d3ec96ceaac5b3756a2a4accb28afa.gif)
然后依照梯度下降的方向更新用户和物品的隐向量:
![q_i leftarrow q_i + gammacdot(e_{ui}cdotp_{u}-lambdacdot q_i)](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_fe70976f9bb0f2d65c2f7ab8b2789941.gif)
![p_u leftarrow p_u + gammacdot(e_{ui}cdot q_{i}-lambdacdotp_u)](http://ju.outofmemory.cn/imgr?</p><p>src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_c5fda757cead5d73fad7a7d1743ef7c1.gif)
2.2 ALS(Alternating Least Square)
由于
![p_u](http://ju.outofmemory.cn/imgr?</p><p>src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_742d6853edfafaca8ffd726cd8457162.gif)
![q_i](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_da326f7200e158a864695985b2e2f095.gif)
![p_u](http://ju.outofmemory.cn/imgr?</p><p>src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_742d6853edfafaca8ffd726cd8457162.gif)
![q_i](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_da326f7200e158a864695985b2e2f095.gif)
通常SGD都会比ALS要简单并且高速, 可是ALS的并行性比較好, 并且能够较好地处理稀疏数据(?).
3. 加入偏置项
矩阵分解方法的一个优点就是能够灵活的加入很多面向应用的要求. 比方, 通常来说, 不同用户的评分倾向不同, 用的用户的打分普遍较高, 有的普遍较低, 物品亦然. 所以只使用用户和物品之间的交互
![q_i^Tp_u](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_7a534ac88484ac1f592622f6fe569db6.gif)
![b_{ui}=mu+b_i+b_u](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_fecd850b519ac15cb3bda0c112e2a08a.gif)
当中
![mu](http://ju.outofmemory.cn/imgr?</p><p>src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_c9faf6ead2cd2c2187bd943488de1d0a.gif)
![b_u, b_i](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_eeeb6d61b46d64094cf4c7bad7286377.gif)
![mu](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_c9faf6ead2cd2c2187bd943488de1d0a.gif)
评分模型为:
![hat{r_{ui}}=mu + b_i | b_u + q_i^Tp_u](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_18bc3666f4b22add2eaa5c6279c232cd.gif)
转化为最优化问题为:
![min_{pcdot,qcdot,bcdot}sum_{(u,i)inmathcal{k}}(r_{ui}-mu-b_u-b_i-p_u^Tq_i)^2 + lambda(|p_u|^2 + |q_i|^2 +b_u^2+ b_i^2)](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_04d35408c8fb1aba54eece2afa180dce.gif)
4. 其它的输入源
当解决冷启动问题时, 用户的评分信息非常少, 这时候就须要使用用户的其它输入信息, 比方用户隐式反馈(浏览, 购买历史等). 令
![N(u)](http://www.kemaswill.com/wp-content/plugins/latex/cache/tex_23fbad0b76c3b2886b8395fdb3dccc1f.gif)
![x_iinmathbb{R}^f](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_d9547dcec4fcaa6c780932f025f976a3.gif)
![sum_{iin N(u)}x_i](http://ju.outofmemory.cn/imgr?</p><p>src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_4fad5c905d6e355f3daafbffab7a00e7.gif)
能够对上式进行正则化:
![|N(u)|^{-0.5}sum_{iin N(u)}x_i](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_911ec8c0604bc13af71e7b589e04e365.gif)
也能够使用用户的一些其它属性(性别, 年龄, 收入等)来对用户建模, 令
![A_u](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_068c4dbb106c87186d1f4c4ed052a676.gif)
![y_{a}inmathbb{R}^f](http://ju.outofmemory.cn/imgr?</p><p>src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_b4909aca77fa13d86bd9c656a752ae26.gif)
![sum_{ain A(u)}y_a](http://ju.outofmemory.cn/imgr?</p><p>src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_736d555e98da6d653ec58b60b91f5af2.gif)
用户对物品的评分能够表示为:
![hat{r_{ui}}=mu + b_i | b_u + q_i^T[p_u + |N(u)|^{-0.5}sum_{iin N(u)}x_i +sum_{ain A(u)}y_a]](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_23f02ffc32483e5eb712707ff785a043.gif)
5. 时间因素
到如今为止, 模型是静态的, 可是实际中物品的流行程度会随着时间变化, 用户的评分倾向也会变化, 用户的隐向量也会随时间变化. 所以能够将这些变量表示成时间的函数来更好地描写叙述这些现象:
![hat{r}_{ui}=mu + b_i(t) + b_u(t) + q_i^Tp_u(t)](http://ju.outofmemory.cn/imgr?src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_686c0f90c139cee061b24d0722820dcf.gif)
6. 不同可信度的输入源
不同的评分的可信度不同. 比方广告会影响某个物品的评分, 另外, 有些作弊的用户会对某些物品恶意的打高分或者低分. 另外, 在使用隐式反馈时, 能够使用某些行为(比方浏览)等得次数来表示用户喜欢某个物品的程度. 能够通过为某个评分
![r_{ui}](http://www.kemaswill.com/wp-content/plugins/latex/cache/tex_438724a7e9ceb5e49f4bcf45653d74e1.gif)
![c_{ui}](http://ju.outofmemory.cn/imgr?</p><p>src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_270d4ef6cdf478a3db35dac0ffe6014e.gif)
![min_{pcdot,qcdot,bcdot}sum_{(u,i)inmathcal{k}}(c_{ui}(r_{ui}-mu-b_u-b_i-p_u^Tq_i)^2 + lambda(|p_u|^2 + |q_i|^2 +b_u^2+ b_i^2)](http://ju.outofmemory.cn/imgr?</p><p>src=http%3A%2F%2Fwww.kemaswill.com%2Fwp-content%2Fplugins%2Flatex%2Fcache%2Ftex_abe5557497eb4023e0211116028b4b6a.gif)
參考文献:
[1]. Yuhuda Koren, Robert Bell and Chris Volinsky. Matrix Factorization Techniques for Recommender Systems.