梯度公式:X^T \cdot errors / m

import numpy as np
def linear_regression_gradient_descent(X, y, alpha, iterations):
    h, w = X.shape
    theta = np.zeros((w, 1))
    for _ in range(iterations):
        predictions = X @ theta
        errors = y.reshape(h, 1) - predictions
        updates = X.T @ errors / h
        theta += alpha * updates
    return np.round(theta.flatten(), 4)