def classify(self, texts):
vectors = self.dictionary.feature_vectors(texts)
predictions = self.svm.decision_function(vectors)
predictions = np.transpose(predictions)[0]
predictions = predictions / 2 + 0.5
predictions[predictions > 1] = 1
predictions[predictions < 0] = 0
return predictions
错误:
TypeError: 'numpy.float64' object does not support item assignment
发生在以下行:
predictions[predictions > 1] = 1
有人有解决这个问题的想法吗?谢谢!
尝试这个测试代码并注意np.array([1,2,3], dtype=np.float64)
。
看来 self.svm.decision_function(vectors) 返回1d数组而不是二维。
如果将 [1,2,3] 替换为 [[1,2,3], [4,5,6]] 一切都会好的。
import numpy as np
predictions = np.array([1,2,3], dtype=np.float64)
predictions = np.transpose(predictions)[0]
predictions = predictions / 2 + 0.5
predictions[predictions > 1] = 1
predictions[predictions < 0] = 0
Output:
Traceback (most recent call last):
File "D:\temp\test.py", line 7, in <module>
predictions[predictions > 1] = 1
TypeError: 'numpy.float64' object does not support item assignment
那么,你的向量是什么?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)