본문 바로가기

Mathematics/Linear Algebra

Linear Regression with one variable

<Linear Regression with one variable>

    1. Model representation

    2. Cost function

    3. Cost function intuition

    4. Gradient descent


Model representation

 

Supervised Learning: data에 right answer이 존재

  • Regression: output이 실수 형태
  • Classification: output이 discrete-value

Unsupervised Learning: data에 right answer이 존재 x

 

Linear regression with one variable (Univariate linear regression)


Cost function

 

Hypothesis: H(x) = wx + b

'Cost function' from:&nbsp;https://www.kdnuggets.com/2020/05/5-concepts-gradient-descent-cost-function.html

 

→ H(x)와 y가 가까워지는 w와 b 값 탐색 (minimize (H(x) - y))

 

Cost function = Objective function


Cost function intuition

 

Linear regression expressions from:&nbsp;https://www.kdnuggets.com/2020/05/5-concepts-gradient-descent-cost-function.html

 

→ minimizing Cost function

 

 

Hypothesis & Cost function from: Andrew Ng

 

 

Cost function from: Andrew Ng


Gradient descent

 

Cost function J(θ₁, θ₂)이 주어졌을 때, min J(θ0, θ1)을 구하는 과정

  • 임의의 θ₁, θ₂ 설정
  • θ₁과 θ₂의 값을 변화시키면서 J(θ₁, θ₂) 값을 감소
  • J(θ₁, θ₂)이 minimum값을 가질 때 종료

 

min J(&theta;0, &theta;1)이 하나 존재할 때 from: Andrew Ng

Convex function (볼록함수 형태)

min J(&theta;0, &theta;1)이 여러 개 존재할 때 from: Andrew Ng

Local minima

 

 

Gradient descent algorithm

Cost function에 θ가 하나만 존재할 시 예시,

  • Cost function:

    J(θ) = 2θ^2 - 4θ + 5

    J´(θ) = 4θ - 4

  • θ = 4 (임의의 값) 초기화
  • θ = 4 지점에서 기울기: J´(θ = 4) = 12
  • α = 0.1(Learning rate)로 설정 시, θ - α * J´(θ) = 4 - 0.1 * (+12)

    → 현재 위치(θ = 4)를 1.2 (-0.1 * 12) 만큼 왼쪽으로 이동 (θ = 2.8로 update)

    → Cost function 그래프의 높이가 낮아지는 방향으로 이동

  • 다시, θ = 2.8 인 지점에서 J(θ)가 minimum 해지는 지점까지 θ update

 

Cost function에 θ₁와 θ₂가 존재할 시 예시,

  • Cost function:

    J(θ₁, θ₂) = θ₁^2 + 3θ₂^2 - 2θ₁θ₂ + 4θ₁ -5θ₂ + 3

    d J(θ₁, θ₂) / dθ₁ = 2θ₁ - 2θ₂ + 4 

    d J(θ₁, θ₂) / dθ₂ = 6θ₂ - 2θ₁ - 5

  • θ₁ = -1, θ₂ = 2로 초기화
  • α = 0.1(Learning rate)
  • d J(θ₁=2, θ₂=4) / dθ₁ = -1 - 0.1*(-2)
  • d J(θ₁=2, θ₂=4) / dθ₂ = 2 - 0.1*(+9)

    → θ₁ = -0.8, θ₂ = 1.1로 update

  • 다시, θ₁ = -0.8, θ₂ = 1.1인 지점에서 J(θ)가 minimum 해지는 지점까지 θ update

 

'Mathematics > Linear Algebra' 카테고리의 다른 글

Lp Norm of vector, matrix  (0) 2022.06.17
Linear Regression with multiple variables  (0) 2022.05.19
SVD  (0) 2022.05.16
Advanced Eigendecomposition 2  (0) 2022.05.13
Advanced Eigendecomposition  (0) 2022.05.12