Linear Regression via Gradient Descent

easy
Unit 1 · Regression & Metrics0/3 to milestone

Fit y^=Xw+b\hat{y} = Xw + b by minimising mean squared error with batch gradient descent.

∂L∂w=2nX⊤(y^−y),∂L∂b=2n∑(y^−y)\frac{\partial L}{\partial w} = \frac{2}{n} X^\top(\hat{y} - y), \qquad \frac{\partial L}{\partial b} = \frac{2}{n}\sum(\hat{y} - y)

Implement fit(X, y, lr=0.01, epochs=1000) that starts from w = 0, b = 0 and returns (w, b) where w is a NumPy array of shape (n_features,).

#regression#optimisation#numpy2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Linear Regression via Gradient Descent · TechGradify