机器学习-推荐系统

以推荐电影为例

symbol

17symbol

基于内容的推荐算法

根据电影内容找到用户特征θ 本质上利用线性回归

其中 Σi:r(i,j) = 1是指 将所有电影 i 的用户评分累加起来

最小化θ

梯度下降-优化θ

协同过滤(collaborative filtering)及算法

不再根据电影内容,而是直接根据用户评分得到电影特征

其中 Σj:r(i,j) = 1是指 将用户 j 评分过所有电影的分值累加起来

没有 X_0 , θ_0

同时学习几乎所有电影的特征和所有用户参数 ,最终预测所有用户对未评价电影的评分

17综合协同

17算法流程

矢量化:低秩矩阵分解

17低秩矩阵分解

电影相似度

17特征相似度计算

实施细节

均值规范化(防止全未评分用户预测全0)

重新对均值进行协同过滤

17均值规范化

编程作业

cofiCostFunc.m

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function [J, grad] = cofiCostFunc(params, Y, R, num_users, num_movies, ...
num_features, lambda)
%COFICOSTFUNC Collaborative filtering cost function
% [J, grad] = COFICOSTFUNC(params, Y, R, num_users, num_movies, ...
% num_features, lambda) returns the cost and gradient for the
% collaborative filtering problem.
%

% Unfold the U and W matrices from params
X = reshape(params(1:num_movies*num_features), num_movies, num_features);
Theta = reshape(params(num_movies*num_features+1:end), ...
num_users, num_features);


% You need to return the following values correctly
J = 0;
X_grad = zeros(size(X));
Theta_grad = zeros(size(Theta));

% ====================== YOUR CODE HERE ======================
% Instructions: Compute the cost function and gradient for collaborative
% filtering. Concretely, you should first implement the cost
% function (without regularization) and make sure it is
% matches our costs. After that, you should implement the
% gradient and use the checkCostFunction routine to check
% that the gradient is correct. Finally, you should implement
% regularization.
%
% Notes: X - num_movies x num_features matrix of movie features
% Theta - num_users x num_features matrix of user features
% Y - num_movies x num_users matrix of user ratings of movies
% R - num_movies x num_users matrix, where R(i, j) = 1 if the
% i-th movie was rated by the j-th user
%
% You should set the following variables correctly:
%
% X_grad - num_movies x num_features matrix, containing the
% partial derivatives w.r.t. to each element of X
% Theta_grad - num_users x num_features matrix, containing the
% partial derivatives w.r.t. to each element of Theta
%

J = sum(sum(((X*Theta' - Y).^2) .* R)) / 2 + lambda/2*(sum(sum(Theta.^2)) + sum(sum(X.^2)));
X_grad = ((X*Theta' - Y).* R) * Theta + lambda * X;
Theta_grad = ((X*Theta' - Y).* R)' * X+ lambda * Theta;

% =============================================================

grad = [X_grad(:); Theta_grad(:)];

end
---------------- 本文结束 ----------------

本文标题:机器学习-推荐系统

文章作者:Pabebe

发布时间:2019年08月07日 - 19:51:38

最后更新:2020年06月16日 - 18:24:34

原始链接:https://pabebezz.github.io/article/e1151c0b/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

0%