【问题标题】:Multiple Regression in Python (with Factor Selection)Python 中的多重回归(带因子选择)
【发布时间】:2016-12-29 05:41:04
【问题描述】:

我读过的关于 Python 中的多重回归的所有线程大多都推荐 Statsmodels 中的 OLS 函数。这是我遇到的问题,我试图通过将其回报与可以解释该基金回报的 14 个自变量进行回归来解释基金的回报(HYFAX 以绿色突出显示)。这应该有一个显着的 F 检验,并在经过因子的逐步迭代后吐出具有最高调整 R 平方的最佳拟合模型。有没有办法在python中做到这一点?

Fund returns vs Factors

【问题讨论】:

    标签: python numpy scikit-learn statistics regression


    【解决方案1】:

    听起来您只是想查看模型拟合的结果。下面是一个带有 1 个预测器的示例,但可以轻松扩展到 14 个:

    导入 statsmodels 并指定您要构建的模型(这是您要包含 14 个预测变量的地方):

    import statsmodels.api as sm
    
    #read in your data however you want and assign your y, x1...x14 variables
    
    model = sm.OLS(x, y)
    

    拟合模型:

    results = model.fit()
    

    现在只需显示您的模型拟合的摘要:

    print(results.summary())
    

    这将为您提供调整后的 R 平方值、F 检验值、β 权重等。应该如下所示:

                                OLS Regression Results                            
    ==============================================================================
    Dep. Variable:                      x   R-squared:                       0.601
    Model:                            OLS   Adj. R-squared:                  0.594
    Method:                 Least Squares   F-statistic:                     87.38
    Date:                Wed, 24 Aug 2016   Prob (F-statistic):           3.56e-13
    Time:                        19:51:25   Log-Likelihood:                -301.81
    No. Observations:                  59   AIC:                             605.6
    Df Residuals:                      58   BIC:                             607.7
    Df Model:                           1                                         
    Covariance Type:            nonrobust                                         
    ==============================================================================
                     coef    std err          t      P>|t|      [95.0% Conf. Int.]
    ------------------------------------------------------------------------------
    y              0.8095      0.087      9.348      0.000         0.636     0.983
    ==============================================================================
    Omnibus:                        0.119   Durbin-Watson:                   1.607
    Prob(Omnibus):                  0.942   Jarque-Bera (JB):                0.178
    Skew:                          -0.099   Prob(JB):                        0.915
    Kurtosis:                       2.818   Cond. No.                         1.00
    ==============================================================================
    

    【讨论】:

      猜你喜欢
      • 2014-03-25
      • 1970-01-01
      • 1970-01-01
      • 2017-12-07
      • 2014-12-11
      • 2019-07-29
      • 2014-07-02
      • 1970-01-01
      • 2016-11-01
      相关资源
      最近更新 更多