You are viewing a single comment's thread. Return to all comments →
The following code must work but I think the env under the submit is faulty and doesn't let anything but simple print statements to run.
def get_coeff(x,y): x_avg = sum(x)/x.__len__() y_avg = sum(y)/y.__len__() numerator = sum([(a - x_avg)*(b-y_avg) for a,b in zip(x,y)]) denominator = sum([(a - x_avg)**2 for a in x]) return round(numerator/denominator, 3) if __name__ == '__main__': feature_1 = "Physics Scores 15 12 8 8 7 7 7 6 5 3" feature_2 = "History Scores 10 25 17 11 13 17 20 13 9 15" feature_1 = [int(x) for x in input().split() if x.isnumeric()] feature_2 = [int(x) for x in input().split() if x.isnumeric()] print(str(get_coeff(feature_1,feature_2)))
Seems like cookies are disabled on this browser, please enable them to open this website
Correlation and Regression Lines - A Quick Recap #2
You are viewing a single comment's thread. Return to all comments →
The following code must work but I think the env under the submit is faulty and doesn't let anything but simple print statements to run.