线性回归练习

跟着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 线性回归练习的更多相关文章

  1. deep learning 练习 多变量线性回归

    多变量线性回归(Multivariate Linear Regression) 作业来自链接:http://openclassroom.stanford.edu/MainFolder/Document ...

  2. Top Deep Learning Projects in github

    Top Deep Learning Projects A list of popular github projects related to deep learning (ranked by sta ...

  3. Deep Learning 6_深度学习UFLDL教程:Softmax Regression_Exercise(斯坦福大学深度学习教程)

    前言 练习内容:Exercise:Softmax Regression.完成MNIST手写数字数据库中手写数字的识别,即:用6万个已标注数据(即:6万张28*28的图像块(patches)),作训练数 ...

  4. 机器学习(Machine Learning)&深度学习(Deep Learning)资料【转】

    转自:机器学习(Machine Learning)&深度学习(Deep Learning)资料 <Brief History of Machine Learning> 介绍:这是一 ...

  5. Deep Learning and Shallow Learning

    Deep Learning and Shallow Learning 由于 Deep Learning 现在如火如荼的势头,在各种领域逐渐占据 state-of-the-art 的地位,上个学期在一门 ...

  6. 深度学习 Deep Learning UFLDL 最新 Tutorial 学习笔记 1:Linear Regression

    1 前言 Andrew Ng的UFLDL在2014年9月底更新了. 对于開始研究Deep Learning的童鞋们来说这真的是极大的好消息! 新的Tutorial相比旧的Tutorial添加了Conv ...

  7. 转载 Deep learning:三(Multivariance Linear Regression练习)

    前言: 本文主要是来练习多变量线性回归问题(其实本文也就3个变量),参考资料见网页:http://openclassroom.stanford.edu/MainFolder/DocumentPage. ...

  8. 转载 Deep learning:六(regularized logistic回归练习)

    前言: 在上一讲Deep learning:五(regularized线性回归练习)中已经介绍了regularization项在线性回归问题中的应用,这节主要是练习regularization项在lo ...

  9. (1)Deep Learning之感知器

    What is deep learning? 在人工智能领域,有一个方法叫机器学习.在机器学习这个方法里,有一类算法叫神经网络.神经网络如下图所示: 上图中每个圆圈都是一个神经元,每条线表示神经元之间 ...

随机推荐

  1. C# 将对象保存为文件 读取文件并转为对象 压缩文件 解压缩文件

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...

  2. LaTeX_fleqn参数时,多行公式对齐居中的同时选择性的加编号

    [转载请注明出处]http://www.cnblogs.com/mashiqi 2016/10/20 一年多没写博文了.今天写一个短的,记录一下使用LaTeX的一些经验. 有些时候,我们的latex文 ...

  3. Koala-Sass编译

    1.安装: 下载地址:http://koala-app.com/ 安装好了之后,打开界面如下: 2.简单配置: 打开设置: 3.设置中文: 打开安装目录下的文件:C:\Program Files (x ...

  4. Sqoop使用手册

    转载请注明出处:http://www.cnblogs.com/xiaodf/ 1 Sqoop概述 2 版本说明 3 驱动安装 3.1 MySQL 4 基本用法 4.1 导入 4.1.1 保护密码 4. ...

  5. PHP实现发红包程序

    我们先来分析下规律. 设定总金额为10元,有N个人随机领取: N=1 第一个 则红包金额=X元: N=2 第二个 为保证第二个红包可以正常发出,第一个红包金额=0.01至9.99之间的某个随机数. 第 ...

  6. 系统弹性概念[TODO]

    系统弹性 Shopify构建分布式可扩展应用的最佳实践 [编者的话]在构建大型分布式系统应用时,如何降低不同部分之间的依赖,增强系统的弹性,电商解决方案提供商 Shopify 给出了解决方法. 弹性矩 ...

  7. JS对象实现随机满天小星星实例

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. Qt4编码

    #if QT_VERSION < 0x050000 qDebug() << "qt5以下的版本, 从QTextCodec设置全局字符集"; QTextCodec* ...

  9. Java操作redis简单示例

    第一:安装Redis    首先我们要安装Redis,就像我们操作数据库一样,在操作之前肯定要先创建好数据库的环境.    Redis的下载可以百度一下,或者打开下面的下载链接:    https:/ ...

  10. HTML学习-日常问题-1

    最近入了Html的坑 所以开始了学习前端的漫长道路 所以打算将日常遇到的小问题记录下来 1.关于img自适应的问题 <div class="main"> <div ...