Traceback (most recent call last):
File "", line 1, in
pre = clf.predict(gen_data)
File "D:\anaconda\lib\site-packages\sklearn\svm\classes.py", line 1121, in predict
y = super(OneClassSVM, self).predict(X)
File "D:\anaconda\lib\site-packages\sklearn\svm\base.py", line 308, in predict
X = self._validate_for_predict(X)
File "D:\anaconda\lib\site-packages\sklearn\svm\base.py", line 439, in _validate_for_predict
X = check_array(X, accept_sparse='csr', dtype=np.float64, order="C")
File "D:\anaconda\lib\site-packages\sklearn\utils\validation.py", line 433, in check_array
array = np.array(array, dtype=dtype, order=order, copy=copy)
ValueError: setting an array element with a sequence.
被这个错误困扰了两天,查了不少博客,大多都说是因为数组元素没对齐,可是我的gen_data数据维度都对的上。
于是我又换了另一组数据试试,结果另一组数据在运行pre = clf.predict(gen_data)的时候就没错,对比两个数据才发现,这个错误是因为数据类型的不一样导致的。能运行成功的数据类型是float64,运行失败的数据类型是float32。所以最后再进行个数据类型转换就好了
gen_data = np.float64(gen_data)