>> 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).