How to revert np.log(data) and data.diff()?

I have used np.log(data) and then applied data.diff() to transform my data in timeseries model. I have the predictions. How do I convert it back to normal scale?

Here is an example for your reference:

--------------------------------------------------------------------
| sales     | np.log(sales) | (np.log(sales)).diff() | predictions |
--------------------------------------------------------------------
|166.594019 | 5.115560      | -0.045918              | -0.045918   |
--------------------------------------------------------------------

Note: I have provided only one example which from index 2 as the first value after data.diff() will be null. And hence the prediction at index 1 is 0.

Topic transformation numpy arima time-series python

Category Data Science


As far as I understand the difference is $log(s_t)-log(s_{t-1})$, right?

I'm not sure that doing the diff on the log value is the best option but this means:

$$log(s_t)-log(s_{t-1})=log\left(\frac{s_t}{s_{t-1}}\right)$$

You could use exp to go back to the regular ratio:

$$exp\left(log\left(\frac{s_t}{s_{t-1}}\right)\right)=\frac{s_t}{s_{t-1}}$$

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.