簡體   English   中英

繪制熊貓OLS線性回歸結果

[英]Plotting Pandas OLS linear regression results

對於從熊貓進行的線性回歸,我如何繪制線性回歸結果?

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()但是沒有用。 我想在一個繪圖上繪制所有三個樣本,是否有任何熊貓代碼或matplotlib代碼以這些摘要的格式處理數據?

無論如何,結果看起來像這樣:

控制

------------------------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---------------------------------

-------------------------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---------------------------------

-------------------------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---------------------------------

您可能會發現我的問題對您有所幫助從熊貓回歸中繪制回歸線

我試圖找到一些與Pandas一起進行ols繪圖的代碼,但是卻無法付諸實踐,通常來說,使用Statsmodels可能會更好,因為它了解Pandas數據結構..因此過渡不是太難。 然后,我的回答和引用的示例將更有意義。

另請參閱: http : //nbviewer.ipython.org/gist/dartdog/9008026

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM