Prophet: Error on fit: Line search failed to achieve a sufficient decrease

Created on 22 May 2017  路  11Comments  路  Source: facebook/prophet

This is my dataframe

            ds         y
1   2017-04-05  6.147619
2   2017-04-07  0.107143
3   2017-04-07  2.050000
8   2017-04-11 -1.261905
12  2017-04-13  1.321429
9   2017-04-14 -0.135714
10  2017-04-14  0.752381
17  2017-04-18 -0.464286
15  2017-04-18 -1.892857
14  2017-04-20  2.966667
11  2017-04-24  0.530952
13  2017-04-26  0.178571
20  2017-04-28 -1.607143
21  2017-04-28 -1.071429
19  2017-05-04  1.838095
18  2017-05-16 -0.285714
23  2017-05-18 -0.071429

Here is the output I get when running fit().

Disabling yearly seasonality. Run prophet with yearly_seasonality=True to override this.
Initial log joint probability = -5.46208
    Iter      log prob        ||dx||      ||grad||       alpha      alpha0  # evals  Notes 
       1      -5.46208             0       19.4154       1e-12       0.001       27   
Optimization terminated with error: 
  Line search failed to achieve a sufficient decrease, no more progress can be made
Traceback (most recent call last):
  File "./Project_Report.py", line 165, in <module>
    runProjectReport(projectId)
  File "./Project_Report.py", line 162, in runProjectReport
    control.compare_estimations(projectId)
  File "/home/asoliver/work/reports/src/pm_reports/Pandas_Control_Report.py", line 135, in compare_estimations
    m1.fit(predictDf)
  File "/usr/lib/python3.6/site-packages/fbprophet/forecaster.py", line 535, in fit
    params = model.optimizing(dat, init=stan_init, iter=1e4, **kwargs)
  File "/usr/lib/python3.6/site-packages/pystan/model.py", line 510, in optimizing
    ret, sample = fit._call_sampler(stan_args)
  File "stanfit4anon_model_7a788197ac3493030b72020b9ffdbe7d_9047680921141364125.pyx", line 814, in stanfit4anon_model_7a788197ac3493030b72020b9ffdbe7d_9047680921141364125.StanFit4Model._call_sampler (/tmp/tmp4_w9put0/stanfit4anon_model_7a788197ac3493030b72020b9ffdbe7d_9047680921141364125.cpp:16904)
  File "stanfit4anon_model_7a788197ac3493030b72020b9ffdbe7d_9047680921141364125.pyx", line 401, in stanfit4anon_model_7a788197ac3493030b72020b9ffdbe7d_9047680921141364125._call_sampler (/tmp/tmp4_w9put0/stanfit4anon_model_7a788197ac3493030b72020b9ffdbe7d_9047680921141364125.cpp:8973)
RuntimeError: Something went wrong after call_sampler
bug ready

Most helpful comment

@ericbellet this was fixed in the current version on github. It will be pushed to pip soon, but in the meantime either download the code from github and install it from source, or you can also get around this issue by passing algorithm='Newton' to fit like so:

m.fit(df, algorithm='Newton')

All 11 comments

Error is in Stan model and there could be multiple reasons for it. Some of them I have given below -

  1. For few dates there are two or more records, not very suitable for time series modelling. Please aggregate the data and use.
  2. Negative values - it's not good idea to use negative values in the forecasting
  3. As you are using default setting, weekly seasonality will be created but there is not enough data to derive all parameters. If possible use more data

Hope above suggestions when followed might remove this error.

screen shot 2017-05-29 at 4 29 57 pm

I have the same problem with this data.

RuntimeError Traceback (most recent call last)
in ()
1 m = Prophet(weekly_seasonality=True,yearly_seasonality=False)
----> 2 m.fit(results)
3 print results
4 #future = m.make_future_dataframe(periods=number_predictions, freq='D')
5 #forecast = m.predict(future)

/Users/blanclink35/anaconda/lib/python2.7/site-packages/fbprophet/forecaster.pyc in fit(self, df, *kwargs)
533
534 else:
--> 535 params = model.optimizing(dat, init=stan_init, iter=1e4, *
kwargs)
536 for par in params:
537 self.params[par] = params[par].reshape((1, -1))

/Users/blanclink35/anaconda/lib/python2.7/site-packages/pystan/model.pyc in optimizing(self, data, seed, init, sample_file, algorithm, verbose, as_vector, **kwargs)
504 stan_args = pystan.misc._get_valid_stan_args(stan_args)
505
--> 506 ret, sample = fit._call_sampler(stan_args)
507 pars = pystan.misc._par_vector2dict(sample['par'], m_pars, p_dims)
508 if not as_vector:

stanfit4anon_model_7a788197ac3493030b72020b9ffdbe7d_8840454088550485021.pyx in stanfit4anon_model_7a788197ac3493030b72020b9ffdbe7d_8840454088550485021.StanFit4Model._call_sampler (/var/folders/l8/fvq2b7r55ld7fsbjynhr8yq40000gn/T/tmpzmRFJm/stanfit4anon_model_7a788197ac3493030b72020b9ffdbe7d_8840454088550485021.cpp:16904)()

stanfit4anon_model_7a788197ac3493030b72020b9ffdbe7d_8840454088550485021.pyx in stanfit4anon_model_7a788197ac3493030b72020b9ffdbe7d_8840454088550485021._call_sampler (/var/folders/l8/fvq2b7r55ld7fsbjynhr8yq40000gn/T/tmpzmRFJm/stanfit4anon_model_7a788197ac3493030b72020b9ffdbe7d_8840454088550485021.cpp:8973)()

RuntimeError: Something went wrong after call_sampler.

m = Prophet(weekly_seasonality=True,yearly_seasonality=True)
m.fit(df)

m = Prophet(weekly_seasonality=False,yearly_seasonality=True)
m.fit(df)

m = Prophet(weekly_seasonality=False,yearly_seasonality=False)
m.fit(df)

m = Prophet(weekly_seasonality=True,yearly_seasonality=False)
m.fit(df)

This looks like the same issue as #192. I'm not able to replicate this issue, could you check what version of pystan you are using?

In my case it was negative values. Once I changed the values to be always positive, it worked fine

@asoliverez thanks. This is a bug, probably related to #182 although I thought that one was specific to logistic growth. I'll have to track this down.

similar problem with me:
image

Disabling yearly seasonality. Run prophet with yearly_seasonality=True to override this.

RuntimeError Traceback (most recent call last)
in ()
1 m = Prophet()
----> 2 m.fit(df);

C:\Program Files\Anaconda3\lib\site-packages\fbprophet\forecaster.py in fit(self, df, *kwargs)
533
534 else:
--> 535 params = model.optimizing(dat, init=stan_init, iter=1e4, *
kwargs)
536 for par in params:
537 self.params[par] = params[par].reshape((1, -1))

C:\Program Files\Anaconda3\lib\site-packages\pystan\model.py in optimizing(self, data, seed, init, sample_file, algorithm, verbose, as_vector, **kwargs)
508 stan_args = pystan.misc._get_valid_stan_args(stan_args)
509
--> 510 ret, sample = fit._call_sampler(stan_args)
511 pars = pystan.misc._par_vector2dict(sample['par'], m_pars, p_dims)
512 if not as_vector:

stanfit4anon_model_9c941523472e65f75f241e35a8769919_6748955726184500932.pyx in stanfit4anon_model_9c941523472e65f75f241e35a8769919_6748955726184500932.StanFit4Model._call_sampler (C:\Users\fisher\AppData\Local\Temp\tmph84up0mb\stanfit4anon_model_9c941523472e65f75f241e35a8769919_6748955726184500932.cpp:15887)()

stanfit4anon_model_9c941523472e65f75f241e35a8769919_6748955726184500932.pyx in stanfit4anon_model_9c941523472e65f75f241e35a8769919_6748955726184500932._call_sampler (C:\Users\fisher\AppData\Local\Temp\tmph84up0mb\stanfit4anon_model_9c941523472e65f75f241e35a8769919_6748955726184500932.cpp:8607)()

RuntimeError: Something went wrong after call_sampler.

it went wrong with this particular series, but did work well with other series with the same sample number.

The issue here seems to be that the LBFGS optimization is sometimes failing to converge (especially on very small datasets). I just pushed https://github.com/facebookincubator/prophet/commit/f7becb0942cd0a005d72ae307aefee431fa962d7 which falls back to the Newton solver if LBFGS fails. This fixes the issue for the dataset of @asoliverez . Could others who are having this issue install from github and see if it fixes for you?

`
/usr/bin/anaconda/lib/python2.7/site-packages/fbprophet/forecaster.py in fit(self, df, *kwargs)
593
594 else:
--> 595 params = model.optimizing(dat, init=stan_init, iter=1e4, *
kwargs)
596 for par in params:
597 self.params[par] = params[par].reshape((1, -1))

/usr/bin/anaconda/lib/python2.7/site-packages/pystan/model.pyc in optimizing(self, data, seed, init, sample_file, algorithm, verbose, as_vector, **kwargs)
508 stan_args = pystan.misc._get_valid_stan_args(stan_args)
509
--> 510 ret, sample = fit._call_sampler(stan_args)
511 pars = pystan.misc._par_vector2dict(sample['par'], m_pars, p_dims)
512 if not as_vector:

stanfit4anon_model_7a788197ac3493030b72020b9ffdbe7d_8840660148491925221.pyx in stanfit4anon_model_7a788197ac3493030b72020b9ffdbe7d_8840660148491925221.StanFit4Model._call_sampler (/tmp/tmpiQXjT1/stanfit4anon_model_7a788197ac3493030b72020b9ffdbe7d_8840660148491925221.cpp:17114)()

stanfit4anon_model_7a788197ac3493030b72020b9ffdbe7d_8840660148491925221.pyx in stanfit4anon_model_7a788197ac3493030b72020b9ffdbe7d_8840660148491925221._call_sampler (/tmp/tmpiQXjT1/stanfit4anon_model_7a788197ac3493030b72020b9ffdbe7d_8840660148491925221.cpp:8988)()

RuntimeError: Something went wrong after call_sampler.
screen shot 2017-07-26 at 3 27 33 pm
`

@ericbellet this was fixed in the current version on github. It will be pushed to pip soon, but in the meantime either download the code from github and install it from source, or you can also get around this issue by passing algorithm='Newton' to fit like so:

m.fit(df, algorithm='Newton')

This fix is now in CRAN and pypi in v0.2.

I have the same issue
m.fit(df, algorithm='Newton')
solved it, thanks a lot.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

maxwell873 picture maxwell873  路  3Comments

arnaudvl picture arnaudvl  路  3Comments

robertdknight picture robertdknight  路  3Comments

ChaymaeHarfoush picture ChaymaeHarfoush  路  3Comments

dsvrsec picture dsvrsec  路  3Comments