Least squares
From Tech
Revision as of 14:23, 7 March 2013 by 77.72.146.250 (talk) (Created page with " def leastsquares(data): n=len(data)+0.0 avx=sum([d[0] for d in data])/n avy=sum([d[1] for d in data])/n do=[(d[0]-avx, d[1]-avy) for d in data] slope=sum([…")
def leastsquares(data): n=len(data)+0.0 avx=sum([d[0] for d in data])/n avy=sum([d[1] for d in data])/n do=[(d[0]-avx, d[1]-avy) for d in data] slope=sum([d[0]*d[1] for d in do]) / sum([d[0]*d[0] for d in do]) offset=avy-avx*slope return offset, slope #print "avx=", avx #print "avy=", avy #print "slope=", slope #print "offset=", offset