• + 0 comments

    Python 3 solution with comments, taking the formulas from the tutorial:

    n = 5
    X = [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*y for x, y in zip(X,Y))) - (sum(X) * sum(Y))) / (n * sum(x**2 for x in X) - (sum(X)**2))
    
    a = mean_Y - (b * mean_X)
    
    # calculate the predicted y for x = 80
    
    y_predicted = a + (b * 80)
    
    # should come out to # 78.288
    print(round(y_predicted, 3))