我使用sklearn运行了一个逻辑回归,使用类似于下面的代码:from pandas import *
from sklearn.feature_extraction.text import CountVectorizer
from sklearn import linear_model
vect= CountVectorizer(binary =True)
a = read_table('text.tsv', sep='\t', index_col=False)
X = vect.fit_transform(c['text'].values)
logreg = linear_model.LogisticRegression(C=1)
d = logreg.fit(X, c['label'])
d.coef_
现在我想将d.coef_u中的值与构成稀疏矩阵X中的行的唯一项相关联。正确的方法是什么?似乎不能让它工作,即使它似乎应该有一个词汇表属性。我得到:
^{pr2}$
更进一步,如果我想得到这些系数的统计显著性和置信区间(沿着R的glm得到的结果),这是可能的吗?e、 g##
## Call:
## glm(formula = admit ~ gre + gpa + rank, family = "binomial",
## data = mydata)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.627 -0.866 -0.639 1.149 2.079
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -3.98998 1.13995 -3.50 0.00047 ***
## gre 0.00226 0.00109 2.07 0.03847 *
## gpa 0.80404 0.33182 2.42 0.01539 *
## rank2 -0.67544 0.31649 -2.13 0.03283 *
## rank3 -1.34020 0.34531 -3.88 0.00010 ***
## rank4 -1.55146 0.41783 -3.71 0.00020 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 499.98 on 399 degrees of freedom
## Residual deviance: 458.52 on 394 degrees of freedom
## AIC: 470.5
##
## Number of Fisher Scoring iterations: 4
本文介绍了如何使用sklearn进行逻辑回归,并探讨如何将模型系数与稀疏矩阵中的特征关联。同时,文章提出了如何获取类似R语言glm函数提供的统计显著性和置信区间的方法。

被折叠的 条评论
为什么被折叠?



