首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >绘制Pandas OLS线性回归结果

绘制Pandas OLS线性回归结果
EN

Stack Overflow用户
提问于 2014-03-28 16:22:58
回答 1查看 12.1K关注 0票数 5

对于熊猫的线性回归,我该如何绘制线性回归结果?

代码语言:javascript
复制
import pandas as pd
from pandas.stats.api import ols

df = pd.read_csv('Samples.csv', index_col=0)
control = ols(y=df['Control'], x=df['Day'])
one = ols(y=df['Sample1'], x=df['Day'])
two = ols(y=df['Sample2'], x=df['Day'])

我尝试过plot(),但它不起作用。我想将所有三个样本都绘制在一个图上,在这些摘要的格式中,是否有pandas代码或matplotlib代码来处理hadle数据?

无论如何,结果如下所示:

控制

代码语言:javascript
复制
------------------------Summary of Regression Analysis-------------------------

Formula: Y ~ <x> + <intercept>

Number of Observations:         7
Number of Degrees of Freedom:   2

R-squared:         0.5642
Adj R-squared:     0.4770

Rmse:              4.6893

F-stat (1, 5):     6.4719, p-value:     0.0516

Degrees of Freedom: model 1, resid 5

-----------------------Summary of Estimated Coefficients------------------------
      Variable       Coef    Std Err     t-stat    p-value    CI 2.5%   CI 97.5%
--------------------------------------------------------------------------------
             x    -0.4777     0.1878      -2.54     0.0516    -0.8457    -0.1097
     intercept    41.4621     2.9518      14.05     0.0000    35.6766    47.2476
---------------------------------End of Summary---------------------------------

代码语言:javascript
复制
-------------------------Summary of Regression Analysis-------------------------

Formula: Y ~ <x> + <intercept>

Number of Observations:         6
Number of Degrees of Freedom:   2

R-squared:         0.8331
Adj R-squared:     0.7914

Rmse:              2.0540

F-stat (1, 4):    19.9712, p-value:     0.0111

Degrees of Freedom: model 1, resid 4

-----------------------Summary of Estimated Coefficients------------------------
      Variable       Coef    Std Err     t-stat    p-value    CI 2.5%   CI 97.5%
--------------------------------------------------------------------------------
             x    -0.4379     0.0980      -4.47     0.0111    -0.6300    -0.2459
     intercept    29.6731     1.6640      17.83     0.0001    26.4116    32.9345
---------------------------------End of Summary---------------------------------

代码语言:javascript
复制
-------------------------Summary of Regression Analysis-------------------------

Formula: Y ~ <x> + <intercept>

Number of Observations:         5
Number of Degrees of Freedom:   2

R-squared:         0.8788
Adj R-squared:     0.8384

Rmse:              1.0774

F-stat (1, 3):    21.7542, p-value:     0.0186

Degrees of Freedom: model 1, resid 3

-----------------------Summary of Estimated Coefficients------------------------
      Variable       Coef    Std Err     t-stat    p-value    CI 2.5%   CI 97.5%
--------------------------------------------------------------------------------
             x    -0.2399     0.0514      -4.66     0.0186    -0.3407    -0.1391
     intercept    24.0902     0.9009      26.74     0.0001    22.3246    25.8559
---------------------------------End of Summary---------------------------------
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-29 02:08:23

你可能会发现我的这个问题对Getting the regression line to plot from a Pandas regression很有帮助

我试图找到我的一些代码,用Pandas做一个of图,但我不能找到它,一般来说,你最好使用Statsmodels,它知道Pandas数据结构..因此,过渡并不是太难。然后我的答案和参考的例子会更有意义。

另请参阅:http://nbviewer.ipython.org/gist/dartdog/9008026

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22707534

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档