Multiplicative seasonality being applied correctly?
- Dominant language
- Python
- Stars
- 20.4k
- Forks
- 4.6k
- Avg merge
- 19h 52m
- Merged PRs (30d)
- 1
Description
Hi,
I'm building a model on that has yearly and daily multiplicative seasonality (e.g. weather data - amount of sunlight).
I suspect that the predict method is not applying the multiplication correctly.
I've generated a dummy example to help explain:
```
import numpy as np
import pandas as pd
import prophet
df = pd.DataFrame()
df['ds'] = pd.date_range(start='2019-01-01',end='2021-01-01',freq='4H')
df['daily_effect'] = np.cos(df['ds'].dt.hour/24 * 2*np.pi)*-0.5+0.5
df['yearly_effect'] = np.cos(df['ds'].dt.dayofyear/365 * 2*np.pi)*-0.3 + 0.7
df['y'] = df['daily_effect'] * df['yearly_effect']
df.set_index('ds')['y'].plot()
df.set_index('ds').loc['2020-01-01':'2020-01-05',:].plot()
df.set_index('ds').loc['2020-07-01':'2020-07-05',:].plot()
```

And a zoomed image:

I fit this with a flat growth, multiplicative model:
```
m = prophet.Prophet(growth='flat',weekly_seasonality=False,seasonality_mode='multiplicative')
m.fit(df)
df_future = m.make_future_dataframe(periods=365*6,freq='4H', include_history=False)
df_forecast = m.predict(df_future)
m.plot(df_forecast)
fig = m.plot_components(df_forecast)
```


The fitted components look good, but the prediction looks a bit odd. The peak is not at 1, and the minimum is negative.
If I multiply out the components differently I get a prediction which looks perfect (orange):
```
df_forecast['yhat2'] = df_forecast['trend'] * (1 + df_forecast['yearly']) * (1 + df_forecast['daily'])
df_forecast.set_index('ds')['yhat'].plot()
df_forecast.set_index('ds')['yhat2'].plot()
```

Could this be a difference in the definition of the fitted stan model and the predict method? Or an I specifying the model incorrectly.
Prophet == 1.0.1
pystan == 2.19.1.1
Python 3.7.10
Many thanks
Contributor guide
Assessment
This issue has not been assessed yet.