这学期一直在跟进 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的更多相关文章

  1. Andrew Ng 的 Machine Learning 课程学习 (week3) Logistic Regression

    这学期一直在跟进 Coursera上的 Machina Learning 公开课, 老师Andrew Ng是coursera的创始人之一,Machine Learning方面的大牛.这门课程对想要了解 ...

  2. Andrew Ng 的 Machine Learning 课程学习 (week5) Neural Network Learning

    这学期一直在跟进 Coursera上的 Machina Learning 公开课, 老师Andrew Ng是coursera的创始人之一,Machine Learning方面的大牛.这门课程对想要了解 ...

  3. Andrew Ng 的 Machine Learning 课程学习 (week4) Multi-class Classification and Neural Networks

    这学期一直在跟进 Coursera上的 Machina Learning 公开课, 老师Andrew Ng是coursera的创始人之一,Machine Learning方面的大牛.这门课程对想要了解 ...

  4. matlab基础教程——根据Andrew Ng的machine learning整理

    matlab基础教程--根据Andrew Ng的machine learning整理 基本运算 算数运算 逻辑运算 格式化输出 小数位全局修改 向量和矩阵运算 矩阵操作 申明一个矩阵或向量 快速建立一 ...

  5. machine learning(14) --Regularization:Regularized linear regression

    machine learning(13) --Regularization:Regularized linear regression Gradient descent without regular ...

  6. Logistic回归Cost函数和J(θ)的推导----Andrew Ng【machine learning】公开课

    最近翻Peter Harrington的<机器学习实战>,看到Logistic回归那一章有点小的疑问. 作者在简单介绍Logistic回归的原理后,立即给出了梯度上升算法的code:从算法 ...

  7. [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 ...

  8. Machine Learning - week 2 - Multivariate Linear Regression

    Multiple Features 上一章中,hθ(x) = θ0 + θ1x,表示只有一个 feature.现在,有多个 features,所以 hθ(x) = θ0 + θ1x1 + θ2x2 + ...

  9. [Machine Learning] 单变量线性回归(Linear Regression with One Variable) - 线性回归-代价函数-梯度下降法-学习率

    单变量线性回归(Linear Regression with One Variable) 什么是线性回归?线性回归是利用数理统计中回归分析,来确定两种或两种以上变量间相互依赖的定量关系的一种统计分析方 ...

随机推荐

  1. 2019-RHCE-红帽题库(稳定)

    rhce7 考题2台服务器设置yum源[aa]name=aabaesurl=ftp://server.rhce.cc/dvdenabled=1gpgcheck=0 cd /etc/yum.repos. ...

  2. 分层最短路-2018南京网赛L

    大概题意: 题意:N个点,M条带权有向边,求将K条边权值变为0的情况下,从点1到点N的最短路. 拓展:可以改变K条边的权值为x 做法:把每个点拆成k个点,分别表示还能使用多少次机会,构造新图. 实际写 ...

  3. 算法训练 最大的算式(DP)

    问题描述 题目很简单,给出N个数字,不改变它们的相对位置,在中间加入K个乘号和N-K-1个加号,(括号随便加)使最终结果尽量大.因为乘号和加号一共就是N-1个了,所以恰好每两个相邻数字之间都有一个符号 ...

  4. 我的iphone不能被虚拟机识别怎么办

    我的iphone不能被虚拟机识别怎么办 听语音 | 浏览:3890 | 更新:2015-11-04 15:28 | 标签:iphone vmware ios 1 2 3 4 5 6 分步阅读 特大喜讯 ...

  5. 转载 【Linux】Linux中常用操作命令

    [Linux]Linux中常用操作命令     https://www.cnblogs.com/laov/p/3541414.html#vim   Linux简介及Ubuntu安装 常见指令 系统管理 ...

  6. P4338 [ZJOI2018]历史 LCT+树形DP

    \(\color{#0066ff}{ 题目描述 }\) 这个世界有 n 个城市,这 n 个城市被恰好 \(n-1\) 条双向道路联通,即任意两个城市都可以 互相到达.同时城市 1 坐落在世界的中心,占 ...

  7. angularJs条件查询:

    首先需要建立一个输入框进行数据绑定: <div class="box-tools pull-right"> <div class="has-feedba ...

  8. org.json里实现XML和JSON之间对象互转

    org.json包里有一个类org.json.XML可以实现XML和JSON之间的转换.http://www.json.org/javadoc/org/json/XML.html JSONObject ...

  9. HDU-Big Number (斯特林公式)

    In many applications very large integers numbers are required. Some of these applications are using ...

  10. HDU1398 Square Coins

    Description People in Silverland use square coins. Not only they have square shapes but also their v ...