def r_squared(x, y): """ Return the coeffecient of determination (the squared correlation) of the x, y pairs """ return (covariance(x,y))**2 / float(variance(x)*variance(y))
def least_squares_fit(x, y): """ given training values for x,y computes the least squares values for beta_0 and beta_1""" beta_1 = covariance(x,y)/variance(x) beta_0 = mean(y) - beta_1 * mean(x) return beta_0, beta_1