我正在使用pysal.weights
来计算具有高斯核权重的空间滞后变量('price'),它成功找到了所有最接近的kW.neighbors
,但是有些行没有得到kW.weights
,因此并非所有行都有滞后变量(价格)。
坐标几何或价格列的行均不为nan或零。所以我不确定出了什么问题。
错误如下:
/Users/xxx/miniconda3/lib/python3.6/site-packages/libpysal/weights/distance.py:645: RuntimeWarning: invalid value encountered in true_divide
zi = np.array([dict(list(zip(ni, di)))[nid] for nid in nids]) / bw[i]
/Users/xxx/miniconda3/lib/python3.6/site-packages/libpysal/weights/weights.py:171: UserWarning: The weights matrix is not fully connected. There are 796 components
warnings.warn("The weights matrix is not fully connected. There are %d components" % self.n_components)
/Users/xxx/miniconda3/lib/python3.6/site-packages/libpysal/weights/weights.py:171: UserWarning: The weights matrix is not fully connected. There are 796 components
warnings.warn("The weights matrix is not fully connected. There are %d components" % self.n_components)
代码如下:
lag_vars=['price']
kW = lp.weights.Kernel.from_dataframe(df.loc[:,lag_vars+['geometry']], fixed=False, function='gaussian', k=10)
kW = fill_diagonal(kW, 0)
kW.transform = 'r'
WX = lp.weights.lag_spatial(kW, df.loc[:,lag_vars])
WXtable = pd.DataFrame(WX, columns=['lag_{}'.format(name) for name in lag_vars])
fd_lag = pd.concat((df,WXtable),axis=1)