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.42k stars 4.53k forks source link

Maximum number of iterations hit, may not be at an optima #1620

Closed Oumaima-Boumlik closed 4 years ago

Oumaima-Boumlik commented 4 years ago

Hi everyone! I am using a small data set (2400 row) and try to forecast values for each group of time series based on a groupby (col_resolution), I had the warning of "Maximum number of iterations hit, may not be at an optima " I thought that it depends on the number of changepoints but strangely using the same dataset and changing the column 'tot' as ints instead of floats, it works perfectly. here is my function:

` def fit_predict_model(group):

model = Prophet()

model.fit(group)

days = pd.date_range(start=group['ds'].iloc[0], end=group['ds'].iloc[-1])

df_y = seasonality_plot_df(model, days)

seas = model.predict_seasonal_components(df_y)

forecast = model.predict(df_y)

forecast['fact'] = group['y'].reset_index(drop=True)

return seas, forecast  `

datatest_floats.txt I'm confused about the origin of this problem, could you please guide me?

bletham commented 4 years ago

This probably isn't a problem. Basically what is happening is during model fitting, there are several conditions that will terminate the optimization. One is that the gradient goes to 0, indicating convergence to a local optimum. But there is also a max number of iterations at which it will terminate. For some datasets, the likelihood surface is very flat around the optimum, so the optimizer can slow down and take a lot of iterations, and in this case, reach the max before the gradient has gone all the way to 0. But I'd expect that the parameter fits to still be good. Changing the data will change the optimizer surface, and so change the optimizer behavior.

To be sure, you could try changing the optimizer to Stan's Newton optimizer (default is L-BFGS) and see if that makes much difference in the forecast:

model.fit(group, algorithm='Newton')