Implement linear regression using gradient descent. Given features X, targets y, learning rate, and number of iterations, update weights to minimize the mean squared error.
import numpy as np
def linear_regression_gradient_descent(X: list[list[float]], y: list[float],
alpha: float, iterations: int) -> list[float]:
X = np.array(X, dtype=float)
y = np.array(y, dtype=float)
n = len(y)
theta = np.zeros(X.shape[1])
for _ in range(iterations):
predictions = X @ theta
errors = predictions - y
gradient = (1 / n) * (X.T @ errors)
theta = theta - alpha * gradient
return np.round(theta, 4).tolist()