I\'m using Python and Numpy to calculate a best fit polynomial of arbitrary degree. I pass a list of x values, y values, and the degree of the polynomial I want to fit (lin
Here's a very simple python function to compute R^2 from the actual and predicted values assuming y and y_hat are pandas series:
def r_squared(y, y_hat): y_bar = y.mean() ss_tot = ((y-y_bar)**2).sum() ss_res = ((y-y_hat)**2).sum() return 1 - (ss_res/ss_tot)