def get_R2(Y, Y_hat):
    """
    Gets the coefficient of determination R^2.
    """
    diff_Y_Ybar = Y - Y.mean()
    SStotal = diff_Y_Ybar.dot(diff_Y_Ybar)
    diff_Y_Yhat = Y - Y_hat
    SSerr = diff_Y_Yhat.dot(diff_Y_Yhat)
    return 1 - SSerr / float(SStotal)
