ImportError: No module named compat [ from statsmodels.compat import lmap ] #1868

Closed
pinjutien opened this Issue Aug 4, 2014 · 15 comments

Projects

None yet

3 participants

@pinjutien

Hello,

I have an import issue when I try to use robust regression.
The error, "ImportError: No module named compat", shows up when "from statsmodels.compat import lmap". I can not find the solution by searching "ImportError: No module named compat ".

Can anyone help me here? Thanks!

Mac: 10.6.8
python: Python 2.7.6 -- 64-bit
numpy: 1.8.1
scipy: 0.12.0

@jseabold
Member
jseabold commented Aug 4, 2014

How did you install? What is the output of

import statsmodels.api as sm
sm.show_versions()
@pinjutien

I installed it by
pip install statsmodels

Here they are.

import statsmodels.api as sm

sm.show_versions()

INSTALLED VERSIONS

Python: 2.7.6.final.0
OS: Darwin 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:32:41 PDT 2011; root:xnu-1504.15.3~1/RELEASE_X86_64 x86_64
byteorder: little
LC_ALL: None
LANG: None

Statsmodels

Installed: 0.5.0 (/Users/pin-jutien/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/statsmodels)

Required Dependencies

cython: Not installed
numpy: 1.8.1 (/Users/pin-jutien/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy-1.8.1-py2.7-macosx-10.6-x86_64.egg/numpy)
scipy: 0.12.0 (/Users/pin-jutien/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/scipy)
pandas: 0.14.1 (/Users/pin-jutien/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas)
dateutil: 2.2 (/Users/pin-jutien/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/dateutil)
patsy: 0.3.0 (/Users/pin-jutien/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/patsy-0.3.0-py2.7.egg/patsy)

Optional Dependencies

matplotlib: 1.3.0 (/Users/pin-jutien/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib)
cvxopt: Not installed

Developer Tools

IPython: 1.2.1 (/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7/site-packages/IPython)
jinja2: 2.6 (/Users/pin-jutien/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/jinja2)
sphinx: Not installed
pygments: 1.6 (/Users/pin-jutien/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pygments)
nose: 1.2.1 (/Users/pin-jutien/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/nose)
virtualenv: Not installed
import statsmodels.api as sm

sm.show_versions()

INSTALLED VERSIONS

Python: 2.7.6.final.0
OS: Darwin 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:32:41 PDT 2011; root:xnu-1504.15.3~1/RELEASE_X86_64 x86_64
byteorder: little
LC_ALL: None
LANG: None

Statsmodels

Installed: 0.5.0 (/Users/pin-jutien/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/statsmodels)

Required Dependencies

cython: Not installed
numpy: 1.8.1 (/Users/pin-jutien/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy-1.8.1-py2.7-macosx-10.6-x86_64.egg/numpy)
scipy: 0.12.0 (/Users/pin-jutien/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/scipy)
pandas: 0.14.1 (/Users/pin-jutien/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas)
dateutil: 2.2 (/Users/pin-jutien/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/dateutil)
patsy: 0.3.0 (/Users/pin-jutien/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/patsy-0.3.0-py2.7.egg/patsy)

Optional Dependencies

matplotlib: 1.3.0 (/Users/pin-jutien/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib)
cvxopt: Not installed

Developer Tools

IPython: 1.2.1 (/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7/site-packages/IPython)
jinja2: 2.6 (/Users/pin-jutien/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/jinja2)
sphinx: Not installed
pygments: 1.6 (/Users/pin-jutien/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pygments)
nose: 1.2.1 (/Users/pin-jutien/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/nose)
virtualenv: Not installed

@jseabold
Member
jseabold commented Aug 4, 2014

Can you also give the full traceback of the import error?

@jseabold
Member
jseabold commented Aug 4, 2014

There's some version conflict/installation error here. I don't believe
that import should happen in any 0.5.0 code. I'd delete that full
installation directory and re-install either using pip or building
from source.

@pinjutien

here is my full import error:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7/site-packages/IPython/utils/py3compat.pyc in execfile(fname, *where)
    202             else:
    203                 filename = fname
--> 204             __builtin__.execfile(filename, *where)

/Users/pin-jutien/Desktop/Event Driven/pjt_strategy.py in <module>()
      2 
      3 from __future__ import print_function
----> 4 from statsmodels.compat import lmap
      5 import numpy as np
      6 from scipy import stats

ImportError: No module named compat 
@jseabold
Member
jseabold commented Aug 4, 2014

What is pjt_strategy.py? You said you get the error on trying to import statsmodels. Can you show the traceback from importing statsmodels?

@pinjutien

pjt_strategy.py is the file including those import lines.
I think here is the one you asked.

from statsmodels.compat import lmap

ImportError Traceback (most recent call last)
in ()
----> 1 from statsmodels.compat import lmap

ImportError: No module named compat

@jseabold
Member
jseabold commented Aug 4, 2014

Yes, but that's your code presumably? Why are you trying to import that? It doesn't exist in 0.5.0, so if you try to import it you're going to get an error. Is there an error message from statsmodels itself? If not, this doesn't sound like a statsmodels issue.

@josef-pkt
Member

There is no statsmodels.compat in statsmodels 0.5. It's name was compatnp .
Compat is the new name in master since we have the common py2 py3 code base.

Some files are mixed up, using code for the master version with an 0.5 install.

@pinjutien

The reason I import those is that I would like to use robust regression in statsmodels (http://statsmodels.sourceforge.net/devel/examples/notebooks/generated/robust_models_1.html).
Now, I know it is not statsmodels issue. Thanks.
But, I still want to know how to use robust regression in statsmodels.
I do not know what you mean "using code for the master version with an 0.5 install."
Can you say more about this? Thanks a lot!

@jseabold
Member
jseabold commented Aug 4, 2014

That line is just so that notebook will run with statsmodels master on
Python 2.x and 3.x. You can just ignore it and use map as usual.

@josef-pkt
Member

@pinjutien The link to robust models is for the documentation of the devel version (i.e. master).
The stable documentation is here http://statsmodels.sourceforge.net/stable/examples/generated/example_rlm.html

The documentation for devel has been much improved, and it can still be useful when working with the 0.5 version, for example there were not many changes to RLM.
However, there are changes and new features in all parts and then the examples from the new documentation need to be adjusted (and some features will not be available.)

You could also install the devel version (which requires cython to build and install from a git checkout)

@pinjutien

Thanks for those information. So far, it is sufficient for me to learn and use robust regression based on above suggestions.
In addition, is there an "explicit" manual file for this?
For example, if I would like to know the definition of H1 covariance matrix, I can go to "statsmodels.robust.robust_linear_model.RLM" (http://statsmodels.sourceforge.net/stable/_modules/statsmodels/robust/robust_linear_model.html#RLM.score) to look at it. I mean is it the only way I can do to get all those definition in the code?
I try to find those reference, likes PJ Huber. 'Robust Statistics' John Wiley and Sons, Inc., New York. 1981. I can not find H1 definition. Of course, it may be in the other references.

Sorry to keep bother you guys. Thanks.

@josef-pkt
Member

In addition, is there an "explicit" manual file for this?

No, not yet. We don't have any book that would explain the statistics underlying the different functions, or the math for it.

I went through RLM and other robust estimators a few months ago, In terms of formulas, the SAS manual is pretty good, it provides a good basic summary, and methods similar to ours. (I was working on more robust methods some of which are in SAS but not yet in statsmodels.)

But for example for the derivation of the robust covariance, I was reading an article of Huber from the 1970s, because most books just mention the formulas, and show the general theory.
(Essentially, the robust covariance are the standard sandwich form for M-estimators, but Huber added a correction factor that should make it better in small samples, and is based on an asymptotics when also the number of regressors increases with the sample size.)

@josef-pkt
Member

There is nothing to do here. Closing

@josef-pkt josef-pkt closed this Aug 16, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment