I have a pandas Series with monthly data (df.sales
). I needed to subtract the data 12 months earlier to fit a time series, so I ran this command:
sales_new = df.sales.diff(periods=12)
I then fit an ARMA model, and predicted the future:
model = ARMA(sales_new, order=(2,0)).fit()
model.predict('2015-01-01', '2017-01-01')
Because I had diffed the sales data, when I use the model to predict, it predicts forward diffs. If this was diff of period 1, I would just use an np.cumsum()
, but because this is period 12, it makes it a bit tricker.
What is the best way to "unroll" the diff and turn it back into the scale of the original data?
This should do it:
Step by step version:
I think you need to calculate the future values off the values for the first 12 months: