Loading...
Implement batch gradient descent for simple linear regression.
Given data points (x,y), initial weight w and bias b, learning rate α, and number of iterations, update w and b to minimize Mean Squared Error:
MSE=n1∑i=1n(yi−(w⋅xi+b))2
The gradients are: ∂w∂MSE=n−2∑i=1nxi(yi−(w⋅xi+b)) ∂b∂MSE=n−2∑i=1n(yi−(w⋅xi+b))
Return a tuple (w, b) after all iterations, both rounded to 4 decimal places.
X = [1, 2, 3] y = [2, 4, 6] w = 0.0, b = 0.0 learning_rate = 0.1, iterations = 100
(1.9715, 0.0647)