import numpy as np
import sys
def linear_regression_normal_equation(X ,y):
X = np.array(X ,dtype=float)
y = np.array(y, dtype=float)
# 正规方程
theta = np.linalg.inv(X.T @ X) @ X.T @ y
# 题目要求:第一个是权重,第二个是偏置
weight = round(theta[0], 4)
bias = round(theta[1], 4)
return [weight, bias]
# in_list = [input() for x in range(2)]
lines = sys.stdin.read().strip().splitlines()
X = np.array(eval(lines[0]), dtype=int)
y = np.array(eval(lines[1]), dtype=int)
print(linear_regression_normal_equation(X, y))

京公网安备 11010502036488号