突然间,Probit 无法在 PySAL (1.14.4) 上运行
Suddenly, Probit doesn't work on PySAL (1.14.4)
直到上周,我还有一段代码可以计算一系列事件发生某件事的几率,但从本周开始,这段代码就不起作用了。
代码如下:
import numpy as np
import pysal
import os
dbf = pysal.open('file.csv','r')
y = np.array([dbf.by_col('result')]).T
names_to_extract = ['dist', 'angle']
x = np.array([dbf.by_col(name) for name in names_to_extract]).T
id = np.array([dbf.by_col('incidenceId')]).T
model = pysal.spreg.probit.Probit(y, x, w=None, name_y='result', name_x=['dist','angle'], name_w=None, name_ds=None)
fin = np.column_stack((id, model.y, model.predy))
os.chdir("/destinyfolder")
np.savetxt('xg.csv', fin, delimiter=',', fmt='%d, %d, %f')
我得到这个错误:
/usr/local/lib/python3.7/site-packages/pysal/__init__.py:65: VisibleDeprecationWarning: PySAL's API will be changed on 2018-12-31. The last release made with this API is version 1.14.4. A preview of the next API version is provided in the `pysalnext` package. The API changes and a guide on how to change imports is provided at https://migrating.pysal.org
), VisibleDeprecationWarning)
Traceback (most recent call last):
File "xg.py", line 14, in <module>
model = pysal.spreg.probit.Probit(y, x, w=None, name_y='result', name_x=['dist','angle'], name_w=None, name_ds=None)
File "/usr/local/lib/python3.7/site-packages/pysal/spreg/probit.py", line 807, in __init__
n = USER.check_arrays(y, x)
File "/usr/local/lib/python3.7/site-packages/pysal/spreg/user_output.py", line 359, in check_arrays
if not spu.spisfinite(i):
File "/usr/local/lib/python3.7/site-packages/pysal/spreg/sputils.py", line 267, in spisfinite
return np.isfinite(a.sum())
File "/usr/local/lib/python3.7/site-packages/numpy/core/_methods.py", line 36, in _sum
return umr_sum(a, axis, dtype, out, keepdims, initial)
TypeError: cannot perform reduce with flexible type
通常,我只得到 DeprecationWarning
,但代码有效。从今天开始,代码不起作用。考虑到我目前使用的是 pysal
1.14.4、numpy
1.16.2 和 scipy
1.2.1。我还没有将我的代码更新到 pysal
2.0,因为我无法弄清楚如何将此代码移植到新版本(这就是我首先获得 DeprecationWarning
的原因)。
这是文件:file.csv
你能帮我完成这项工作吗?
你的 x 中的条目是字符串,将它们转换为浮点数:
x = np.array(...).T.astype(np.float)
由于 file.csv 中的 "NULL" 个值,这首先会失败,您需要将它们过滤掉或指定它们应转换为的浮点值。
在发布问题之前,请先尝试简单的 google 搜索以立即获得答案。如果 google 这个错误连同 "pysal 1.14.4",你会立即找到这个解决方案:
TypeError: cannot perform reduce with flexible type
直到上周,我还有一段代码可以计算一系列事件发生某件事的几率,但从本周开始,这段代码就不起作用了。
代码如下:
import numpy as np
import pysal
import os
dbf = pysal.open('file.csv','r')
y = np.array([dbf.by_col('result')]).T
names_to_extract = ['dist', 'angle']
x = np.array([dbf.by_col(name) for name in names_to_extract]).T
id = np.array([dbf.by_col('incidenceId')]).T
model = pysal.spreg.probit.Probit(y, x, w=None, name_y='result', name_x=['dist','angle'], name_w=None, name_ds=None)
fin = np.column_stack((id, model.y, model.predy))
os.chdir("/destinyfolder")
np.savetxt('xg.csv', fin, delimiter=',', fmt='%d, %d, %f')
我得到这个错误:
/usr/local/lib/python3.7/site-packages/pysal/__init__.py:65: VisibleDeprecationWarning: PySAL's API will be changed on 2018-12-31. The last release made with this API is version 1.14.4. A preview of the next API version is provided in the `pysalnext` package. The API changes and a guide on how to change imports is provided at https://migrating.pysal.org
), VisibleDeprecationWarning)
Traceback (most recent call last):
File "xg.py", line 14, in <module>
model = pysal.spreg.probit.Probit(y, x, w=None, name_y='result', name_x=['dist','angle'], name_w=None, name_ds=None)
File "/usr/local/lib/python3.7/site-packages/pysal/spreg/probit.py", line 807, in __init__
n = USER.check_arrays(y, x)
File "/usr/local/lib/python3.7/site-packages/pysal/spreg/user_output.py", line 359, in check_arrays
if not spu.spisfinite(i):
File "/usr/local/lib/python3.7/site-packages/pysal/spreg/sputils.py", line 267, in spisfinite
return np.isfinite(a.sum())
File "/usr/local/lib/python3.7/site-packages/numpy/core/_methods.py", line 36, in _sum
return umr_sum(a, axis, dtype, out, keepdims, initial)
TypeError: cannot perform reduce with flexible type
通常,我只得到 DeprecationWarning
,但代码有效。从今天开始,代码不起作用。考虑到我目前使用的是 pysal
1.14.4、numpy
1.16.2 和 scipy
1.2.1。我还没有将我的代码更新到 pysal
2.0,因为我无法弄清楚如何将此代码移植到新版本(这就是我首先获得 DeprecationWarning
的原因)。
这是文件:file.csv
你能帮我完成这项工作吗?
你的 x 中的条目是字符串,将它们转换为浮点数:
x = np.array(...).T.astype(np.float)
由于 file.csv 中的 "NULL" 个值,这首先会失败,您需要将它们过滤掉或指定它们应转换为的浮点值。
在发布问题之前,请先尝试简单的 google 搜索以立即获得答案。如果 google 这个错误连同 "pysal 1.14.4",你会立即找到这个解决方案:
TypeError: cannot perform reduce with flexible type