线性回归练习

跟着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. (原创)基于CloudStack的平安云-云主机的生命周期

    一.购买云主机1.条件筛选   涉及环境.应用系统.区域.网络.操作系统.套餐.期限.数量筛选2.校验   2.1 应用系统角色权限校验   2.2 应用系统可用配置校验   2.3 产品区域是否下架 ...

  2. 十分钟了解分布式计算:Spark

    Spark是一个通用的分布式内存计算框架,本文主要研讨Spark的核心数据结构RDD的设计思路,及其在内存上的容错.内容基于论文 Zaharia, Matei, et al. "Resili ...

  3. RNN 入门学习资料整理

    建议按序阅读 1. RNN的一些简单概念介绍 A guide to recurrent neural networks and backpropagation Deep learning:四十九(RN ...

  4. 支持向量机 (SVM)分类器原理分析与基本应用

    前言 支持向量机,也即SVM,号称分类算法,甚至机器学习界老大哥.其理论优美,发展相对完善,是非常受到推崇的算法. 本文将讲解的SVM基于一种最流行的实现 - 序列最小优化,也即SMO. 另外还将讲解 ...

  5. CLR via C# 3rd - 05 - Primitive, Reference, and Value Types

    1. Primitive Types        Any data types the compiler directly supports are called primitive types. ...

  6. 用sql语句建表

    CREATE TABLE USER (id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(30) NOT NULL, p ...

  7. js的事件委托

    什么是事件委托:通俗的讲,事件就是onclick,onmouseover,onmouseout,等就是事件,委托呢,就是让别人来做,这个事件本来是加在某些元素上的,然而你却加到别人身上来做,完成这个事 ...

  8. YII2的增删改查

    insert into table (field1,field2)values('1','2');delete from table where   condition update  table s ...

  9. 备忘DES简单加密与解密

    package com.ego.util; import java.io.IOException; import java.security.SecureRandom; import javax.cr ...

  10. Ubuntu下配置Pyspider环境

    Ubuntu 14.04.4 LTS 1.ubuntu 系统自带Python 所以不用安装Python 注:安装前先更新下软件源 命令 :sudo apt-get update 2.开始安装pip 命 ...