Python实现地理加权回归的代码
时间: 2023-11-05 13:07:14 浏览: 145
混合地理加权回归python实现代码
5星 · 资源好评率100%
以下是Python实现地理加权回归的代码:
```python
import numpy as np
import pysal as ps
import statsmodels.api as sm
# 加载数据
db = ps.open('data.dbf', 'r')
y_var = 'crime'
x_vars = ['ind', 'pop']
# 构建空间权重矩阵
w = ps.weights.Queen.from_shapefile('data.shp')
w.transform = 'R'
# 构建地理加权回归模型
model = ps.spreg.GM_Lag(y=db.by_col(y_var), x=db.by_col(x_vars), w=w)
print(model.summary)
```
阅读全文