我正在使用statsmodel中的OLS,链接为https://www.statsmodels.org/stable/examples/notebooks/generated/ols.html

#USD
X = sm.add_constant(USD)
model = sm.OLS(y, X)
results = model.fit()
print(results.summary())
                                 OLS Regression Results
========================================================================================
Dep. Variable:     All Ordinaries closing price   R-squared:                       0.265
Model:                                      OLS   Adj. R-squared:                  0.265
Method:                           Least Squares   F-statistic:                     352.4
Date:                          Tue, 23 Oct 2018   Prob (F-statistic):           2.35e-67
Time:                                  17:30:24   Log-Likelihood:                -8018.8
No. Observations:                           977   AIC:                         1.604e+04
Df Residuals:                               975   BIC:                         1.605e+04
Df Model:                                     1
Covariance Type:                      nonrobust
==============================================================================
                 coef    std err          t      P>|t|      [0.025      0.975]
------------------------------------------------------------------------------
const       1843.1414    149.675     12.314      0.000    1549.418    2136.864
USD         3512.5040    187.111     18.772      0.000    3145.318    3879.690
==============================================================================
Omnibus:                      276.458   Durbin-Watson:                   0.009
Prob(Omnibus):                  0.000   Jarque-Bera (JB):               74.633
Skew:                           0.438   Prob(JB):                     6.22e-17
Kurtosis:                       1.967   Cond. No.                         10.7
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified

您可以在摘要中看到X显示为USD。
但是,添加新变量后
#JPY + USD
X = sm.add_constant(JPY)
X = np.column_stack((X, USD))
model = sm.OLS(y, X)
results = model.fit()
print(results.summary())


 OLS Regression Results
========================================================================================
Dep. Variable:     All Ordinaries closing price   R-squared:                       0.641
Model:                                      OLS   Adj. R-squared:                  0.640
Method:                           Least Squares   F-statistic:                     868.8
Date:                          Tue, 23 Oct 2018   Prob (F-statistic):          2.80e-217
Time:                                  17:39:19   Log-Likelihood:                -7669.4
No. Observations:                           977   AIC:                         1.534e+04
Df Residuals:                               974   BIC:                         1.536e+04
Df Model:                                     2
Covariance Type:                      nonrobust
==============================================================================
                 coef    std err          t      P>|t|      [0.025      0.975]
------------------------------------------------------------------------------
const      -1559.5880    149.478    -10.434      0.000   -1852.923   -1266.253
x1            78.6589      2.466     31.902      0.000      73.820      83.497
x2          -366.5850    178.672     -2.052      0.040    -717.211     -15.958
==============================================================================
Omnibus:                       24.957   Durbin-Watson:                   0.031
Prob(Omnibus):                  0.000   Jarque-Bera (JB):               27.278
Skew:                           0.353   Prob(JB):                     1.19e-06
Kurtosis:                       3.415   Cond. No.                         743.
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.

它没有显示美元和日元,而是x1 x2。有办法解决吗?我尝试谷歌,但一无所获。

最佳答案

由于我的问题全都在乎显示,因此,如果我保留标题,那么问题就解决了,所以我发布解决方案,以防有人遇到相同的问题。

#JPY + USD
X = JPY.join(USD)
X = sm.add_constant(X)
#X = np.column_stack((X, USD))
model = sm.OLS(y, X)
results = model.fit()
print(results.summary())


     OLS Regression Results
========================================================================================
Dep. Variable:     All Ordinaries closing price   R-squared:                       0.641
Model:                                      OLS   Adj. R-squared:                  0.640
Method:                           Least Squares   F-statistic:                     868.8
Date:                          Tue, 23 Oct 2018   Prob (F-statistic):          2.80e-217
Time:                                  22:51:43   Log-Likelihood:                -7669.4
No. Observations:                           977   AIC:                         1.534e+04
Df Residuals:                               974   BIC:                         1.536e+04
Df Model:                                     2
Covariance Type:                      nonrobust
==============================================================================
                 coef    std err          t      P>|t|      [0.025      0.975]
------------------------------------------------------------------------------
const      -1559.5880    149.478    -10.434      0.000   -1852.923   -1266.253
JPY           78.6589      2.466     31.902      0.000      73.820      83.497
USD         -366.5850    178.672     -2.052      0.040    -717.211     -15.958
==============================================================================
Omnibus:                       24.957   Durbin-Watson:                   0.031
Prob(Omnibus):                  0.000   Jarque-Bera (JB):               27.278
Skew:                           0.353   Prob(JB):                     1.19e-06
Kurtosis:                       3.415   Cond. No.                         743.
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.

关于python - 从statsmodels保留摘要中的变量名称,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52942812/

10-12 19:34