473,721 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9735
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.framewor k/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.framewor k/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
3047
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 some example code. Documentation is thin, save that generated by PHPdocs. Can anyone show me some sample code? I'm mostly interested in how other people set up their software - what objects call what objects? What are other programmers doing in their web projects? Is it common for people to...
0
1843
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 the LOGFONT for some legacy C++ code. I cannot figure out how to give ToLogFont an Object* of a LOGFONT that it will return me a good GDI LOGFONT structure. Any example of how to do this would be much appreaciated!
5
1496
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 to see if a value or a key exsists. I know I need to use the GetValue & OpenSubKey methods I've been trying variations on these methods with no luck. Can someone give me a working example?
2
9821
by: Patrick Blackman | last post by:
Need example of using WinAPI "CreateWindowEx" in c# any help would be appreciated.
0
1071
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 them back to the xmldocument on the server. I realize the html is client side, so I need to assign (somehow) unique id's within the xsl stylesheet, and I think use response.form collection (?) to submit the <input> textboxes back to the xmlDocument. One sticking point: how to identify and code...
2
1730
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
4180
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
2197
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 with me. I am looking for a means of posting an XML message to a web service that is requiring a client certificate (SSL). I have come across a few items referencing
1
1597
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. Every minute or so depend on the condition of environment; the sensors will collect the data and send them to the server which will put them into the database. We have no problem on this end since it is not involve any web app. Now what we want on the web app is to create a website which allows
0
8858
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9376
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9230
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6678
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5994
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2596
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2146
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.