| 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 or numpy: http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.lstsq.html#numpy.linalg.lstsq |
| 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: |
| 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. |
| I have a feeling that the answer to this ask.sagemath question may also be helpful. It mentions the built-in |
Asked: Sep 24 '11
Seen: 541 times
Last updated: Sep 27 '11
powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.