欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

实现简单的线性拟合

程序员文章站 2022-07-13 11:51:48
...
import numpy as np
import matplotlib.pyplot as plt

# x = np.arange(1,17,1)
# y = np.array([4.00, 6.40, 8.00, 8.80, 9.22, 9.50, 9.70, 9.86, 10.00, 10.20, 10.32, 10.42, 10.50, 10.55, 10.58, 10.60])

x =[150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 600.0]
y =[6450.0, 7450.0, 8450.0, 9450.0, 11450.0, 15450.0, 18450.0]
print x
print y

z3 = np.polyfit(x,y,3)
p3 = np.poly1d(z3)

print z3
print p3

z1 = np.polyfit(x,y,1)
p1 = np.poly1d(z1)

print z1
print p1


plt.scatter(x,y,color = 'blue')
# plt.plot(x,y,'b^')
# plt.plot(x,p3(x),'gv--')
plt.plot(x,p1(x),'r*-')
plt.show()
实现简单的线性拟合