jinit24 / ARIMA-Model

ARIMA model from scratch using numpy and pandas.
MIT License
19 stars 10 forks source link

How to Un-differencing the data? #1

Closed shenxiangzhuang closed 3 years ago

shenxiangzhuang commented 3 years ago

Hello Jinit, I have read your awesome code in this repo and the article in medium which helps me a lot and thank you for your work. But I can not grasp the key idea about the way of Un-differencing the data. Could you please explain the code with more details?

df_c.Value += np.log(df).shift(1).Value
df_c.Value += np.log(df).diff().shift(12).Value
df_c.Predicted_Values += np.log(df).shift(1).Value 
df_c.Predicted_Values += np.log(df).diff().shift(12).Value
df_c.Value = np.exp(df_c.Value)
df_c.Predicted_Values = np.exp(df_c.Predicted_Values)
jinit24 commented 3 years ago

The differencing is done using :

pd.DataFrame(np.log(df.Value).diff().diff(12))

So if the differencing was just shift(1), you'd add only the shift(1).value (This was the value that was removed) But now that we are differencing twice, you have to add the shift(1), then the shift(1) shifted by 12.

shenxiangzhuang commented 3 years ago

Sorry for my late reply, and I try to figure out the transformation by these equations as fellows, which I think may help others in a way~ image