neural_prophet icon indicating copy to clipboard operation
neural_prophet copied to clipboard

Multiplicative Seasonality fitted correctly but returned wrong

Open ourownstory opened this issue 3 years ago • 1 comments

Discussed in https://github.com/ourownstory/neural_prophet/discussions/303

Originally posted by sgheinze March 26, 2021 I'm hoping someone can help me understand the multiplicative model used in NeuralProphet and how it relates to values in the forecast DataFrame.

I've (perhaps incorrectly) been assuming that the NeuralProphet model is the same as the Prophet model, which according to this post in the Prophet GitHub (https://github.com/facebook/prophet/issues/1329#issuecomment-588536185) and this kaggle source (https://www.kaggle.com/smakarychev/what-is-facebook-prophet-forecasting-model), is: Yhat = trend * (1 + multiplicative terms) + additive terms which for models without additive terms reduces to: Yhat = trend * (1 + multiplicative terms)

However, when I fit a simple multiplicative model to some toy data with only a single multiplicative seasonal term, I am unable to verify that equation:

model = NeuralProphet(n_forecasts=1, seasonality_mode="multiplicative", growth="off", weekly_seasonality=True, yearly_seasonality=False)
metrics = model.fit(df, freq="D")
future = model.make_future_dataframe(df, periods=1)
forecast = model.predict(future)
forecast.head()

	ds	          y	       yhat1  residual1	     trend	 season_weekly
0	2021-03-18	None	27814.070312	NaN	30103.738281	-0.064573

As you can see in the forecast DataFrame above, yhat1 != trend * (1 + season_weekly) for this particular forecast.

Where am I going wrong?

ourownstory avatar Oct 15 '21 13:10 ourownstory

This may have to do with seasonality not being multiplied with trend and then un-normalized. Proper solution would be to do away with the component-wise function and merge it with the actual forward function. https://github.com/ourownstory/neural_prophet/blob/cf535ca55a39192dd3edb2abfaf39cab2eb7ea6d/neuralprophet/time_net.py#L485

ourownstory avatar Oct 15 '21 13:10 ourownstory