Linear Regression

This is Linear Regression


x = [15, 9, 12, 1, 10, 11, 4, 16, 2, 30, 4, 15, 18, 12, 14] y = [13 ,19, 16, 15, 24, 7, 18, 23, 28, 2, 26, 12, 18, 24, 17] def DerivativeSlope(x, y, slope, yInt): length = len(x) total = 0 for i in range(length): predicted = (slope * x[i]) + yInt difference = (y[i] - predicted) * x[i] total += difference returnValue = (-2/length) * total return returnValue def DerivativeIntercept(x, y, slope, yInt): length = len(x) total = 0 for i in range(length): predicted = (slope * x[i]) + yInt difference = (y[i] - predicted) total += difference returnValue = (-2/length) * total return returnValue m = 0 c = 0 l = 0.000001 iterations = 99999 for i in range(iterations): slope = DerivativeSlope(x, y, m ,c) intercept = DerivativeIntercept(x, y, m ,c) m = m - (l * slope) c = c - (l * intercept) print (m, c)
1