Implement linear regression using the Normal Equation: theta = (X^T X)^(-1) X^T * y. Given feature matrix X and target vector y, return the parameter vector theta.
import numpy as np
def linear_regression_normal_equation(X: list[list[float]], y: list[float]) -> list[float]:
X = np.array(X, dtype=float)
y = np.array(y, dtype=float)
# theta = (X^T X)^(-1) X^T y
XTX = X.T @ X
XTy = X.T @ y
theta = np.linalg.inv(XTX) @ XTy
# Round to 4 decimal places
return np.round(theta, 4).tolist()