Linear Regression Most Efficient algorithm calc Line of Best Fit
-
I have a group of points that I need to plot on a graph and calculate the line of best fit(Slope and Intercept) in a programming language. for example x 0 1 2 3 4 y 40 41 45 41 47 At the moment I am using and have implemented the Least Squares algorithm here http://en.wikipedia.org/wiki/Least_squares[^] I was wondering whether anyone knows of a computationally more efficient algorithm with close to the same accuracy and be able to explain how the algorithm works? Thanks in advance :)
My blog:[^]
-
I have a group of points that I need to plot on a graph and calculate the line of best fit(Slope and Intercept) in a programming language. for example x 0 1 2 3 4 y 40 41 45 41 47 At the moment I am using and have implemented the Least Squares algorithm here http://en.wikipedia.org/wiki/Least_squares[^] I was wondering whether anyone knows of a computationally more efficient algorithm with close to the same accuracy and be able to explain how the algorithm works? Thanks in advance :)
My blog:[^]
A decent implementation of linear fitting by LSQ should run in O(n) time and O(1) space. One pass over the data, accumulating sum(x), sum(y), sum(x*x) and sum(x*y) then crunch those four (and n) to get the answer. If you're just doing a simple linear fit, DON'T get sucked into all the matrix stuff. Waaaaay overkill. Cheers, Peter [edit]forgot sum(y)[/edit]
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012