题目链接:Deep-ML
import numpy as np
def linear_regression_normal_equation(X: list[list[float]], y: list[float]) -> list[float]:
X = np.array(X)
y = np.array(y).reshape(-1, 1)
x_transpose = X.T
theta = np.linalg.inv(x_transpose.dot(X)).dot(x_transpose).dot(y)
theta = np.round(theta, 4).flatten().tolist()
return theta