I have some time series data which I am trying to fit to a curve using the polyfit function in Numpy. I have converted the datetime x-values to numbers using the date2num function and have graphed the original data, which is approximately 600 data points (01-01-2014 - 10-08-2015).
I am trying to derive an expression for the curve so that I may approximately forecast future data points, eg over the next 30 days beyond my graphed data. However, my polynomial expression, when graphed at any order, is way off. I am sure I am doing something glaringly wrong but cannot seem to crack it.
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()
The graph below shows the original curve in blue.
