ufldl学习笔记与编程作业:Linear Regression(线性回归)

来源:互联网 发布:易语言打码源码 编辑:程序博客网 时间:2024/05/21 08:01

接下来准备系统的学习一下deep learning课程,一方面是现在学校暑期课程刚好选到,另一方面也是掌握一个现在的热门技能。
UFLDL是斯坦福大学吴恩达(Andrew Ng)教授主编的深度学习资料《Unsupervised Feature Learning and Deep Learning》(2014年新版)的简称,今天学习的是第一课:Linear Regression。
线性回归概念很好理解,主要问题来自于编程作业:

Complete the following steps for this exercise: Fill in the linear_regression.m file to compute J(θ)J(θ) for the linear regression problem as defined earlier. Store the computed value in the variable. You may complete both of these steps by looping over the examples in the training set (the columns of the data matrix X) and, for each one, adding its contribution to f and g. We will create a faster version in the next exercise.
简单来说,这个实验里,你只需要按照公式给出代价函数f的代码和梯度函数g的代码,剩下的Function Minimization的过程已经由资料里的minfunc函数实现了。
从一个最简单的线性回归,可以很清晰地看出建模解决问题的一般思路。
1 定义目标函数;
2 最优化目标函数:求偏导数,求梯度。通过最优化的手段,比如梯度下降,拟牛顿发等。求出最优解。

  f=0;    g=zeros(size(theta));    h = theta' * X;    f = (1/2)*h*h';  g = X*((h-y)');  
 h = theta' * X;   diff=h-y;  f=sum(diff.*diff)/2; g = X*((h-y)');%教程公式里已经给出求出梯度后的公式,这里直接使用即可。
阅读全文
0 0
原创粉丝点击