直到上周,我有一段代码可以计算出一系列事件发生的几率,但是从本周开始,该代码将不起作用。
代码如下:
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
您能帮助我完成这项工作吗?
答案 0 :(得分:0)
x中的条目是字符串,请将其转换为float:
else { /* name fits, concatenate space and lastName */
strcat (fullName, " ");
strcat (fullName, buf);
available -= length + 1;
break;
}
这首先会失败,因为file.csv中的值为“ NULL”,您需要过滤掉这些值或指定应将其转换为哪种浮点值。
在发布问题之前,请先尝试通过简单的Google搜索来立即获得答案。如果将这个错误与“ pysal 1.14.4”一起使用google搜索,您将立即找到此解决方案: