Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StanModel' object has no attribute 'fit_class' Error #249

Closed
tle4336 opened this issue Jul 12, 2017 · 13 comments
Closed

StanModel' object has no attribute 'fit_class' Error #249

tle4336 opened this issue Jul 12, 2017 · 13 comments

Comments

@tle4336
Copy link

tle4336 commented Jul 12, 2017

I got the following error message when trying to use the "fit" feature. I ran Python on Anaconda environment, with Pystan's 2.14 version, Pandas's 0.20.2 version, and Python's 3.5 version. I don't understand why I encounter this issue, so could anyone please help?

Error Message:
'WARNING:pystan:numpy.core.multiarray failed to import
WARNING:pystan:Something went wrong while unpickling the StanModel. Consider recompiling.

RuntimeError Traceback (most recent call last)
RuntimeError: module compiled against API version 0xb but this version of numpy is 0xa

WARNING:pystan:numpy.core.multiarray failed to import
WARNING:pystan:Something went wrong while unpickling the StanModel. Consider recompiling.
Disabling yearly seasonality. Run prophet with yearly_seasonality=True to override this.

AttributeError Traceback (most recent call last)
in ()
11 HAN_BIKE["ds"] = HAN_BIKE["ds"].values.astype('datetime64[D]')
12 m = Prophet()
---> 13 m.fit(HAN_BIKE)

/Applications/anaconda/lib/python3.5/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))

/Applications/anaconda/lib/python3.5/site-packages/pystan/model.py in optimizing(self, data, seed, init, sample_file, algorithm, verbose, as_vector, **kwargs)
466 data = {}
467
--> 468 fit = self.fit_class(data)
469
470 m_pars = fit._get_param_names()

AttributeError: 'StanModel' object has no attribute 'fit_class''

@tle4336
Copy link
Author

tle4336 commented Jul 12, 2017

Sorry, but nobody could help me with the above issue?

@bletham
Copy link
Contributor

bletham commented Jul 15, 2017

To be able to isolate the issue, could you check if pystan is working?

import pystan
model_code = 'parameters {real y;} model {y ~ normal(0,1);}'
model = pystan.StanModel(model_code=model_code)  # this will take a minute
y = model.sampling(n_jobs=1).extract()['y']
y.mean()  # should be close to 0

@tle4336
Copy link
Author

tle4336 commented Jul 17, 2017

@bletham Thanks for your help. Yes, it does give me the result: 0.017287202743671251. It's weird FB doesn't even address this issue in the FAQ for FB prophet;p

@bletham
Copy link
Contributor

bletham commented Jul 25, 2017

I'm sorry to say that I'm really not sure what is happening here. Could you try re-installing fbprophet and seeing if there are any errors / warnings during install? If you're using Anaconda then conda install -c conda-forge fbprophet seems to be the best way to install.

@bletham
Copy link
Contributor

bletham commented Jul 26, 2017

Actually I think the issue is something with the numpy installation. Notice the warning that Pystan is giving about not being able to import numpy multiarray. Are you able to import numpy.core.multiarray? It then says "module compiled against API version 0xb but this version of numpy is 0xa".

Could you upgrade numpy to the latest version, and perhaps also pystan?

@zerogouzi
Copy link

the pystan and fbprophet's isn't suitable, change the version will be fine.

@ggaaooppeenngg
Copy link

the pystan and fbprophet's isn't suitable, change the version will be fine.

which version do you use?

@itssimon
Copy link

itssimon commented Jan 2, 2019

This fixed it for me

@ivonnics
Copy link

ivonnics commented Jan 4, 2019

I am having exactly the same problem when I instantiate the prophet model with:
m = Prophet()
m.fit(df)
I got:
AttributeError Traceback (most recent call last)
<ipython-input-15-1ab3c9387252> in <module>
1 m = Prophet()
----> 2 m.fit(df)

~\Anaconda3\envs\PystanandProphet\lib\site-packages\fbprophet\forecaster.py in fit(self, df, **kwargs)

~\Anaconda3\envs\PystanandProphet\lib\site-packages\pystan\model.py in optimizing(self, data, seed, init, sample_file, algorithm, verbose, as_vector, **kwargs)
470 data = {}
471 seed = pystan.misc._check_seed(seed)
--> 472 fit = self.fit_class(data, seed)
473
474 m_pars = fit._get_param_names()

AttributeError: 'StanModel' object has no attribute 'fit_class'
I tried to downgrade with pip install fbprophet==0.3.post2 , and also tried:
pip install fbprophet --no-cache-dir --no-binary :all:
but got the same...
Any suggestion?

@ivonnics
Copy link

ivonnics commented Jan 5, 2019

Please, notice that @bletham Just reopened #775 ...which address this very same issue...

@zerogouzi
Copy link

zerogouzi commented Jan 7, 2019 via email

@bletham
Copy link
Contributor

bletham commented Jan 7, 2019

As Sean described in #775, the current issue was not a locally-cached whl (as it was in this issue, and as I had initially thought in #775), but rather it was that we had inadvertently put a whl on pypi.

We removed the whl on pypi, and so this issue should now be resolved (again!) and if you pip install it should build properly.

@Mohsinrazaa
Copy link

how to fix this error.

ERROR: Command errored out with exit status 1:
command: 'c:\python37\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\HP\AppData\Local\Temp\pip-install-k1eo64gl\fbprophet\setup.py'"'"'; file='"'"'C:\Users\HP\AppData\Local\Temp\pip-install-k1eo64gl\fbprophet\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\HP\AppData\Local\Temp\pip-record-4c8jwmk6\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\python37\Include\fbprophet'
cwd: C:\Users\HP\AppData\Local\Temp\pip-install-k1eo64gl\fbprophet
Complete output (42 lines):
running install
running build
running build_py
creating build
creating build\lib
creating build\lib\fbprophet
creating build\lib\fbprophet\stan_models
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\HP\AppData\Local\Temp\pip-install-k1eo64gl\fbprophet\setup.py", line 126, in
"""
File "c:\python37\lib\site-packages\setuptools_init_.py", line 145, in setup
return distutils.core.setup(**attrs)
File "c:\python37\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "c:\python37\lib\distutils\dist.py", line 966, in run_commands
self.run_command(cmd)
File "c:\python37\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "c:\python37\lib\site-packages\setuptools\command\install.py", line 61, in run
return orig.install.run(self)
File "c:\python37\lib\distutils\command\install.py", line 545, in run
self.run_command('build')
File "c:\python37\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "c:\python37\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "c:\python37\lib\distutils\command\build.py", line 135, in run
self.run_command(cmd_name)
File "c:\python37\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "c:\python37\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\HP\AppData\Local\Temp\pip-install-k1eo64gl\fbprophet\setup.py", line 46, in run
build_stan_models(target_dir)
File "C:\Users\HP\AppData\Local\Temp\pip-install-k1eo64gl\fbprophet\setup.py", line 28, in build_stan_models
from pystan import StanModel
File "c:\python37\lib\site-packages\pystan_init_.py", line 9, in
from pystan.api import stanc, stan
File "c:\python37\lib\site-packages\pystan\api.py", line 13, in
import pystan._api # stanc wrapper
ImportError: DLL load failed: The specified module could not be found.
----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\python37\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\HP\AppData\Local\Temp\pip-install-k1eo64gl\fbprophet\setup.py'"'"'; file='"'"'C:\Users\HP\AppData\Local\Temp\pip-install-k1eo64gl\fbprophet\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\HP\AppData\Local\Temp\pip-record-4c8jwmk6\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\python37\Include\fbprophet' Check the logs for full command output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants