Ankit Raibole
Ankit Raibole

Reputation: 35

Get back original prediction from logged and differenced time-series data in python

I am doing time-series forecasting to predict future orders. Since the data was non-stationary I did log and first-differencing. then I trained the Arima Model using the order values I got from auto_arima by passing the log-differenced data. I used last 30 days for testing and rest for training. I am getting the predicted values in the logged and differenced format. also I predicted for next 30 days which is not present in the dataset which give prediction in same format. How to get back the original data in both the cases since I don't have the data of future 30 days.

logging differencing

Prediction for testing data

Prediction for future

Upvotes: 0

Views: 5533

Answers (1)

Priya
Priya

Reputation: 743

This can be done conveniently using numpy. The reverse operation involves taking the cumsum() and then the exp().

You can do: Algorithm reference courtesy @Divakar

series = df["Number of Bookings"]
new_series = np.log(series).diff()
# getting only the value of zeroth index since the diff() operation looses first value.
new_series.iloc[0] = np.log(series.iloc[0])
result = np.exp(new_series.cumsum())

Upvotes: 4

Related Questions