472,334 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,334 software developers and data experts.

SciPy - I need an example of use of linalg.lstsq()

And it has to run on Windows, so it can't use xplt.

I would prefer that it use the simplest multi-dimensional model, z = k +
a*x1 + b*x2 + c*x3 + d*x4

Anyone have such a thing?

Thanks,

Mitchell Timin

--
I'm proud of http://ANNEvolve.sourceforge.net. If you want to write software,
or articles, or do testing or research for ANNEvolve, let me know.

Humans may know that my email address is: (but remove the 3 digit number)
zenguy at shaw666 dot ca
May 10 '06 #1
2 9630
I. Myself wrote:
And it has to run on Windows, so it can't use xplt.
Huh?

A. xplt runs on Windows, too.
B. xplt has nothing to do with linalg.lstsq().
C. xplt has been removed from scipy.
I would prefer that it use the simplest multi-dimensional model, z = k +
a*x1 + b*x2 + c*x3 + d*x4


In [1]: import numpy as np

In [2]: np.linalg.lstsq?
Type: function
Base Class: <type 'function'>
String Form: <function lstsq at 0x6d3f30>
Namespace: Interactive
File:
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/numpy-0.9.7.2476-py2.4-macosx-10.4-ppc.egg/numpy/linalg/linalg.py
Definition: np.linalg.lstsq(a, b, rcond=1e-10)
Docstring:
returns x,resids,rank,s
where x minimizes 2-norm(|b - Ax|)
resids is the sum square residuals
rank is the rank of A
s is the rank of the singular values of A in descending order

If b is a matrix then x is also a matrix with corresponding columns.
If the rank of A is less than the number of columns of A or greater than
the number of rows, then residuals will be returned as an empty array
otherwise resids = sum((b-dot(A,x)**2).
Singular values less than s[0]*rcond are treated as zero.
In [3]: z = np.rand(10)

In [4]: x1 = np.rand(10)

In [5]: x2 = np.rand(10)

In [6]: x3 = np.rand(10)

In [7]: x4 = np.rand(10)

In [8]: A = np.column_stack([x1, x2, x3, x4, np.ones(10, float)])

In [9]: A
Out[9]:
array([[ 0.07257264, 0.36544251, 0.68467294, 0.33813333, 1. ],
[ 0.09520828, 0.27102091, 0.04673061, 0.12905473, 1. ],
[ 0.839834 , 0.46010114, 0.3949568 , 0.38983012, 1. ],
[ 0.49776387, 0.70666191, 0.85005579, 0.47738743, 1. ],
[ 0.25457977, 0.93335912, 0.88441593, 0.05255062, 1. ],
[ 0.85982216, 0.97920853, 0.27991214, 0.94230651, 1. ],
[ 0.03224487, 0.1275237 , 0.66943552, 0.320765 , 1. ],
[ 0.86807363, 0.63800103, 0.67153924, 0.69125023, 1. ],
[ 0.26571213, 0.68845408, 0.06478114, 0.03657494, 1. ],
[ 0.46615143, 0.99464106, 0.9303421 , 0.61363703, 1. ]])

In [10]: np.linalg.lstsq(A, z)
Out[10]:
(array([-0.32421087, -0.23330787, 0.13369118, -0.28334431, 0.84010014]),
array([ 0.22958042]),
5,
array([ 4.59505886, 1.1181838 , 0.85704672, 0.70211311, 0.4420187 ]))
If you have more scipy questions, you will probably want to ask on the
scipy-user list:

http://www.scipy.org/Mailing_Lists

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

May 10 '06 #2
Robert Kern wrote:
I. Myself wrote:
And it has to run on Windows, so it can't use xplt.

Huh?

A. xplt runs on Windows, too.
B. xplt has nothing to do with linalg.lstsq().
C. xplt has been removed from scipy.

Thank you. I have been misled by the Scipy Tutorial by Travis
Oliphant. It has an example which uses xplt; it also mentions that xplt
is only for x-windows.

Your example below seems like just what I'm looking for. I will try it out.

Thanks again.

Mitchell Timin
I would prefer that it use the simplest multi-dimensional model, z = k +
a*x1 + b*x2 + c*x3 + d*x4


In [1]: import numpy as np

In [2]: np.linalg.lstsq?
Type: function
Base Class: <type 'function'>
String Form: <function lstsq at 0x6d3f30>
Namespace: Interactive
File:
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/numpy-0.9.7.2476-py2.4-macosx-10.4-ppc.egg/numpy/linalg/linalg.py
Definition: np.linalg.lstsq(a, b, rcond=1e-10)
Docstring:
returns x,resids,rank,s
where x minimizes 2-norm(|b - Ax|)
resids is the sum square residuals
rank is the rank of A
s is the rank of the singular values of A in descending order

If b is a matrix then x is also a matrix with corresponding columns.
If the rank of A is less than the number of columns of A or greater than
the number of rows, then residuals will be returned as an empty array
otherwise resids = sum((b-dot(A,x)**2).
Singular values less than s[0]*rcond are treated as zero.
In [3]: z = np.rand(10)

In [4]: x1 = np.rand(10)

In [5]: x2 = np.rand(10)

In [6]: x3 = np.rand(10)

In [7]: x4 = np.rand(10)

In [8]: A = np.column_stack([x1, x2, x3, x4, np.ones(10, float)])

In [9]: A
Out[9]:
array([[ 0.07257264, 0.36544251, 0.68467294, 0.33813333, 1. ],
[ 0.09520828, 0.27102091, 0.04673061, 0.12905473, 1. ],
[ 0.839834 , 0.46010114, 0.3949568 , 0.38983012, 1. ],
[ 0.49776387, 0.70666191, 0.85005579, 0.47738743, 1. ],
[ 0.25457977, 0.93335912, 0.88441593, 0.05255062, 1. ],
[ 0.85982216, 0.97920853, 0.27991214, 0.94230651, 1. ],
[ 0.03224487, 0.1275237 , 0.66943552, 0.320765 , 1. ],
[ 0.86807363, 0.63800103, 0.67153924, 0.69125023, 1. ],
[ 0.26571213, 0.68845408, 0.06478114, 0.03657494, 1. ],
[ 0.46615143, 0.99464106, 0.9303421 , 0.61363703, 1. ]])

In [10]: np.linalg.lstsq(A, z)
Out[10]:
(array([-0.32421087, -0.23330787, 0.13369118, -0.28334431, 0.84010014]),
array([ 0.22958042]),
5,
array([ 4.59505886, 1.1181838 , 0.85704672, 0.70211311, 0.4420187 ]))
If you have more scipy questions, you will probably want to ask on the
scipy-user list:

http://www.scipy.org/Mailing_Lists

--
I'm proud of http://ANNEvolve.sourceforge.net. If you want to write software,
or articles, or do testing or research for ANNEvolve, let me know.

Humans may know that my email address is: (but remove the 3 digit number)
zenguy at shaw666 dot ca
May 10 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: lawrence | last post by:
I've downloaded and am now studying the Eclipse class libary. It looks very elegant and well done. But as I am somewhat new to OO, I'd like to see...
0
by: Bob | last post by:
I am trying to get a LOGFONT structure from the System::Drawing::Font class using ToLogFont (System::Object*) in a managed C++ application. I need...
5
by: Yogi_Bear_79 | last post by:
I've been playing with the RegistryKey class in the Microsoft.Win32 namespace. I can do various things but I can't seem to get the syntax correct...
2
by: Patrick Blackman | last post by:
Need example of using WinAPI "CreateWindowEx" in c# any help would be appreciated.
0
by: KathyB | last post by:
HI, I've posted this type of question before so please don't be annoyed, but I still need example(s) of how to build dynamic controls and post...
2
by: John Howard | last post by:
Where can I find a good explination and example of using VB.Net/ASP.net to browse an MS Access database using ADO.Net? Thanks in advance, John
4
donilourdu
by: donilourdu | last post by:
hi I am doni I need example for tigger in MySQL database. looking for replies with regards, doni
0
by: =?Utf-8?B?ai5hLiBoYXJyaW1hbg==?= | last post by:
Hi, I'm using MSXML6 in my C++ windows service app. that will be running on Server 2003 (NOT a web server!). I'm new to some of this, so bear...
1
by: pwong | last post by:
Hi. We plan to research/develop a web-application to monitor some data. The plan is to deploy approximately 50 sensors at different location....
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.