绘制 Pandas OLS 线性回归结果
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/22707534/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Plotting Pandas OLS linear regression results
提问by ccsv
How would I plot my linear regression results for this linear regression I did from pandas?
我将如何为我从 Pandas 做的这个线性回归绘制我的线性回归结果?
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'])
I tried plot()but it did not work. I want to plot all three samples on one plot are there any pandas code or matplotlib code to hadle data in the format of these summaries?
我试过了,plot()但没有用。我想在一个图上绘制所有三个样本 是否有任何 Pandas 代码或 matplotlib 代码来处理这些摘要格式的数据?
Anyways the results look like this:
无论如何,结果如下所示:
Control
控制
------------------------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---------------------------------
one
一
-------------------------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---------------------------------
two
二
-------------------------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---------------------------------
采纳答案by dartdog
You may find this question of mine helpful Getting the regression line to plot from a Pandas regression
您可能会发现我的这个问题很有帮助从 Pandas 回归中绘制回归线
I tried to find some of my code doing a ols plot with Pandas,, but could not lay my hand on it, In general you would probably be better off using Statsmodels for this, it knows about Pandas datastructures.. so the transition is not too hard. Then my answer and the referenced examples will make more sense..
我试图找到我的一些代码,用 Pandas 做一个 ols 绘图,但无法解决它,总的来说,你最好使用 Statsmodels,它知道 Pandas 数据结构......所以过渡不是太难。然后我的回答和引用的例子会更有意义..

