【问题标题】:Confidence Intervals for Coefficients in Python?Python中系数的置信区间?
【发布时间】:2020-10-06 14:07:55
【问题描述】:

在 R 中,您可以获得逻辑回归中每个系数的置信区间,如下所示 (https://www.r-bloggers.com/example-9-14-confidence-intervals-for-logistic-regression-models/)。

你能在 Python 的 sci-kit learn 中做到这一点吗?我正在探索,但找不到方法。

【问题讨论】:

    标签: python r machine-learning regression


    【解决方案1】:

    我认为你不能从 sci-kit learn 中获得,一种选择是在 python 中使用 statsmodels,这与 R 非常相似:

    import statsmodels.api as sm
    import pandas as pd
    
    df = pd.read_csv("http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data",
                     header=None,names=["s_wid","s_len","p_wid","p_len","species"])
    
    y = np.array(df['species'] == "Iris-virginica").astype(int)
    X = sm.add_constant(df.iloc[:,:4])
    model = sm.Logit(y, X)
    result = model.fit()
    
    result.summary()
    
    Logit Regression Results
    Dep. Variable:  y   No. Observations:   150
    Model:  Logit   Df Residuals:   145
    Method: MLE Df Model:   4
    Date:   Wed, 17 Jun 2020    Pseudo R-squ.:  0.9377
    Time:   00:25:21    Log-Likelihood: -5.9493
    converged:  True    LL-Null:    -95.477
    Covariance Type:    nonrobust   LLR p-value:    1.189e-37
    coef    std err z   P>|z|   [0.025  0.975]
    const   -42.6378    25.708  -1.659  0.097   -93.024 7.748
    s_wid   -2.4652 2.394   -1.030  0.303   -7.158  2.228
    s_len   -6.6809 4.480   -1.491  0.136   -15.461 2.099
    p_wid   9.4294  4.737   1.990   0.047   0.145   18.714
    p_len   18.2861 9.743   1.877   0.061   -0.809  37.381
    

    【讨论】:

      猜你喜欢
      • 2018-07-13
      • 2019-04-30
      • 2015-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-04
      • 2014-04-09
      • 2019-06-28
      相关资源
      最近更新 更多