You are viewing a single comment's thread. Return to all comments →
import statistics import math X = [95, 85, 80, 70, 60] Y = [85, 95, 70, 65, 70] mean_x = statistics.mean(X) mean_y = statistics.mean(Y) diff_x = 0 diff_y = 0 for i in range(len(X)): diff_x += pow(X[i] - mean_x, 2) diff_y += pow(Y[i] - mean_y, 2) stand_dev_x = math.sqrt(1 / len(X) * diff_x) stand_dev_y = math.sqrt(1 / len(Y) * diff_x) sum = 0 for i in range(len(X)): sum += ((X[i] - mean_x) / stand_dev_x ) * ((Y[i] - mean_y) / stand_dev_y) r = 1 / len(X) * sum b = r * stand_dev_y / stand_dev_x a = mean_y - b * mean_x answer = a + b * 80 print(round(answer, 3))
Seems like cookies are disabled on this browser, please enable them to open this website
Day 8: Least Square Regression Line
You are viewing a single comment's thread. Return to all comments →