We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
x=[95,85,80,70,60]y=[85,95,70,65,70]sum_x=sum(x)sum_y=sum(y)n=len(x)#orlen(y)b=(n*sum(x[i]*y[i]foriinrange(n)))-(sum_x*sum_y)b/=n*sum(list(map(lambdai:i*i,x)))-sum_x**2# or b /= n * sum(i ** 2 for i in x) - sum_x ** 2mean_x=sum_x/nmean_y=sum_y/na=mean_y-b*mean_xprint(a+b*80)
Cookie support is required to access HackerRank
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 →
Python simple and clean solution: