gpt4 book ai didi

python - 统计模型逻辑回归优势比

转载 作者:行者123 更新时间:2023-12-01 03:54:53 25 4
gpt4 key购买 nike

我想知道如何从 python statsmodels 中拟合的逻辑回归模型中获得优势比。

>>> import statsmodels.api as sm
>>> import numpy as np
>>> X = np.random.normal(0, 1, (100, 3))
>>> y = np.random.choice([0, 1], 100)
>>> res = sm.Logit(y, X).fit()
Optimization terminated successfully.
Current function value: 0.683158
Iterations 4
>>> res.summary()
<class 'statsmodels.iolib.summary.Summary'>
"""
Logit Regression Results
==============================================================================
Dep. Variable: y No. Observations: 100
Model: Logit Df Residuals: 97
Method: MLE Df Model: 2
Date: Sun, 05 Jun 2016 Pseudo R-squ.: 0.009835
Time: 23:25:06 Log-Likelihood: -68.316
converged: True LL-Null: -68.994
LLR p-value: 0.5073
==============================================================================
coef std err z P>|z| [95.0% Conf. Int.]
------------------------------------------------------------------------------
x1 -0.0033 0.181 -0.018 0.985 -0.359 0.352
x2 0.0565 0.213 0.265 0.791 -0.362 0.475
x3 0.2985 0.216 1.380 0.168 -0.125 0.723
==============================================================================
"""
>>>

最佳答案

您可以通过以下方式获得优势比:

np.exp(res.params)

同时获取置信区间 ( source ):

params = res.params
conf = res.conf_int()
conf['Odds Ratio'] = params
conf.columns = ['5%', '95%', 'Odds Ratio']
print(np.exp(conf))

免责声明:我刚刚整理了对您问题的评论。

关于python - 统计模型逻辑回归优势比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37647396/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com