使用python提取回归系数

Using python to extract regression coefficients

我在 python 中执行泊松回归,然后执行 poisson.fit().summary 以获得以下输出:

poisson.fit().summary()
<class 'statsmodels.iolib.summary.Summary'>
"""
                 Generalized Linear Model Regression Results                  
==============================================================================
Dep. Variable:                    Y   No. Observations:                   28
Model:                            GLM   Df Residuals:                       26
Model Family:                 Poisson   Df Model:                            1
Link Function:                    log   Scale:                          1.0000
Method:                          IRLS   Log-Likelihood:            -1.5464e+07
Date:                Wed, 13 Feb 2019   Deviance:                   3.0928e+07
Time:                        19:54:52   Pearson chi2:                 4.43e+07
No. Iterations:                     6   Covariance Type:             nonrobust
==============================================================================
                 coef    std err          z      P>|z|      [0.025      0.975]
------------------------------------------------------------------------------
Intercept     12.8383      0.000   2.95e+04      0.000      12.837      12.839
x            0.0094   1.11e-05    848.646      0.000       0.009       0.009
==============================================================================

但是,我的问题是,如何分别提取截距和X值?

我尝试了 poisson.params(如之前帖子中的建议),但它似乎对我不起作用。我收到这样的错误

*** AttributeError: 'GLM' object has no attribute 'params'

我希望每个系数都存储在单独的变量中:

Intercept =  12.8383
X = 0.0094

这可能吗?

Doe 没有代码,很难说为什么你会得到你所看到的行为?

这是一个完整的示例代码。

import numpy as np
import pandas as pd

import statsmodels.api as sm
import statsmodels.formula.api as smf


df = pd.DataFrame(np.random.randint(100, size=(50,2)))
df.rename(columns={0:'X1', 1:'X2'}, inplace=True)

# GLM Model

model = smf.glm("X2 ~ X1", data=df, family= sm.families.Poisson()).fit()

print(model.summary())
print(model.params)


# Poisson Model

poisson = smf.poisson("X2 ~ X1", data=df).fit()
print (poisson.summary())
print (poisson.params)