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.
Python 3 solution with comments, taking the formulas from the tutorial:
n=5X=[95,85,80,70,60]Y=[85,95,70,65,70]mean_X=sum(X)/len(X)mean_Y=sum(Y)/len(Y)# determine the equation parameters for y = a + b*x b=((n*sum(x*yforx,yinzip(X,Y)))-(sum(X)*sum(Y)))/(n*sum(x**2forxinX)-(sum(X)**2))a=mean_Y-(b*mean_X)# calculate the predicted y for x = 80y_predicted=a+(b*80)# should come out to # 78.288print(round(y_predicted,3))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Day 8: Least Square Regression Line
You are viewing a single comment's thread. Return to all comments →
Python 3 solution with comments, taking the formulas from the tutorial: