我有一些时间序列数据,我试图用Numpy中的polyfit
函数拟合曲线。我已使用date2num
函数将日期时间x值转换为数字,并绘制了原始数据,即大约600个数据点(01-01-2014 - 10-08-2015)。用Python/Numpy将数据拟合成多项式曲线
我想要为曲线派生一个表达式,以便我可以近似预测未来的数据点,例如在未来30天内我的图形数据。但是,当以任何顺序绘制图表时,我的多项式表达式都是离开的。我确信我正在做一些明显错误的事情,但似乎无法破解它。
x = df["dates"]
y= df["brand"]
poly = numpy.polyfit(x, y, 5)
polynomial = numpy.poly1d(poly)
xs = numpy.linspace(x[0], x[-1]+60, len(x)+60)
y_int = polynomial(xs)
plt.plot(x, y)
plt.plot(xs, y_int)
plt.show()
下图显示了蓝色的原始曲线。