可以用statsmodel.api模块。比如说逻辑回归>>> import statsmodels.api as sm
>>> log_reg = sm.Logit(df['y'], df[['a', 'b', 'c']])
>>> clf = log_reg.fit()
Optimization terminated successfully.
Current function value: 0.692762
Iterations 3
如果要查看系数的p value,调用clf.summary()就可以了,这个方法对OLS回归也是一样的。>>> clf.summary()
Logit Regression Results
Dep. Variable: y No. Observations: 1000
Model: Logit Df Residuals: 997
Method: MLE Df Model: 2
Date: Tue, 17 Oct 2017 Pseudo R-squ.: -0.1341
Time: 10:19:37 Log-Likelihood: -692.76
converged: True LL-Null: -610.86
LLR p-value: 1.000
coef std err z P>|z| [95.0% Conf. Int.]
a 0.1240 0.219 0.565 0.572 -0.306 0.554
b -1.9466 6.245 -0.312 0.755 -14.186 10.293
c 3.7477 6.230 0.602 0.547 -8.463 15.958
SofaSofa数据科学社区DS面试题库 DS面经
×
Warning
您确定要删除本贴么?所有相关回复也会被一并删除并且无法恢复。
取消
确定删除
道画师
2017-10-17 22:26