Machine Learning Week3
来源:互联网 发布:linux查看文件目录命令 编辑:程序博客网 时间:2024/06/05 08:29
week3的主要内容并不算很多,其实相对于week2,主要是修改了h函数,变成了sigmoid,而不是原来的向量乘法。
不过我觉得有两点需要注意,第一点就是fminunc函数,这个函数接受options作为设置,然后结构initial_theta作为优化的theta参数,之后是一个句柄(不知道是不是这么叫),会通过这个函数计算loss和梯度grad。返回值的loss,grad,我想grad用来更新了,loss用来判断了。
第二点就是在正则化的时候,bias不去平方,也不去正则化的更新。
function [J, grad] = costFunctionReg(theta, X, y, lambda)%COSTFUNCTIONREG Compute cost and gradient for logistic regression with regularization% J = COSTFUNCTIONREG(theta, X, y, lambda) computes the cost of using% theta as the parameter for regularized logistic regression and the% gradient of the cost w.r.t. to the parameters. % Initialize some useful valuesm = length(y); % number of training examples% You need to return the following variables correctly J = 0;grad = zeros(size(theta));% ====================== YOUR CODE HERE ======================% Instructions: Compute the cost of a particular choice of theta.% You should set J to the cost.% Compute the partial derivatives and set grad to the partial% derivatives of the cost w.r.t. each parameter in thetah = sigmoid(X * theta);J = sum(-y .* log(h) - (1-y).*log(1-h))/(m) + sum(theta(2:end).^2)*lambda/(2*m);deltaGrad = zeros(size(theta));deltaGrad = X' * (h-y) /m;deltaGrad(2:end) = deltaGrad(2:end) + lambda*theta(2:end)/m;grad = deltaGrad;% =============================================================end
0 0
- Machine Learning week3
- Machine Learning Week3
- Machine Learning-Andrew Ng-week3
- Machine Learning(Andrew)Week3(上)
- Machine Learning(Andrew)Week3(下)
- coursera Machine Learning Week3-1 学习笔记
- coursera Machine Learning Week3-2 学习笔记
- Coursera Machine Learning Week3 学习笔记
- 【Coursera Machine Learning】 Week3 学习笔记
- Coursera Machine Learning 作业代码 week3
- Andrew Ng的machine learning课程week3编程题python实现
- Coursera Machine Learning ex2第三周 week3编程全套满分题目+注释(包括选做optional)
- coursera deep learning course2 week3
- coursera deep learning course4 week3
- machine learning
- Machine Learning
- machine learning
- Machine Learning
- NSIS卸载后无法删除开始菜单中的内容
- 矩阵的求逆
- 分布式调用跟踪系统的设计和应用学习
- 大数据集群环境搭建
- 自定义ViewPagerIndictor
- Machine Learning Week3
- laravel路由组划分
- 【整理】JS中的History对象
- Delphi Project 之工程选项(Project Options)
- Android 动画之RotateAnimation应用详解
- JAVA SOCKET connect超时设置是如何实现的?
- 日间模式转换夜间模式
- 【电脑技术】:电脑黑屏的情况统计
- ovs bond选项情况