To test the fbprophet library, I created a very simple synthetic series and generated a model like this:

import statsmodels.api as sm
from fbprophet import Prophet
import pandas as pd
import numpy as np

idx = pd.date_range('2016-01-01', '2016-05-04', freq='D')
phase = np.pi / 2
len_idx = len(idx)
points = np.arange(0, len_idx)
df = pd.DataFrame({'y': np.sin(points * 2 * np.pi / 30 + phase) + points / 100}, index=idx)
df['ds'] = df.index

mdl = Prophet()
mdl.add_seasonality('monthly', period=30, fourier_order=5)
df_result = mdl.predict(30, 'D')
_ = mdl.model.plot(df_result)

enter image description here

what looks like a very good fit and forecast. I'm now trying to evaluate the forecast using the Ljung-Box statistic:

df_train = df.iloc[:100]
df_test = df.iloc[100:]
mdl = Prophet()
mdl.add_seasonality('monthly', period=30, fourier_order=5)
df_forecast = mdl.predict(df_test)
df_forecast.index = df_forecast.ds
residue = df_test.y - df_forecast.yhat
nlags = 20
sm.stats.diagnostic.acorr_ljungbox(residue, nlags)
(array([26.58531982, 37.54004325, 39.75143298, 39.87513462, 39.87724859,
    39.87823833, 39.87841515]),
 array([2.52152459e-07, 7.05152716e-09, 1.20293579e-08, 4.59357440e-08,
    1.58094709e-07, 4.81312117e-07, 1.32806258e-06]))

and I get very small values for the p-value, meaning that the null hypothesis cannot be rejected (if I understood the test correctly), so there is still autocorrelated values in the forecast residue. What is the probable cause of this? The residues for this model look like residues

  • Either a deficient model or a deterministic time series – IrishStat Sep 8 at 8:45
  • Sorry, I didn't get that. How a deterministic time series would generate a Ljung-Box test with small p-values? – Ivan Sep 14 at 12:35

If there is untreated deterministic structure in the model residuals this inflates the error variance and downwards biases the acg thus downwards biasing the anacronostic Ljung-Box test . Deterministic structure like pulses , seasonal pulses , level/step shifts or local time trends arise quite frequently .

If you post your data I will try and help further.

  • 1
    Could you explain how this is relevant? The data were generated as shown in the question. Perhaps you posted this answer in the wrong place? – whuber Sep 14 at 19:43
  • ok if he generated the data ... i didn't as I don't use r and I was asking him to post it. If he doesn't want to do that nevermind !. his residuals suggest a deficient model or over-parameterized model. – IrishStat Sep 14 at 19:59
  • 1
    The OP doesn't use R either: this is Python code. The code and the plot look like enough information to generate the data using any language you like--how about Fortran? :-) – whuber Sep 14 at 20:01
  • 1
    Regardless, isn't it clear that none of the things you mention will be relevant to such a dataset? Take a look at the sizes of the forecast residuals, btw. – whuber Sep 14 at 20:05
  • 1
    Nobody is saying that data analysis lacks value or shouldn't be done. I'm just suggesting that it's important to read the question and respond to what it asks and to the context in which it is asked. Your post here is essentially the same as several hundred other responses you have posted--sometimes very helpfully--but it just doesn't seem remotely applicable to this case. – whuber Sep 15 at 12:42

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.