How do I calculate r-squared using Python and Numpy?

后端 未结 11 1891
春和景丽
春和景丽 2020-11-28 19:29

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

11条回答
  •  死守一世寂寞
    2020-11-28 20:23

    I have been using this successfully, where x and y are array-like.

    def rsquared(x, y):
        """ Return R^2 where x and y are array-like."""
    
        slope, intercept, r_value, p_value, std_err = scipy.stats.linregress(x, y)
        return r_value**2
    

提交回复
热议问题