How can I use sage to fit some points like
x = [1, 3, 4...] y = [1.2, 4.5, 3.6, ...]
to a straight line using method of least squares And make a plot of the points and the line?
Searching in google for "sage least squares" gives three examples as the three top hits. Here is another example: http://sage.cs.drake.edu/home/pub/52/
You can also use scipy to do it: http://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html#least-square-fitting-leastsq
posted Sep 24 '11Jason Grout
3305 ● 7 ● 28 ● 74
In my opinion the easiest way to do the fit is to use the find_fit function, which is standard in SAGE. For example:
When you have a huge number of points and you want just a polynomial fit, I found that it is (numerically) better to use the polyfit function from numpy:
posted Sep 27 '11Joaquim Puig
171 ● 5 ● 9
I didn't find any reference to linear regression in the SAGE reference manual. That means you have to use Maxima directly. Fortunately that's not so difficult.
It's easier if you present the data as a list of pairs (x,y). Try this in a SAGE notebook cell:
You are presented a whole bunch of statistics about the regression. From there on I guess you can manage on your own. Good luck.
posted Sep 25 '11Dirk Danckaert
165 ● 1 ● 9
Asked: Sep 24 '11
Seen: 750 times
Last updated: Sep 27 '11
powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.