Giter Club home page Giter Club logo

Comments (11)

cjekel avatar cjekel commented on May 22, 2024 1

You can now manually specify rcond when you initialize pwlf. bf67d7d

I will push pwlf==0.4.3 to pypi shortly.

my_pwlf = pwlf.PiecewiseLinFit(x, y, rcond=-1)

The default is still rcond=None.

from piecewise_linear_fit_py.

cjekel avatar cjekel commented on May 22, 2024

Can you give me the versions of numpy and pwlf?

pwlf.__version__
np.__version__

from piecewise_linear_fit_py.

lk1983823 avatar lk1983823 commented on May 22, 2024

pwlf.version 0.3.3
np.version 1.14.3

from piecewise_linear_fit_py.

cjekel avatar cjekel commented on May 22, 2024

I'll have to create an environment with numpy==1.14.3 later today. I know numpy<1.14 would break because they changed how rcond is handled.

In the meantime is it possible for you to update numpy to at least numpy>=1.15.4 and see if that fixes your problem?

I think the anaconda command within your environment would be

conda update numpy 

Can you run this simple least squares fit? Or do you get the same error?

# https://stackoverflow.com/questions/27128688/how-to-use-least-squares-with-weight-matrix-in-python
import numpy as np
A=np.array([[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,0,0]])
B = np.array([1,1,1,1,1])
W = np.array([1,2,3,4,5])
Aw = A * np.sqrt(W[:,np.newaxis])
Bw = B * np.sqrt(W)
X = np.linalg.lstsq(Aw, Bw, rcond=None)

from piecewise_linear_fit_py.

lk1983823 avatar lk1983823 commented on May 22, 2024

Thank you! By upgrading my numpy to 1.15.4, the problem disappears! 👍

from piecewise_linear_fit_py.

cjekel avatar cjekel commented on May 22, 2024

I'm glad you got it working!

I tried setting up a numpy==0.14.3 environment and couldn't reproduce. I think something was wrong with your numpy build =/


Edit. I should note that I was expecting this error to occur from numpy<=0.14. Perhaps I should I add rcond as an optional parameter in the class...

from piecewise_linear_fit_py.

stklik avatar stklik commented on May 22, 2024

FYI, I keep seeing the same error with the pwlf==0.4.2 and numpy==1.16.2.

Running the code from above produces

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-e4acef74a3ed> in <module>()
      5 Aw = A * np.sqrt(W[:,np.newaxis])
      6 Bw = B * np.sqrt(W)
----> 7 X = np.linalg.lstsq(Aw, Bw, rcond=None)

/opt/conda/lib/python3.6/site-packages/numpy/linalg/linalg.py in lstsq(a, b, rcond)
   1913         work = zeros((lwork,), t)
   1914         results = lapack_routine(m, n, n_rhs, a, m, bstar, ldb, s, rcond,
-> 1915                                  0, work, -1, iwork, 0)
   1916         lwork = int(work[0])
   1917         work = zeros((lwork,), t)

TypeError: must be real number, not NoneType

changing rcond=-1 a suggested here makes it work again.

from piecewise_linear_fit_py.

cjekel avatar cjekel commented on May 22, 2024

@stklik Are you absolute sure that you are running numpy==1.16.2? If so, you should raise an issue on numpy that recommended default of rcond=None does not work with all numpy backends.

Some old discussion on the topic:
numpy/numpy#11015
numpy/numpy#9582


In terms of pwlf, I could make a parameter in __init__ which sets and option for rcond, allowing for backwards compatibility.

from piecewise_linear_fit_py.

stklik avatar stklik commented on May 22, 2024

so, my pip freeze | grep numpy tells me it's 1.16.2.
I'm running inside a Docker image, so I'll try to check if there are any issues with the installations.

I will push pwlf==0.4.3 to pypi shortly.

Thanks, this will certainly solve my problem.

from piecewise_linear_fit_py.

stklik avatar stklik commented on May 22, 2024

@cjekel After further investigation, I am fairly convinced that my issue has to do with the Jupyter dockerstacks and the fact that they use conda to install numpy while pwlf setup triggers a pip install + some access rights issues.
I will investigate and raise it with the people over there if I find out what to do.

PS: Thanks for adding the rcond param, it works for me now, despite "my situation".

--> can be closed from my POV

from piecewise_linear_fit_py.

cjekel avatar cjekel commented on May 22, 2024

Having multiple Python instances is a pain. The pip in your docker setup is probably for the OS's python. I normally run

which pip
which pip3
which pip3.6

to give some idea where the pip files are located. It's possible that one of those is your conda pip. You may have more options... Feel free to email me if you can't seem to get it sorted out.

You can also try

python -m pip install pwlf

to make sure that this Python environment is the same as pip.

If anything rcond adds backwards compatibility for someone stuck on numpy <= 1.14. :)

from piecewise_linear_fit_py.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.