[ML of Andrew Ng]Week 1 : Linear Regression with One Variable
2016-03-07 22:50
411 查看
Week 1 Linear Regression with One Variable
Week 1 Linear Regression with One VariableIntroduction
Two definitions of ML
Two types of ML
Prerequisite for this course
Linear Regression with One Variable
The Hypothesis Function
Cost Function
Gradient Descent
Gradient Descent for Linear Regression
Introduction
Two definitions of ML
The field of study that gives computers the ability to learn without being explicitly programmed.A computer program is said to learn from experience E with respect to some class of tasks T and performance measure P, if its performance at tasks in T, as measured by P, improves with experience E.
Two types of ML
Supervised Learning and Unsupervised Learning.The keys of supervised learning are the correct output and labeled examples.
While data in Unsupervised learning has no labels,they are same.We don’t know what to do.
Prerequisite for this course
Knowledge of basic computer science principles and skills, at a level sufficient to write a reasonably non-trivial computer program.Familiarity with the basic probability theory. (CS109 or Stat116 is sufficient but not necessary.)
Familiarity with the basic linear algebra (any one of Math 51, Math 103, Math 113, or CS 205 would be much more than necessary.)
Linear Regression with One Variable
The Hypothesis Function
hθ(x)=θ0+θ1xor:
hθ(x)=θ0x0+θ1x1whichx0=1
PS: x(i)j means the jrd features and ird examples.
we can get the vectors θ and X as:
θ=[θ0θ1] (2×1)
and:
X=⎡⎣⎢⎢⎢⎢⎢11⋮1x(1)x(2)⋮x(m)⎤⎦⎥⎥⎥⎥⎥ (m×2)
So we get the H=Xθ (m×2)×(2×1)=(m×1) like as:
H=⎡⎣⎢⎢⎢⎢⎢hθ(x(1))hθ(x(2))⋮hθ(x(m))⎤⎦⎥⎥⎥⎥⎥ (m×1)
In matlab:
h = X*theta;
Cost Function
J(θ0,θ1)=12m∑i=1m(hθ(x(i))−y(i))2Attention: J(θ0,θ1) is a scalar, just a number.
In matlab, we can use like:
J = 1/(2*m) * sum((X*theta - y).^2); %.^ means dot product %sum means sum all elements in matrix
Gradient Descent
θj=θj−α∂∂θjJ(θ0,θ1)repeat until convergence.
parameter α: Learning rate
parameter ∂: Slope of tangent aka derivative
Gradient Descent for Linear Regression
When specifically applied to the case of linear regression, a new form of the gradient descent equation can be derived.θj=θj−α1m∑i=1m((hθ(x(i)j)−y(i))x(i)j)
In matlab, we can use like:
theta = theta - (alpha/m * X' * (X*theta - y)); %because of the matrix multiplication, we need not sum them.
相关文章推荐
- 10031---Java并发编程:volatile关键字解析
- 最全、最好用微信浏览器JS API合集!!!
- C#代码用F12转到定义时,不到源代码,而到元数据
- Application.mk
- 并发编程
- on a date:The Vampire Diaries
- 日历问题
- java -jar shell 启动、停止
- [android] sql语句实现数据库的增删改查
- 选夫婿1
- 伪装地理位置软件"任我行“android版本发布
- 修改jqGrid列表样式
- 最小堆建立
- tomcat双击startup.bat闪退的办法
- C#中static void Main(string[ ] args)中的作用及解释
- ubuntu下利用gcc编译C语言程序
- BZOJ 1305
- Codeforces Round #345 (Div. 2)
- 根据自己的身份账号ID查询性别及年龄
- 数据结构复习提纲