添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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

Hi, I am experiencing some strange behavior with model = statsmodels.tsa.arima_model.ARIMA . I am using statsmodels 0.8.0 with Python 2.7.14 on IPython 5.5.0 .

How to replicate :

>> import statsmodels as sm
>> model = sm.tsa.arima_model.ARIMA
AttributeError: 'module' object has no attribute 'tsa'
>> import statsmodels.api as sm
FutureWarning: The pandas.core.datetools module is deprecated and will be removed in a future version. Please use the pandas.tseries module instead.
>> model = sm.tsa.arima_model.ARIMA
AttributeError: 'module' object has no attribute 'arima_model'
>> import statsmodels as sm
>> model = sm.tsa.arima_model.ARIMA  ## works fine now

What is expected:
The import should work in the very first line.

What happened:
To be able to function properly, the import required importing statsmodels.api then overwriting that with importing statsmodels to finally work.

That's a consequence of the python import behavior and our dual import paths
http://www.statsmodels.org/devel/importpaths.html

your can use a version of either of the two ways

  • the api paths which import almost all of statsmodels:
    import statsmodels.api as sm
    sm.tsa.ARIMA
  • use direct import of or from the actual module
    import statsmodels as stm (just a shortcut name, imports almost nothing)
    import statsmodels.tsa.arima_model
    then stm.tsa.arima_model.ARIMA is available
    or simpler
    from statsmodels.tsa.arima_model import ARIMA
  • In the first case you can use tab completion to see what's available.
    In the second case you need to know the actual module path where a function or class is available, and import that.

    The behavior that you see is because after import statsmodels.api as sm (almost) all of statsmodels has been imported (and loaded into memory).