facebook / prophet

Tool for producing high quality forecasts for time series data that has multiple seasonality with linear or non-linear growth.
https://facebook.github.io/prophet
MIT License
18.24k stars 4.5k forks source link

how to inverse forecast data to original after predict using stationany data from differencing? #2102

Open OrangeCrab opened 2 years ago

OrangeCrab commented 2 years ago

I'm newbie, I have a project about time series forecasting, I use facebook prophet. This is my route: stationary test -> differencing -> stationary data -> fit & predict -> forecasting data 'yhat' is inversed done, but I dont know how to inverse 'yhat_upper', 'yhat_lower',...

(I inverse 'yhat' by:

def inverse_differencing(root, tg):
        series_inverted = []
        for i in range(len(root)-1, -1,-1):
                series_inverted = np.r_[root[i], tg].cumsum().astype(float)
                tg = series_inverted.copy()
        return series_inverted
# root is list of base value using for inverse
tg = forecast['yhat'][-prediction_size_:].copy()
series_inverted = inverse_differencing(root, tg)

_result is seriesinverted )

help me, pls my English is not good, Im sorry

tcuongd commented 2 years ago

Firstly, I wouldn't recommend difference-ing the data, Prophet can handle non-stationary time series because it models the underlying growth directly.

I think if you wanted to inverse everything, you would need to access the draws of the predicted distribution, invert all of those values, then re-calculate the lower and upper bounds. You can access the draws by using m.predictive_samples(future_df).