Jam*_*mes 5 python statistics scipy statsmodels
当我尝试OLS适合这两个库时,我得到不同的r ^ 2值(确定系数),我无法弄清楚原因.(为方便起见,删除了一些间距)
In [1]: import pandas as pd
In [2]: import numpy as np
In [3]: import statsmodels.api as sm
In [4]: import scipy.stats
In [5]: np.random.seed(100)
In [6]: x = np.linspace(0, 10, 100) + 5*np.random.randn(100)
In [7]: y = np.arange(100)
In [8]: slope, intercept, r, p, std_err = scipy.stats.linregress(x, y)
In [9]: r**2
Out[9]: 0.22045988449873671
In [10]: model = sm.OLS(y, x)
In [11]: est = model.fit()
In [12]: est.rsquared
Out[12]: 0.5327910685035413
Run Code Online (Sandbox Code Playgroud)
这里发生了什么?我想不出来!某处有错误吗?
| 归档时间: |
|
| 查看次数: |
2508 次 |
| 最近记录: |