[ML of Andrew Ng]Week 1 : Linear Regression with One Variable

Week 1 Linear Regression with One Variable

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+θ1x

or:
hθ(x)=θ0x0+θ1x1whichx0=1

PS: x(i)j means the j rd features and ird examples.

we can get the vectors θ and X as:

θ=[θ0θ1]
(2×1)

and:
X=111x(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)=12mi=1m(hθ(x(i))y(i))2

Attention: 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α1mi=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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值