Why Can't I Import Statsmodels Directly?
Solution 1:
Long answer see http://www.statsmodels.org/stable/importpaths.html
Statsmodels has intentionally mostly empty __init__.py
but has a parallel import collection through the api.py
.
The recommended import for interactive work import statsmodels.api as sm
imports almost all of statsmodels, numpy, pandas and patsy, and large parts of scipy. This is slooow on cold start.
If we want to import just a specific part of statsmodels, then we don't need to import all these extras. Having empty __init__.py
means that we can import just a single module (which of course imports the dependencies of that module).
e.g. from statsmodels.robust.scale import mad
or
import statmodels.robust scale as smscale
smscale.mad(...)
(Small caveat: Some of the very low level imports might not remain always backwards compatible if the internal structure changes. However, the general policy is to deprecate functions over one or two releases while maintaining the old access structure.)
Solution 2:
You can, you just have to import robust
as well:
import statsmodels as sm
import statsmodels.robust
Then:
>>>sm.robust.scale.mad(a)
0.35630934336679576
robust
is a subpackage of statsmodels
, and importing a package does not in general automatically import subpackages (unless the package is written to do so explicitly).
Post a Comment for "Why Can't I Import Statsmodels Directly?"