Python sklearn - how to calculate p-values

前端 未结 2 1632
再見小時候
再見小時候 2020-12-28 08:56

This is probably a simple question but I am trying to calculate the p-values for my features either using classifiers for a classification problem or regressors for regressi

2条回答
  •  暖寄归人
    2020-12-28 09:31

    You can use statsmodels

    import statsmodels.api as sm
    logit_model=sm.Logit(y_train,X_train)
    result=logit_model.fit()
    print(result.summary())
    

    The results would be something like this

                               Logit Regression Results                           
    ==============================================================================
    Dep. Variable:                      y   No. Observations:               406723
    Model:                          Logit   Df Residuals:                   406710
    Method:                           MLE   Df Model:                           12
    Date:                Fri, 12 Apr 2019   Pseudo R-squ.:                0.001661
    Time:                        16:48:45   Log-Likelihood:            -2.8145e+05
    converged:                      False   LL-Null:                   -2.8192e+05
                                            LLR p-value:                8.758e-193
    ==============================================================================
                     coef    std err          z      P>|z|      [0.025      0.975]
    ------------------------------------------------------------------------------
    x1            -0.0037      0.003     -1.078      0.281      -0.010       0.003
    

提交回复
热议问题