Batch Gradient Descent for Linear Regression (MSE)
Scenario
You are building a linear regression model from scratch and will optimize its parameters using batch gradient descent.
Assume you have:
-
Feature matrix X \in R^{n \times d} (n samples, d features)
-
Target vector y \in R^{n}
-
A weight vector w \in R^{d} and a scalar bias b (intercept)
Task
Write Python-style pseudocode for batch gradient descent that minimizes mean squared error (MSE) for linear regression. Briefly explain what each step in your pseudocode does.
Your pseudocode should cover:
-
Initialization of parameters (w, b)
-
Vectorized prediction
-
Error and loss (MSE)
-
Gradient computation
-
Parameter updates
-
Looping and stopping conditions (e.g., max iterations, tolerance)