Python+Statasmodels+实现泊松回归+实例+代码

  • 泊松回归,属于地理学以及GIS空间分析常用模型。适合应用于因变量为计数型变量的实例。模型基本知识移步百度,以下为亲测实例代码。一定有错漏,欢迎交流~
# _*_ coding: utf-8 _*_
import pandas as pd
import numpy as np
import statsmodels.api as sm
from statsmodels.formula.api import ols #加载ols模型
from statsmodels.formula.api import poisson
import matplotlib.pyplot as plt

data = pd.read_csv("C:\\变量st.csv")
print(data.head())

y = data['工作日D']
x1 = data['X_NDVI']
x2 = data['X_街景绿化']
x3 = data['X_道路里程']
x4 = data['X_坡度']
x5 = data['X_公交站']
x6 = data['X_地铁站']
x7 = data['X_购物点']
x8 = data['X_混合']

x = np.column_stack((x1, x2, x3, x4, x5, x6, x7, x8))

# possion回归
model = sm.GLM(y,x,family=sm.families.Poisson())
# model=poisson(y,x)
results = model.fit()
print(results.summary())

输出模型结果:

                 Generalized Linear Model Regression Results                  
==============================================================================
Dep. Variable:                   工作日D   No. Observations:                   43
Model:                            GLM   Df Residuals:                       35
Model Family:                 Poisson   Df Model:                            7
Link Function:                    log   Scale:                          1.0000
Method:                          IRLS   Log-Likelihood:            -2.4490e+05
Date:                Sat, 01 Aug 2020   Deviance:                   4.8933e+05
Time:                        17:51:09   Pearson chi2:                 9.94e+05
No. Iterations:                     7                                         
Covariance Type:            nonrobust                                         
==============================================================================
                 coef    std err          z      P>|z|      [0.025      0.975]
------------------------------------------------------------------------------
x1            -0.2752      0.014    -19.714      0.000      -0.303      -0.248
x2             5.4745      0.010    523.050      0.000       5.454       5.495
x3             6.6649      0.011    618.719      0.000       6.644       6.686
x4             4.8497      0.017    282.112      0.000       4.816       4.883
x5             0.9419      0.013     69.895      0.000       0.915       0.968
x6             0.3792      0.010     36.683      0.000       0.359       0.399
x7             0.2701      0.012     22.606      0.000       0.247       0.294
x8             1.4817      0.008    194.155      0.000       1.467       1.497
==============================================================================

你可能感兴趣的:(算法,python,机器学习,数据挖掘)