get the R^2 value from scipy.linalg.lstsq

余生长醉 提交于 2019-12-03 17:12:58
etna

Following http://en.wikipedia.org/wiki/Coefficient_of_determination:

B = data[:,2]

SStot = ((B - B.mean())**2).sum()
SSres = ((B - np.dot(A,C))**2).sum()
R2 = 1 - SSres / SStot

As noted in the Wikipedia article, R2 has a lot of shortcomings. To the best of my knowledge, scipy/numpy compare poorly to a library like statsmodels.

If you want to run multivariate regressions as you need to compute ex-post estimated coefficient standard errors, t-stats, p-values and so on and so forth if you want to know what's going on in your data.

There are plenty of posts dedicated to running OLS with Python so just pick one e.g.: http://www.datarobot.com/blog/ordinary-least-squares-in-python/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!