Linear regression in NumPy

Discussion in 'Python' started by Jianzhong Liu, Dec 5, 2006.

  1. Hello, Guys,

    I have a question about the linear_least_squares in Numpy.

    My linear_least_squares cannot give me the results.

    I use Numpy1.0. The newest version. So I checked online and get your
    guys some examples.

    I did like this.

    [john@crux 77] ~ >> py
    Python 2.4.3 (#1, May 18 2006, 07:40:45)
    [GCC 3.3.3 (cygwin special)] on cygwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from Numeric import *
    >>> from LinearAlgebra import linear_least_squares
    >>> from Matrix import *
    >>> y = Matrix([[1], [2], [4]])
    >>> x = Matrix([[1, 1], [1, 2], [1, 3]])
    >>> print y

    Matrix([[1],
    [2],
    [4]])
    >>> x

    Matrix([[1, 1],
    [1, 2],
    [1, 3]])
    >>> print linear_least_squares(x, y)


    Here my Numpy stops. and never give me a result. THis is the problem of
    Numpy or sth wrong.

    Can you guys give me a LinearAlgebra.py so that I can have a try?

    Thanks,

    John
     
    Jianzhong Liu, Dec 5, 2006
    #1
    1. Advertising

  2. Jianzhong Liu

    Jon Guest

    > I have a question about the linear_least_squares in Numpy.

    Not quite sure what is going on, it looks like there could be some
    confusion as to linear_least_squares is expecting as an argument of
    some Numeric arrays and what you are supplying (a Matrix) is perhaps
    not close enough to being the same thing.

    Up-to-date versions for all this are all in "numpy" nowadays and the
    numpy mailing list is perhaps a better place to ask:
    http://projects.scipy.org/mailman/listinfo/numpy-discussion

    Anyway, I've pasted in an example using Numeric and LinearAlgebra,
    which you seem to have on your system. They still work fine. Not sure
    what the "Matrix" package is that you are using?

    HTH,

    Jon

    example:

    C:\>python
    Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
    on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from Numeric import *
    >>> from LinearAlgebra import linear_least_squares
    >>> a=array( [[1, 1], [1, 2], [1, 3]] )
    >>> y=array( [ 1,2,4] ) # note 1 D
    >>> a

    array([[1, 1],
    [1, 2],
    [1, 3]])
    >>> y

    array([1, 2, 4])
    >>> linear_least_squares(a,y)

    (array([-0.66666667, 1.5 ]), array([ 0.16666667]), 2, array([
    4.07914333, 0.60049122]))
    >>>


    # Is this what you expect as output???

    Jianzhong Liu wrote:
    > Hello, Guys,
    >
    > I have a question about the linear_least_squares in Numpy.
    >
    > My linear_least_squares cannot give me the results.
    >
    > I use Numpy1.0. The newest version. So I checked online and get your
    > guys some examples.
    >
    > I did like this.
    >
    > [john@crux 77] ~ >> py
    > Python 2.4.3 (#1, May 18 2006, 07:40:45)
    > [GCC 3.3.3 (cygwin special)] on cygwin
    > Type "help", "copyright", "credits" or "license" for more information.
    > >>> from Numeric import *
    > >>> from LinearAlgebra import linear_least_squares
    > >>> from Matrix import *
    > >>> y = Matrix([[1], [2], [4]])
    > >>> x = Matrix([[1, 1], [1, 2], [1, 3]])
    > >>> print y

    > Matrix([[1],
    > [2],
    > [4]])
    > >>> x

    > Matrix([[1, 1],
    > [1, 2],
    > [1, 3]])
    > >>> print linear_least_squares(x, y)

    >
    > Here my Numpy stops. and never give me a result. THis is the problem of
    > Numpy or sth wrong.
    >
    > Can you guys give me a LinearAlgebra.py so that I can have a try?
    >
    > Thanks,
    >
    > John
     
    Jon, Dec 5, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nikie

    Linear regression in NumPy

    nikie, Mar 17, 2006, in forum: Python
    Replies:
    15
    Views:
    13,732
    nikie
    Mar 24, 2006
  2. Replies:
    1
    Views:
    422
    John Machin
    Sep 2, 2006
  3. Robert Kern

    Re: Linear regression in 3 dimensions

    Robert Kern, Sep 2, 2006, in forum: Python
    Replies:
    5
    Views:
    2,362
    David J. Braden
    Sep 15, 2006
  4. Nod Lee

    linear regression in webform

    Nod Lee, Jan 9, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    369
    Cowboy \(Gregory A. Beamer\)
    Jan 9, 2007
  5. Krzysztof Bieniasz

    Re: Non-linear regression help in Python

    Krzysztof Bieniasz, Feb 14, 2011, in forum: Python
    Replies:
    0
    Views:
    617
    Krzysztof Bieniasz
    Feb 14, 2011
Loading...

Share This Page