Lesson 3 of 7 · 2 min
Worked Numerical Example
Problem: Fit y = mx + b to: x = [1,2,3,4,5], y = [5,7,9,11,13] (true: m=2, b=3)
Iteration 0: Start with m=0, b=0
ŷ = 0×[1,2,3,4,5] + 0 = [0,0,0,0,0]
Loss = (1/5)×[(5-0)²+(7-0)²+(9-0)²+(11-0)²+(13-0)²] = (1/5)×[25+49+81+121+169] = 89.0
∂Loss/∂m = -(2/5)×[1×(5-0)+2×(7-0)+3×(9-0)+4×(11-0)+5×(13-0)]
= -(2/5)×[5+14+27+44+65] = -(2/5)×155 = -62.0
∂Loss/∂b = -(2/5)×[(5-0)+(7-0)+(9-0)+(11-0)+(13-0)]
= -(2/5)×45 = -18.0
m_new = 0 - 0.08×(-62.0) = 4.96
b_new = 0 - 0.08×(-18.0) = 1.44After ~1000 iterations: m ≈ 2.0, b ≈ 3.0
