小编161*_*143的帖子

获取 sklearn 逻辑回归的边际效应

我想从sklearn模型中获得逻辑回归的边际效应

我知道您可以使用“.get_margeff()”获取统计模型逻辑回归的这些信息。sklearn 没有什么东西吗?我想避免自己进行计算,因为我觉得会有很大的错误空间。

import statsmodels.formula.api as sm
from statsmodels.tools.tools import add_constant
from sklearn.datasets import load_breast_cancer
import pandas as pd
import numpy as np

data = load_breast_cancer()
x = data.data
y= data.target
x=add_constant(x,has_constant='add')

model = sm.Logit(y, x).fit_regularized()
margeff = model.get_margeff(dummy=True,count=True)
##print the margal effect
print(margeff.margeff)
>> [ 6.73582136e-02  2.15779589e-04  1.28857837e-02 -1.06718136e-03
 -1.96032750e+00  1.36137385e+00 -1.16303369e+00 -1.37422595e+00
  8.14539021e-01 -1.95330095e+00 -4.86235558e-01  4.84260993e-02
  7.16675627e-02 -2.89644712e-03 -5.18982198e+00 -5.93269894e-01
  3.22934080e+00 -1.28363008e+01  3.07823155e+00  5.84122170e+00
  1.92785670e-02 -9.86284081e-03 -7.53298463e-03 -3.52349287e-04
  9.13527446e-01  1.69938656e-01 -2.89245493e-01 -4.65659522e-01
 -8.32713335e-01 -1.15567833e+00]


# manual …
Run Code Online (Sandbox Code Playgroud)

python statistics scikit-learn statsmodels logistic-regression

6
推荐指数
1
解决办法
3997
查看次数