机器学习:最小二乘法(Python实现)
作者:互联网
最小二乘法求回归
题目
解
import numpy as np
x_h = np.array([178,179,170,179,165,169,177,167,172,167])
f_h = np.array([185,187,176,187,168,173,182,177,180,170])
x_bar = np.average(x_h)
f_bar = np.average(f_h)
sum1 = np.dot(x_h,f_h.transpose())
sum2 = np.dot(x_h,x_h.transpose())
w = (sum1 - 10*x_bar*f_bar)/(sum2-10*x_bar*x_bar)
b = f_bar - w * x_bar
print(w,b)
标签:bar,Python,最小,sum1,177,179,np,array,乘法 来源: https://blog.csdn.net/qq_41145832/article/details/120791298