如何绘制statsmodels多变量OLS回归

时间:2018-03-09 17:15:03

标签: pandas dataframe plot regression

我有一些看起来像这样的OLS结果:

                            OLS Regression Results                            
==============================================================================
Dep. Variable:     dependent_variable   R-squared:                       0.364
Model:                            OLS   Adj. R-squared:                  0.328
Method:                 Least Squares   F-statistic:                     10.09
Date:                Fri, 09 Mar 2018   Prob (F-statistic):           4.74e-20
Time:                        12:11:10   Log-Likelihood:                 210.15
No. Observations:                 299   AIC:                            -386.3
Df Residuals:                     282   BIC:                            -323.4
Df Model:                          16                                         
Covariance Type:            nonrobust                                         
==============================================================================
                 coef    std err          t      P>|t|      [0.025      0.975]
------------------------------------------------------------------------------
const         -1.4285      0.543     -2.629      0.009      -2.498      -0.359
SIM            0.0481      0.021      2.290      0.023       0.007       0.090
OIL            0.0902      0.080      1.124      0.262      -0.068       0.248
DEF           -0.0890      0.098     -0.907      0.365      -0.282       0.104
PE            -2.8715      0.638     -4.500      0.000      -4.128      -1.615
VRP           -0.6240      0.079     -7.866      0.000      -0.780      -0.468
CAPE          -2.5268      0.502     -5.035      0.000      -3.515      -1.539
BM             1.0856      0.291      3.730      0.000       0.513       1.659
CAY           -0.1232      0.036     -3.411      0.001      -0.194      -0.052
BDI            0.0533      0.070      0.766      0.444      -0.084       0.190
DP             1.5659      0.316      4.957      0.000       0.944       2.188
MA            -0.0518      0.077     -0.675      0.500      -0.203       0.099
NOS           -0.0847      0.048     -1.778      0.076      -0.179       0.009
PCAval         5.4010      1.117      4.834      0.000       3.202       7.600
CPI           -0.0837      0.075     -1.118      0.264      -0.231       0.064
BY            -0.1682      0.061     -2.779      0.006      -0.287      -0.049
TERM           0.0871      0.045      1.951      0.052      -0.001       0.175
==============================================================================
Omnibus:                        4.654   Durbin-Watson:                   1.904
Prob(Omnibus):                  0.098   Jarque-Bera (JB):                4.401
Skew:                           0.289   Prob(JB):                        0.111
Kurtosis:                       3.134   Cond. No.                         458.
==============================================================================

我想为这个回归生成一个很好的情节,但是我不确定是否有任何用于绘制多变量回归的库。到目前为止,没有任何工作,我已经尝试了here列出的答案,但没有用。

相关DF看起来像:

             SIM       OIL       DEF        PE       VRP     ERP4M      CAPE  \
SIM     1.000000 -0.050460  0.083599 -0.034125 -0.150744  0.064383  0.020047   
OIL    -0.050460  1.000000 -0.422509  0.037500 -0.043082  0.526773  0.248337   
DEF     0.083599 -0.422509  1.000000  0.621826  0.200023 -0.574159 -0.787776   
PE     -0.034125  0.037500  0.621826  1.000000  0.151396 -0.004591 -0.624840   
VRP    -0.150744 -0.043082  0.200023  0.151396  1.000000 -0.146723 -0.374840   
ERP4M   0.064383  0.526773 -0.574159 -0.004591 -0.146723  1.000000  0.272633   
CAPE    0.020047  0.248337 -0.787776 -0.624840 -0.374840  0.272633  1.000000   
BM     -0.013919 -0.278438  0.667338  0.425422  0.470390 -0.244372 -0.940337   
CAY    -0.012688 -0.042881  0.423774  0.155665  0.189580 -0.387483 -0.422951   
BDI    -0.059310  0.184701  0.014964  0.175442 -0.096856  0.009685 -0.051522   
DP      0.031967 -0.359831  0.910237  0.749141  0.250744 -0.445332 -0.867026   
MA     -0.011023  0.160401 -0.816400 -0.751237 -0.051251  0.398050  0.598858   
NOS     0.057399 -0.292519  0.501947  0.233667 -0.026792 -0.406684 -0.297782   
PCAval -0.046081  0.433105 -0.294880  0.384547 -0.278818  0.422584  0.463201   
SPX     0.037689  0.366747 -0.245153  0.110772 -0.489112  0.551562  0.103475   
CPI    -0.002426  0.302854 -0.401922 -0.613360 -0.106276 -0.149682  0.539511   
BY      0.028855  0.320562 -0.383879  0.002436 -0.086611  0.419317  0.292955   
TERM    0.025035 -0.025416  0.255060  0.316007  0.346241  0.082039 -0.623297   
ERP1M   0.037997  0.361399 -0.235481  0.117769 -0.477621  0.553413  0.079395 

我想打印每个变量与ERP4M的相关性。

 corr = df.corr(method='pearson').loc[['ERP4M']]
 smg.plot_corr(corr_matrix, xnames=list(corr))
 plt.show()

0 个答案:

没有答案