prophet icon indicating copy to clipboard operation
prophet copied to clipboard

AttributeError: 'Prophet' object has no attribute 'stan_backend'

Open eromoe opened this issue 1 year ago • 8 comments

Same code working in cmd(ipython) , but failed in vscode(jupyter)

from prophet import Prophet
m = Prophet()

error:

2023-07-17 17:42:52,583 - cmdstanpy - DEBUG - cmd: where.exe tbb.dll
cwd: None
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[62], line 1
----> 1 m = Prophet()

File c:\Users\ufo\anaconda3\envs\quant\lib\site-packages\prophet\forecaster.py:143, in Prophet.__init__(self, growth, changepoints, n_changepoints, changepoint_range, yearly_seasonality, weekly_seasonality, daily_seasonality, holidays, seasonality_mode, seasonality_prior_scale, holidays_prior_scale, changepoint_prior_scale, mcmc_samples, interval_width, uncertainty_samples, stan_backend)
    141 self.fit_kwargs = {}
    142 self.validate_inputs()
--> 143 self._load_stan_backend(stan_backend)

File c:\Users\ufo\anaconda3\envs\quant\lib\site-packages\prophet\forecaster.py:156, in Prophet._load_stan_backend(self, stan_backend)
    153 else:
    154     self.stan_backend = StanBackendEnum.get_backend_class(stan_backend)()
--> 156 logger.debug("Loaded stan backend: %s", self.stan_backend.get_type())

AttributeError: 'Prophet' object has no attribute 'stan_backend'

eromoe avatar Jul 17 '23 09:07 eromoe

Work fine on jupyterlab too, got this error only on vscode.

eromoe avatar Jul 18 '23 02:07 eromoe

Work fine on jupyterlab too, got this error only on vscode.

me too

AngleYang123 avatar Oct 10 '23 04:10 AngleYang123

I believe the solution to this is to move this log statement here: https://github.com/facebook/prophet/blob/211d2ebd4d17aacaea6dc3f1b18fca95f98ea1ba/python/prophet/forecaster.py#L168C16-L168C21

inside the else block immediately above it @tcuongd

WardBrian avatar Oct 12 '23 13:10 WardBrian

I just wanted to add that I am having a similar issue where it runs fine on Spyder, but when I try to run the same script in PowerBI and pointed at the same python environment I am running into the same error

CoreySco avatar Nov 01 '23 18:11 CoreySco

I'm having the same error using vscode. I tryed what @WardBrian said but the sam error moved to the line 1232 as you can see in this log:

Importing plotly failed. Interactive plots will not work.
you are using nologin method, data you access may be limited
INFO:prophet:Disabling yearly seasonality. Run prophet with yearly_seasonality=True to override this.
INFO:prophet:Disabling weekly seasonality. Run prophet with weekly_seasonality=True to override this.
INFO:prophet:Disabling daily seasonality. Run prophet with daily_seasonality=True to override this.
Exception in thread Thread-1 (worker):
Traceback (most recent call last):
  File "C:\Users\Elia\AppData\Local\Programs\Python\Python311\Lib\threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "C:\Users\Elia\AppData\Local\Programs\Python\Python311\Lib\threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "d:\Programmazione\price_prediction\main.py", line 21, in worker  
    prophet.fit(hist)
  File "C:\Users\Elia\AppData\Local\Programs\Python\Python311\Lib\site-packages\prophet\forecaster.py", line 1232, in fit
    self.params = self.stan_backend.fit(stan_init, dat, **kwargs)        
                  ^^^^^^^^^^^^^^^^^
AttributeError: 'Prophet' object has no attribute 'stan_backend'

The actual code that caused this error is this:

from tvDatafeed import TvDatafeed, Interval
from prophet.plot import plot_plotly
from prophet import Prophet
import threading

# currencys = ["BTC", "ETH", "SHIB", "LUNC", "BNB"]
currencys = ["BTC", ]

tv = TvDatafeed()
def worker(currency):

    currency += "USDT"
    hist = tv.get_hist(symbol=currency, exchange='binance', interval=Interval.in_1_minute, n_bars=1000)

    cols = ["datetime", "close"]
    hist = hist.reset_index()
    hist = hist[cols]
    hist.columns = ["ds", "y"]
    
    prophet = Prophet()
    prophet.fit(hist)
    future_dates = prophet.make_future_dataframe(period=100)
    predictions = prophet.predict(future_dates)
    plot_plotly(prophet, predictions)


for c in currencys:
    t = threading.Thread(target=worker, args=(c,))
    t.start()

Lizzit avatar Mar 02 '24 14:03 Lizzit

I have the same problem. @Lizzit Did you manage to solve this problem? I'm working on VS Code

KonradIEO avatar Mar 12 '24 17:03 KonradIEO

Work fine on jupyterlab too, got this error only on vscode.

Nope, I am facing it on jupyterlab as well: image

Did someone find a fix for this?

minakhalid avatar Mar 23 '24 16:03 minakhalid

@minakhalid I haven't found a simple solution to this problem - I reinstalled whole library. The problem lies in (not good) connection between prophet and pystan library. The whole path to a solution was long for me, but long story short: prophet worked only when I installed it via conda. I recommend completing the installation according to the link below: https://blog.quantinsti.com/installing-prophet-library-windows/

I hope it will help

KonradIEO avatar Mar 26 '24 09:03 KonradIEO