Andrew Ng 的 Machine Learning 课程学习 (week2) Linear Regression
这学期一直在跟进 Coursera上的 Machina Learning 公开课, 老师Andrew Ng是coursera的创始人之一,Machine Learning方面的大牛。这门课程对想要了解和初步掌握机器学习的人来说是不二的选择。这门课程涵盖了机器学习的一些基本概念和方法,同时这门课程的编程作业对于掌握这些概念和方法起到了巨大的作用。
课程地址 https://www.coursera.org/learn/machine-learning
笔记主要是简要记录下课程内容,以及MATLAB编程作业....
Regression
回归,属于有监督学习中的一种方法。该方法的核心思想是从离散的统计数据中得到数学模型,然后将该数学模型用于预测或者分类。该方法处理的数据可以是多维的。课程最初介绍了一个房屋价格的基本问题,然后引出了线性回归的解决方法,然后针对误差问题做了概率解释。
与 Classification 的区别
Regression: to predict the continuous valued output.
Classification: to predict the discrete valued output.
Costfuntion
求最小值,局部最优或者全局最优

Grdient Descent
在选定线性回归模型后,只需要确定参数 θ,就可以将模型用来预测。然而 θ 需要在 J(θ)最小的情况下才能确定。因此问题归结为求极小值问题,使用梯度下降法。梯度下降法最大的问题是求得有可能是全局极小值,这与初始点的选取有关。
梯度下降法是按下面的流程进行的:
1)首先对 θ 赋值,这个值可以是随机的,也可以让 θ 是一个全零的向量。
2)改变 θ 的值,使得 J(θ)按梯度下降的方向进行减少。
梯度方向由 J(θ)对 θ 的偏导数确定,由于求的是极小值,因此梯度方向是偏导数的反方向。结果为

对于本章(week2)的编程作业题如下:
Week2 任务: Linear Regression
computeCost.m
function J = computeCost(X, y, theta) % Initialize some useful values
m = length(y); % number of training examples % You need to return the following variables correctly
J = ; % ====================== YOUR CODE HERE ======================
% Instructions: Compute the cost of a particular choice of theta
% You should set J to the cost. h = X * theta;
E = h - y;
J = / (*m) * E' * E; % ============================================================
end
gradientDescent.m
function [theta, J_history] = gradientDescent(X, y, theta, alpha, num_iters) % Initialize some useful values
m = length(y); % number of training examples
J_history = zeros(num_iters, );
for iter = :num_iters % ====================== YOUR CODE HERE ======================
% Instructions: Perform a single gradient step on the parameter vector
% theta.
%
% Hint: While debugging, it can be useful to print out the values
% of the cost function (computeCost) and gradient here.
%
h = X * theta;
E = h - y;
theta = theta - alpha / m * X' * E; % ========================================================= % Save the cost J in every iteration
J_history(iter) = computeCost(X, y, theta);
end
end
computeCostMulti.m
h = X * theta;
E = h - y;
J = / (*m) * E' * E;
gradientDescentMulti.m
h = X * theta;
E = h - y;
theta = theta - alpha / m * X' * E;
Andrew Ng 的 Machine Learning 课程学习 (week2) Linear Regression的更多相关文章
- Andrew Ng 的 Machine Learning 课程学习 (week3) Logistic Regression
这学期一直在跟进 Coursera上的 Machina Learning 公开课, 老师Andrew Ng是coursera的创始人之一,Machine Learning方面的大牛.这门课程对想要了解 ...
- Andrew Ng 的 Machine Learning 课程学习 (week5) Neural Network Learning
这学期一直在跟进 Coursera上的 Machina Learning 公开课, 老师Andrew Ng是coursera的创始人之一,Machine Learning方面的大牛.这门课程对想要了解 ...
- Andrew Ng 的 Machine Learning 课程学习 (week4) Multi-class Classification and Neural Networks
这学期一直在跟进 Coursera上的 Machina Learning 公开课, 老师Andrew Ng是coursera的创始人之一,Machine Learning方面的大牛.这门课程对想要了解 ...
- matlab基础教程——根据Andrew Ng的machine learning整理
matlab基础教程--根据Andrew Ng的machine learning整理 基本运算 算数运算 逻辑运算 格式化输出 小数位全局修改 向量和矩阵运算 矩阵操作 申明一个矩阵或向量 快速建立一 ...
- machine learning(14) --Regularization:Regularized linear regression
machine learning(13) --Regularization:Regularized linear regression Gradient descent without regular ...
- Logistic回归Cost函数和J(θ)的推导----Andrew Ng【machine learning】公开课
最近翻Peter Harrington的<机器学习实战>,看到Logistic回归那一章有点小的疑问. 作者在简单介绍Logistic回归的原理后,立即给出了梯度上升算法的code:从算法 ...
- [C5] Andrew Ng - Structuring Machine Learning Projects
About this Course You will learn how to build a successful machine learning project. If you aspire t ...
- Machine Learning - week 2 - Multivariate Linear Regression
Multiple Features 上一章中,hθ(x) = θ0 + θ1x,表示只有一个 feature.现在,有多个 features,所以 hθ(x) = θ0 + θ1x1 + θ2x2 + ...
- [Machine Learning] 单变量线性回归(Linear Regression with One Variable) - 线性回归-代价函数-梯度下降法-学习率
单变量线性回归(Linear Regression with One Variable) 什么是线性回归?线性回归是利用数理统计中回归分析,来确定两种或两种以上变量间相互依赖的定量关系的一种统计分析方 ...
随机推荐
- C#根据弹窗标题获取窗体句柄并模拟点击按钮(FindWindow,FindWindowEx,SendMessage)
任务:将下面弹窗自动关闭 /// <summary> /// 找到窗口 /// </summary> /// <param name="lpClassName& ...
- Delphi和C#数据类型对应表
Delphi DataType C# datatype ansistring string boolean bool byte byte char char comp double currency ...
- c# 生成xml,xsi不能生成问题
C# 生成xml,xsi不能生成问题 一.简单了解xsi及其其他属性: xsi:schemaLocation用于声明了目标名称空间的模式文档,属性的值由一个URI引用对组成,两个URI之间以空白符分 ...
- Ubuntu小记
一. Ubuntu分区记忆 参考教程调整: 1. /boot用于安装grub,设为主分区 2. /根目录20G一般足够 3. /home剩下的给home 4. swap空间=物理内存 挂载点 大小 类 ...
- ajaxs
AJAX 是一种独立于 Web 服务器软件的浏览器技术.AJAX 基于下列 Web 标准:JavaScript XML HTML CSS 在 AJAX 中使用的 Web 标准已被良好定义,并被所有的主 ...
- CUDA中自动初始化显卡设备宏
每次为了减少初始化的工作量,可以写入下面的宏. #define CUT_DEVICE_INIT(ARGC,ARGV){ \ int deviceCount; \ CUDA_SAFE_CALL_NO_S ...
- 小程序不在以下 request 合法域名列表中
我们如果是正式上线可以在小程序后台配置合法域名,必须是https 测试时我们可以关闭验证 在 设置 - 项目设置 里勾选不校验https 和 TLS
- ubuntu 16 64位编译安装php
./configure \ --prefix=/usr/local/php7 \ --exec-prefix=/usr/local/php7 \ --with-config-file-path=/us ...
- lintcode - 被围绕的区域
class Solution { public: /* * @param board: board a 2D board containing 'X' and 'O' * @return: nothi ...
- Go语言基础之12--Channel
一.不同goroutine之间如何进行通讯? 1.全局变量和锁同步 缺点:多个goroutine要通信时,定义太多的全局变量(每个全局变量功能不一样),不好维护 2.Channel 二.channel ...