[英]Confidence Intervals for Coefficients in Python?
In R, you can get confidence intervals for each coefficient in a Logistic Regression as shown here ( https://www.r-bloggers.com/example-9-14-confidence-intervals-for-logistic-regression-models/ ).在 R 中,您可以获得逻辑回归中每个系数的置信区间,如下所示( https://www.r-bloggers.com/example-9-14-confidence-intervals-for-logistic-regression-models/ ) .
Can you do this in sci-kit learn in Python?你能在 Python 的 sci-kit 学习中做到这一点吗? I was exploring, but I couldn't find a way.
我正在探索,但我找不到方法。
I don't think you can get that from sci-kit learn, one option is to use statsmodels in python, which is very similar to R:我不认为你可以从 sci-kit 学习中得到,一种选择是在 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.