deep learning 练习1 线性回归练习
线性回归练习
跟着Andrew Ng做做练习:http://openclassroom.stanford.edu/MainFolder/DocumentPage.php?course=DeepLearning&doc=exercises/ex2/ex2.html
这一小节做线性回归的小练习,数据摘自上面的网站,其中X是小男孩身高,Y是小男孩年龄,数据集包括50组训练数据。
1,预处理
通过 x = load('ex2x.dat');
y = load('ex2y.dat');
加载数据;
然后生成X的单位向量
m = length(y); % store the number of training examples
x = [ones(m, 1), x]; % Add a column of ones to x
2,线性回归
线性回归模型为

参数批量更新规则为

其中学习速率设置为α=0.07,参数初始化为0;
然后开始迭代,直到theta收敛。
由于这个东西十分简单,现直接贴代码如下
clc
clear all;
close all;
x = load('ex2x.dat');
y = load('ex2y.dat'); figure % open a new figure window
plot(x, y, 'o');%离散点
ylabel('Height in meters')
xlabel('Age in years') m = length(y); % store the number of training examples
x = [ones(m, ) x]; % Add a column of ones to x----这个是由于f(x)=w'*X+b可以转化为f(x)=[X,1]*[w';b]
a=0.07;
theta = zeros(size(x(,:)))'; %参数包括两个,k,,,,b for i=:
theta=theta-a./m.*x'*(x*theta-y);%批量梯度下降
end
hold on % Plot new data without clearing old plot
plot(x(:,), x*theta, '-') % remember that x is now a matrix with columns
% and the second column contains the time info
legend('Training data', 'Linear regression')
deep learning 练习1 线性回归练习的更多相关文章
- deep learning 练习 多变量线性回归
多变量线性回归(Multivariate Linear Regression) 作业来自链接:http://openclassroom.stanford.edu/MainFolder/Document ...
- Top Deep Learning Projects in github
Top Deep Learning Projects A list of popular github projects related to deep learning (ranked by sta ...
- Deep Learning 6_深度学习UFLDL教程:Softmax Regression_Exercise(斯坦福大学深度学习教程)
前言 练习内容:Exercise:Softmax Regression.完成MNIST手写数字数据库中手写数字的识别,即:用6万个已标注数据(即:6万张28*28的图像块(patches)),作训练数 ...
- 机器学习(Machine Learning)&深度学习(Deep Learning)资料【转】
转自:机器学习(Machine Learning)&深度学习(Deep Learning)资料 <Brief History of Machine Learning> 介绍:这是一 ...
- Deep Learning and Shallow Learning
Deep Learning and Shallow Learning 由于 Deep Learning 现在如火如荼的势头,在各种领域逐渐占据 state-of-the-art 的地位,上个学期在一门 ...
- 深度学习 Deep Learning UFLDL 最新 Tutorial 学习笔记 1:Linear Regression
1 前言 Andrew Ng的UFLDL在2014年9月底更新了. 对于開始研究Deep Learning的童鞋们来说这真的是极大的好消息! 新的Tutorial相比旧的Tutorial添加了Conv ...
- 转载 Deep learning:三(Multivariance Linear Regression练习)
前言: 本文主要是来练习多变量线性回归问题(其实本文也就3个变量),参考资料见网页:http://openclassroom.stanford.edu/MainFolder/DocumentPage. ...
- 转载 Deep learning:六(regularized logistic回归练习)
前言: 在上一讲Deep learning:五(regularized线性回归练习)中已经介绍了regularization项在线性回归问题中的应用,这节主要是练习regularization项在lo ...
- (1)Deep Learning之感知器
What is deep learning? 在人工智能领域,有一个方法叫机器学习.在机器学习这个方法里,有一类算法叫神经网络.神经网络如下图所示: 上图中每个圆圈都是一个神经元,每条线表示神经元之间 ...
随机推荐
- Unity3D–RectTransfrom 记录笔记
一.基本要点 部分来源:http://www.2fz1.com/post/unity-ugui-recttransform/ RectTransform继承于Trasnfrom , 在Trasnfor ...
- python数据结构
. 数据结构¶ .1. 深入列表¶ 链表类型有很多方法,这里是链表类型的所有方法: list.append(x) 把一个元素添加到链表的结尾,相当于 a[len(a):] = [x] . list ...
- 基于Maven site的穷人的本地知识管理系统
1 Motivation On daily study or development, a simple knowledge management system is required. In the ...
- linux5个搜索命令
概要 linux中主要有5个文件查找命令:find.locate.whereis.which.type.find最为强大,但耗时较长.locate可看做find的精简版,但是它的速度非常快.where ...
- JSWindow对象
Window 对象 Window 对象表示浏览器中打开的窗口. 如果文档包含框架(frame 或 iframe 标签),浏览器会为 HTML 文档创建一个 window 对象,并为每个框架创建一个额外 ...
- Java和C++的虚函数的异同
参考博客:点我 要点:Java中的普通函数默认为虚函数,因此动态绑定的行为是默认的,而C++必须将方法声明为虚函数(virtual关键字),执行时才会进行动态绑定,详细区别可参考代码以及注释. 代码大 ...
- ListView的item里面控件文本颜色修改
@SuppressLint("InflateParams") @Override public View getChildView(int groupPosition, int c ...
- SSH开源框架的优缺点
js+servlet+javabean的开发模式需要写很多的重复代码,比如固定的doGet()方法,而且它的控制跳转不灵活,往往一个问题处理需要两个.java文件,而且当采用MVC模式开发时有很大的耦 ...
- SHOI 2009 会场预约 平衡树 STL练习
题目描述 PP大厦有一间空的礼堂,可以为企业或者单位提供会议场地.这些会议中的大多数都需要连续几天的时间(个别的可能只需要一天),不过场地只有一个,所以不同的会议的时间申请不能够冲突.也就是说,前一个 ...
- MyFirstgame 拼图
package auto; /** * IDA*求解15puzzle问题 * IDA*整合了IDDFS和A*算法.其中IDDFS控制了求解过程中的内存开销,A*算法意味着"启发式" ...