先说明一下。本数据来源自丁香医生。
三次样条插值函数在拟合效果上
代码如下:
import scipy.interpolate as spi
import matplotlib.pyplot as plt
x = [1,2,3,4,5,6,7,8,9,10,11,12,13,14]
y=[41,41,45,62,121,198,258,440,571,830,1287,1975,2744,4535]
ix3=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
ipo3=spi.splrep(x,y,k=3)
iy3=spi.splev(ix3,ipo3)
print(iy3)
plt.plot(x,y,'o')
plt.plot(ix3,iy3)
plt.legend(['origin','interp'],loc='upper left')
plt.show()
看得出来,俩天之内肯定破万,希望大家照顾好自己。