48
Andrew Ng Linear regression with one variable Model representation Machine Learning

Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

  • Upload
    others

  • View
    13

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

Linear regression with one variable

Model representation

Machine Learning

Page 2: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

0

100

200

300

400

500

0 500 1000 1500 2000 2500 3000

0

100

200

300

400

500

0 500 1000 1500 2000 2500 3000

집가격(Portland, OR)

가격(in 1000s of dollars)

크기 (feet2)

감독학습(Supervised Learning)

자료의 “정확한답"이각예들에대해주어진

회귀문제(Regression Problem)

실수-값을갖는출력을예측

Page 3: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

기호:m = 훈련자료의갯수x’s = “입력” 변수 / 특징(features)y’s = “출력” 변수 / “목적(target)” 변수

Size in feet2 (x) Price ($) in 1000's (y)

2104 4601416 2321534 315852 178… …

집가격의훈련집합

(Portland, OR)

Page 4: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

훈련자료집합

학습알고리즘

h집크기 추정가격

우리는 h를어떻게표현하는가?

변수가하나인선형회귀.단변량선형회귀

(Univariate linear regression)

Page 5: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

Cost function

Machine Learning

Linear regression with one variable

Page 6: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

는어떻게선택하는가 ?

훈련자료

가설(Hypothesis):

‘s : 파라메타(Parameters)

Size in feet2 (x) Price ($) in 1000's (y)

2104 4601416 2321534 315852 178… …

Page 7: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

0

1

2

3

0 1 2 3

0

1

2

3

0 1 2 3

0

1

2

3

0 1 2 3

Page 8: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

y

x

생각: 이우리의훈련자료에대한 에

가깝도록 를선택한다.

Page 9: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

Cost functionintuition I

Machine Learning

Linear regression with one variable

Page 10: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

가설:

파라메타:

비용함수 :

목적:

간략화

Page 11: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

0

1

2

3

0 1 2 3

y

x

(고정된 에대하여, 이것은 x의함수) (파라메타 의함수 )

0

1

2

3

-0.5 0 0.5 1 1.5 2 2.5

Page 12: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

0

1

2

3

0 1 2 3

y

x

0

1

2

3

-0.5 0 0.5 1 1.5 2 2.5

(고정된 에대하여, 이것은 x의함수) (파라메타 의함수 )

Page 13: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

0

1

2

3

-0.5 0 0.5 1 1.5 2 2.5

y

x

0

1

2

3

0 1 2 3

(고정된 에대하여, 이것은 x의함수) (파라메타 의함수 )

Page 14: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

Cost functionintuition II

Machine Learning

Linear regression with one variable

Page 15: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

Hypothesis(가설):

파라메타:

비용함수:

목적:

Page 16: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

0

100

200

300

400

500

0 1000 2000 3000

Price ($) in 1000’s

Size in feet2 (x)

(고정된 에대하여, 이것은 x의함수) (파라메타 의함수 )

Page 17: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

Page 18: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

(파라메타 의함수 )(고정된 에대하여, 이것은 x의함수)

Page 19: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

(파라메타 의함수 )(고정된 에대하여, 이것은 x의함수)

Page 20: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

(파라메타 의함수 )(고정된 에대하여, 이것은 x의함수)

Page 21: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

(파라메타 의함수 )(고정된 에대하여, 이것은 x의함수)

Page 22: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

Gradient descent

Machine Learning

Linear regression with one variable

Page 23: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

어떤함수 를가지고

를원한다

Outline:

• 어떤 로시작한다.

• 최소값에도달할때까지, 가

감소하도록 를계속변화시킨다

Page 24: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

1

0

J(0,1)

Page 25: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

0

1

J(0,1)

Page 26: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

Gradient descent algorithm

Correct: Simultaneous update Incorrect:

Page 27: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

Gradient descentintuition

Machine Learning

Linear regression with one variable

Page 28: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

경사하강(Gradient descent) algorithm

Page 29: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

Page 30: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

α 가너무작으면, 경사하강이느릴수있다.

α 가너무크면, 경사하강은최소점을지나칠수있다. 수렴에실패하거나, 심지어는발산할수있다.

Page 31: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

at local optima

Current value of

Page 32: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

경사하강은학습률 α 가고정된상태로도, 국지적최소점으로수렴할수있다.

우리가국지적최소값에접근함에따라서, 경사하강은자동적으로더작은단계를취한다. 따라서, 시간에따라서 α 를줄일필요가없다.

Page 33: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

Gradient descent for linear regression

Machine Learning

Linear regression with one variable

Page 34: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

Gradient descent algorithm Linear Regression Model

Page 35: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

Page 36: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

Gradient descent algorithm

과 를동시에갱신

Page 37: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

1

0

J(0,1)

Page 38: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

Page 39: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

(for fixed , this is a function of x) (function of the parameters )

Page 40: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

(for fixed , this is a function of x) (function of the parameters )

Page 41: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

(for fixed , this is a function of x) (function of the parameters )

Page 42: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

(for fixed , this is a function of x) (function of the parameters )

Page 43: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

(for fixed , this is a function of x) (function of the parameters )

Page 44: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

(for fixed , this is a function of x) (function of the parameters )

Page 45: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

(for fixed , this is a function of x) (function of the parameters )

Page 46: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

(for fixed , this is a function of x) (function of the parameters )

Page 47: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

(for fixed , this is a function of x) (function of the parameters )

Page 48: Introduction to Programming - Jun Jijun.hansung.ac.kr/ML/docs-slides-Lecture2-kr.pdf · 2016-09-01 · Introduction to Programming Author: OpenClassroom Created Date: 9/1/2016 1:54:22

Andrew Ng

“배치(Batch)” 경사강하

“Batch”: 경사강하의각단계마다모든훈련자료를

사용한다.