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.27k stars 4.51k forks source link

persistent error in MCMC sampling #2324

Open elenaAMA opened 1 year ago

elenaAMA commented 1 year ago

Hi, I am trying to run MCMC sampling on a windows machine to obtain uncertainty intervals around seasonality estimates of my historical data and I keep getting this error, no matter what dataset I use to fit the model. The fitting works perfectly if I don't set MCMC samples.

Also, I am aware that on windows machines MCMC sampling, even when successful, takes a very long time, so I was wondering if there any other ways to get some indications of how reliable the estimation of the seasonality components are? I am using a work computer so I cannot use a virtual linux machine.

TypeError Traceback (most recent call last) ‹ipython-input-39-ceef802c3e45> in ‹module>

m.add _seasonality(name='avg_months', period=30.5, fourier order=5) fit=m. fit(data) forecast = m .predict()

C: \ProgramData\Miniconda3\envs\jup385\lib\site-packages\prophet\forecaster.pyinfit(self,df,kwargs) self.params[par] = np.array([self.params(par]]) elif self.mcmc samples > 0: self.params= self.stan_backend. sampling (stan init, dat, self.meme samples, kwargs) else: self.params= self.stan_backend.fit(stan_init, dat, **kwargs)

C: \ProgramData\Miniconda3\envs\jup385\lib\site-packages\prophet\models.pyin sampling(self, stan_init, stan_data, samples,kwargs) self.stan_fit = self. model.sample(args) res = self.stan fit.draws () (samples, c, columns) = res. shape res = res. reshape((samples* C, columns)) TypeError: 'int' object is not callable

tcuongd commented 1 year ago

We might need the full code and data to help debug.

a-bolger commented 1 year ago

I also have the same error, and this seems to be the only post online discussing the bug. Here's a sample bit of code:

from prophet import Prophet

data = pd.date_range(start='1/1/2022', end='2/1/2022', freq='h').to_frame().rename(columns={0: 'ds'})
data['y'] = range(len(data))

m = Prophet(
    mcmc_samples=10
)
m.fit(data)

future = m.make_future_dataframe(
    periods=100, 
    freq='h'
)

m.predict(future)

It runs fine when you remove the mcmc_samples parameter.

But with a nonzero mcmc_samples parameter, I get the same error as the OP here:

File /usr/local/lib/python3.9/site-packages/prophet/forecaster.py:1172, in Prophet.fit(self, df, **kwargs)
   1170         self.params[par] = np.array([self.params[par]])
   1171 elif self.mcmc_samples > 0:
-> 1172     self.params = self.stan_backend.sampling(stan_init, dat, self.mcmc_samples, **kwargs)
   1173 else:
   1174     self.params = self.stan_backend.fit(stan_init, dat, **kwargs)

File /usr/local/lib/python3.9/site-packages/prophet/models.py:131, in CmdStanPyBackend.sampling(self, stan_init, stan_data, samples, **kwargs)
    128 args.update(kwargs)
    130 self.stan_fit = self.model.sample(**args)
--> 131 res = self.stan_fit.draws()
    132 (samples, c, columns) = res.shape
    133 res = res.reshape((samples * c, columns))

TypeError: 'int' object is not callable