#2 Machine Learning : How to minimize Cost

yennΒ·2021λ…„ 1μ›” 10일
1

Machine Learning

λͺ©λ‘ 보기
2/2
post-thumbnail

How to minimize Cost

hypothesis

H(x) = Wx

Cost(W,b) μˆ˜μ‹

cost(W,b)=1mβˆ‘i=1m(Hx(i)βˆ’y(i))2cost(W,b) = \frac{1}{m} \sum^m_{i=1} (H{x^{(i)}} - y^{(i)})^2

β‡’ μ΅œμ†Œμ (minimize) λ₯Ό μ°ΎλŠ”κ²Œ λͺ©ν‘œ

Cost(W)

Gradient Descent algorithm, κ²½μ‚¬ν•˜κ°•λ²•

  • cost ν•¨μˆ˜ μ΅œμ†Œν™”

  • cost ν•¨μˆ˜κ°€ μ£Όμ–΄μ‘Œμ„ λ•Œ, Cost(W,b)Cost(W,b)μ—μ„œ costcostλ₯Ό μ΅œμ†Œν™” ν•˜λŠ” WW와 bbλ₯Ό μ°Ύμ•„μ€Œ

  • cost ν•¨μˆ˜ 말고도 각쒅 optimization에 μ΄μš©λ˜λŠ” 일방적인 방법

    β†’ 더 λ§Žμ€ 값듀이 주어지더라도, μ΅œμ†Œν™” ν•  수 있음

λ™μž‘ 방법

  • μ›ν•˜λŠ” κ°’ μ–΄λ””μ—μ„œλ‚˜ μ‹œμž‘
  • W와 b값을 κ³„μ†ν•΄μ„œ λ³€κ²½ν•˜λ©΄μ„œ cost(W,b)λ₯Ό μ€„μ—¬λ‚˜κ°
  • μœ„ 과정을 λ°˜λ³΅ν•˜λ©΄μ„œ 미뢄을 μ΄μš©ν•˜μ—¬ μ΅œμ†Œκ°’μ„ 찾음
  • κ²°κ΅­ local minimum에 μˆ˜λ ΄ν•˜κ²Œ 됨 β†’ 항상 μ΅œμ†Œμ μ—μ„œ μˆ˜λ ΄ν•˜κ²Œ λœλ‹€λŠ” 보μž₯은 μ—†μŒ

formal definition

cost(W)=1mβˆ‘i=1m(Wx(i)βˆ’y(i))2cost(W) = \frac{1}{m} \sum^m_{i=1} (W{x^{(i)}} - y^{(i)})^2

λ―ΈλΆ„μ‹œ 계산 편의λ₯Ό μœ„ν•΄ μ•„λž˜ μˆ˜μ‹κ³Ό 같이 λ³€ν™˜

cost(W)=12mβˆ‘i=1m(Wx(i)βˆ’y(i))2cost(W) = \frac{1}{2m} \sum^m_{i=1} (W{x^{(i)}} - y^{(i)})^2

Gradient descent algorithm

: cost ν•¨μˆ˜λ₯Ό μ΅œμ†Œν™” ν•˜λŠ” Wλ₯Ό κ΅¬ν•˜κ³  λͺ¨λΈμ„ λ§Œλ“€ 수 μžˆλ‹€.

W:=Wβˆ’Ξ±12mβˆ‘i=1m(Wx(i)βˆ’y(i))x(i)W := W - \alpha \frac{1}{2m} \sum^m_{i=1} (W{x^{(i)}} - y^{(i)})x^{(i)}

* Ξ± : learning rate (μƒμˆ˜) 
* := : "assignment" μ—°μ‚°μž

Cost function

: cost function을 3μ°¨μ›μœΌλ‘œ λ‚˜νƒ€λ‚΄μ—ˆμ„ λ•Œ, Gradient descent algorithm을 μ μš©ν•˜μ—¬ 기울기λ₯Ό λ‚΄λ €κ°€ 보면 μ΅œμ†Œν™”λ˜λŠ” 지점이 μ—¬λŸ¬κ΅°λ° 생길 수 μžˆμœΌλ―€λ‘œ μ•Œκ³ λ¦¬μ¦˜μ΄ μ œλŒ€λ‘œ λ™μž‘ν•˜μ§€ μ•ŠλŠ” 단점이 있음

Convex function

: cost function 의 단점을 λ³΄μ™„ν•˜κΈ° μœ„ν•΄μ„œ, Hypothesis와 cost function을 μ‚¬μš©ν•˜μ—¬ Convex function을 μ•„λž˜μ™€ 같이 λ§Œλ“€μ–΄μ£Όλ©΄, μ–΄λŠ μ§€μ μ—μ„œ μ‹œμž‘ν•˜λ“  간에 λ„μ°©ν•˜λŠ” 점이 μ΅œμ†Œκ°’μ΄ 됨

즉, cost function을 섀계할 λ•Œ λ°˜λ“œμ‹œ μ•„λž˜λ‘œ λ³Όλ‘ν•œ λͺ¨μ–‘을 κ°€μ§€λŠ” Convex function이 λ˜μ–΄μ•Ό 함


μ°Έκ³  κ°•μ’Œ : λͺ¨λ‘λ₯Ό μœ„ν•œ λ”₯λŸ¬λ‹ κ°•μ’Œ
μ°Έκ³  μ‚¬μ΄νŠΈ : Wikidocs

profile
Junior BackendEngineer 😎

0개의 λŒ“κΈ€