这学期一直在跟进 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. 使用metasploit进行栈溢出攻击-5

    我们先尝试使用这个脚本进行攻击: msf > use exploit/linux/myvictim msf exploit(myvictim) > set payload linux/x8 ...

  2. Educational Codeforces Round 60 (Rated for Div. 2)D(思维,DP,快速幂)

    #include <bits/stdc++.h>using namespace std;const long long mod = 1e9+7;unordered_map<long ...

  3. rest framework认证组件和django自带csrf组件区别详解

    使用 Django 中的 csrf 处理 Django中有一个django.middleware.csrf.CsrfViewMiddleware中间件提供了全局的csrf检查.它的原理是在<fo ...

  4. Oracle中With As 、Group By 语法

    比如有下面三张表,用With as  .Group By语法解决几个问题; with as :  可以用来创建临时表,作为过度的表: group by:   按照某个字段来分类: 对应字段如下: Sa ...

  5. 8、OpenCV Python 图像直方图

    __author__ = "WSX" import cv2 as cv import numpy as np from matplotlib import pyplot as pl ...

  6. 模板【洛谷P3390】 【模板】矩阵快速幂

    P3390 [模板]矩阵快速幂 题目描述 给定n*n的矩阵A,求A^k 矩阵A的大小为n×m,B的大小为n×k,设C=A×B 则\(C_{i,j}=\sum\limits_{k=1}^{n}A_{i, ...

  7. luogu2480 [SDOI2010]古代猪文

    link 题意一开始没TM读懂... 就是给定一个\(G\le10^{10},N\le10^9\),求\(G^{\sum_{d|n}{n\choose d}}\),对999911659取模 由于999 ...

  8. Ubuntu server 修改系统时区

    执行命令: sudo dpkg-reconfigure tzdata

  9. 经典SQL行列转换

    -- http://www.programbbs.com/doc/4885.htm /* 标题:普通行列转换(version 2.0) 说明:普通行列转换(version 1.0)仅针对sql ser ...

  10. vue(3)IDE

    使用vscode,下载:https://code.visualstudio.com/Download 1.安装vscode 2.安装插件 方式一:https://marketplace.visuals ...