scikit-learn-contrib / py-earth

A Python implementation of Jerome Friedman's Multivariate Adaptive Regression Splines
http://contrib.scikit-learn.org/py-earth/
BSD 3-Clause "New" or "Revised" License
455 stars 121 forks source link

NameError: name 'np' is not defined #137

Closed mattdbrown closed 7 years ago

mattdbrown commented 7 years ago

Been trying to use py-earth and this issue keeps popping up, here's a traceback:

Traceback (most recent call last):
  File "analyze.py", line 264, in <module>
    dep.fit_transform(Data[ins].copy()))
  File "/home/mb/pylib/python2.7/site-packages/py_earth-0.1.0-py2.7-linux-x86_64.egg/pyearth/earth.py", line 597, in fit
    self.xlabels_, linvars, skip_scrub=True)
  File "/home/mb/pylib/python2.7/site-packages/py_earth-0.1.0-py2.7-linux-x86_64.egg/pyearth/earth.py", line 712, in forward_pass
    xlabels=self.xlabels_, linvars=linvars, **args)
  File "pyearth/_forward.pyx", line 70, in pyearth._forward.ForwardPasser.__init__ (pyearth/_forward.c:4111)
NameError: name 'np' is not defined

It might be related to another error I'm experiencing - an ImportError that I get the first time I try to import the module. Second time goes through, so I just catch the ImportError the first time, and then import again. Here's a traceback on that.

Traceback (most recent call last):
  File "analyze.py", line 16, in <module>
    import pyearth
  File "/home/mb/pylib/python2.7/site-packages/py_earth-0.1.0-py2.7-linux-x86_64.egg/pyearth/__init__.py", line 8, in <module>
    from .earth import Earth
  File "/home/mb/pylib/python2.7/site-packages/py_earth-0.1.0-py2.7-linux-x86_64.egg/pyearth/earth.py", line 1, in <module>
    from ._forward import ForwardPasser
  File "pyearth/_qr.pxd", line 4, in init pyearth._forward (pyearth/_forward.c:27302)
  File "pyearth/_qr.pyx", line 1, in init pyearth._qr (pyearth/_qr.c:22630)
ImportError: No module named cython_lapack
jcrudy commented 7 years ago

@mattdbrown Thanks for reporting. How are you installing py-earth? I suspect this is an installation issue.

mattdbrown commented 7 years ago

@jcrudy - Installing it exactly as described on the readme, but just used my user library so didn't have to sudo. I have sudo access, but generally prefer to install in my own local python libs directory.

jcrudy commented 7 years ago

@mattdbrown Hmm, it's hard to say what is going on. I'll need more info. Here are a bunch of questions:

  1. Can you give me some details about your system, such as OS and Python version?
  2. What versions of numpy and scipy are you using?
  3. Is there more than one Python installation on your system?
  4. Are you able to import pyearth if you run Python from the command line?
  5. Could you share simple code that reproduces the problem? (I suspect it's not your code that's the problem, but want to make sure.)
  6. Where is the file you're running located relative to the py-earth repo you cloned? And how are you running it?
mattdbrown commented 7 years ago

@jcrudy - Sure!

  1. It's running Ubuntu 14.04.5 LTS, Python 2.7.6
  2. Numpy: 1.11.2 Scipy: 0.13.0
  3. Yeah, there's a Python 3 installation but no other Python 2.7 installs.
  4. I am able to import pyearth from an interactive python session, but I still get the ImportError the first time I do it.
  5. Data is a pandas dataframe, and vars/depvars are dataframe mappers from sklearn_pandas - the issue occurs on the regr.fit command
regr = pyearth.Earth()
regr.fit(vars.fit_transform(Data.copy()),
    depvars.fit_transform(Data.copy()))
  1. The file I'm running is not in the same directory as the python install, it's on a distributed filesystem. The same issue occurs when I run it interactive from the commandline though.
jcrudy commented 7 years ago

@mattdbrown One thing that stands out is that you have a pretty old version of scipy. Are you able to upgrade to a newer version, such as 0.18.1? I think that might at least fix your import problem. Some of the code in pyearth relies on the cython_lapack module of scipy, which wasn't added until I think 0.17.0 or so.

mattdbrown commented 7 years ago

@jcrudy - Ahh, that makes sense, I'll try to update and see if that fixes my issue.

mattdbrown commented 7 years ago

@jcrudy - seems to be working fine on both issues, now. Maybe making that version dependency explicit would be a good thing. Thanks!