Created
March 19, 2015 00:31
-
-
Save lettergram/b187112766ad8e5ddebe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def LS(array): | |
sumxy = 0.0 | |
sumx = 0.0 | |
sumy = 0.0 | |
sumxx = 0.0 | |
x = 0 | |
y = 1 | |
for i in range(len(array)): | |
sumxy += (array[i][x] * array[i][y]) | |
sumx += array[i][x] | |
sumy += array[i][y] | |
sumxx += array[i][x]**2 | |
''' m is slope ''' | |
slope = sumxy - ((sumx * sumy) / len(array)) | |
slope /= sumxx - (sumx**2 / len(array)) | |
''' b is the initial starting point ''' | |
initial = (sumy - (slope * sumx)) / len(array) | |
LinearRegression = [] | |
for i in range(len(array)): | |
LinearRegression.append([i, initial + (slope * i)]) | |
return LinearRegression |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment