原
吴恩达机器学习 - 推荐系统
2018年06月25日 22:26:51
离殇灬孤狼
阅读数:187
</div>
<div class="operating">
</div>
</div>
</div>
</div>
<article>
<div id="article_content" class="article_content clearfix csdn-tracking-statistics" data-pid="blog" data-mod="popu_307" data-dsm="post" style="height: 2070px; overflow: hidden;">
<div class="article-copyright">
版权声明:如果感觉写的不错,转载标明出处链接哦~blog.csdn.net/wyg1997 https://blog.csdn.net/wyg1997/article/details/80808388 </div>
<div class="markdown_views">
<!-- flowchart 箭头图标 勿删 -->
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;"><path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path></svg>
<p>题目链接:<a href="https://s3.amazonaws.com/spark-public/ml/exercises/on-demand/machine-learning-ex8.zip" rel="nofollow" target="_blank">点击打开链接</a></p>
笔记:
每个算法最重要的莫过于代价函数了:
公式:
求代价:
求梯度:
Code(cofiCostFunc.m):
function [J, grad] = cofiCostFunc(params, Y, R, num_users, num_movies, ...
num_features, lambda)
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);
J =
0;
X_grad =
zeros(
size(X));
Theta_grad =
zeros(
size(Theta));
J = sum(sum((
R.*(X*
Theta')-Y).^
2))/
2.0 + ...
lambda/
2.0*sum(sum(
Theta.^
2)) + lambda/
2.0*sum(sum(
X.^
2));
X_grad = (
R.*(X*
Theta')-Y)*Theta +
lambda.*X;
Theta_grad = (
R.*(X*
Theta')-Y)
'*X + lambda.*Theta;
% =============================================================
grad = [X_grad(:); Theta_grad(:)];
end
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
最后给了一个推荐电影的例子,用笔记上的流程就行啦。
阅读更多