空间回归,“ w必须是pysal.W对象”错误

时间:2019-04-17 08:39:39

标签: python-3.x regression pysal

当我尝试执行空间自动回归分析时,我在权重功能上遇到了麻烦。我曾尝试用KNN创建一个“ w”矩阵,但是当我运行时,我有以下内容;

“ w必须是pysal.W对象”

这是我第一次从事SAR工作。所以我很迷茫。

u = data['X']
v = data['y']
Coordinates = list(zip(u,v))

kd = pysal.lib.cg.kdtree.KDTree(np.array(Coordinates))
w = pysal.lib.weights.KNN(kd, 2)
ag=ps.spreg.ML_Lag(y, X, wnn2)
print (lag.summary)

我该如何解决?

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-81-f18e3bd7bfd8> in <module>
----> 1 ag=ps.spreg.ML_Lag(y, X, wnn2)
      2 print (lag.summary)

~\Anaconda3\envs\projenv\lib\site-packages\pysal\spreg\ml_lag.py in __init__(self, y, x, w, method, epsilon, spat_diag, vm, name_y, name_x, name_w, name_ds)
    544         n = USER.check_arrays(y, x)
    545         USER.check_y(y, n)
--> 546         USER.check_weights(w, y, w_required=True)
    547         x_constant = USER.check_constant(x)
    548         method = method.upper()

~\Anaconda3\envs\projenv\lib\site-packages\pysal\spreg\user_output.py in check_weights(w, y, w_required)
    455             raise Exception("A weights matrix w must be provided to run this method.")
    456         if not isinstance(w, weights.W):
--> 457             raise Exception("w must be a pysal.W object")
    458         if w.n != y.shape[0]:
    459             raise Exception("y must be nx1, and w must be an nxn PySAL W object")

例外:w必须是pysal.W对象

0 个答案:

没有答案