我正在研究朴素贝叶斯分类器,并且得到了以下数组列表作为对数预测:
predict = [array([-45.73329593, -47.23015876]), array([-56.83024746, -59.20630121]), array([-53.17297542, -55.19852072]), array([-35.67031864, -36.09391906]), array([-65.57891295, -66.81787995]), array([-62.64077968, -64.78048969]), array([-60.44866178, -61.96371683]), array([-46.36333681, -49.33896595]), array([-44.94102615, -46.89321275]), array([-58.67657099, -60.2740146 ]), array([-62.4623459 , -64.55626115])]
我一直在尝试运行:np.argmax(predict, axis = 1)
,以便选择predict
的最大值。我使用argmax
返回相应的索引,但它不断抛出此错误:TypeError: 'list' object is not callable
。为什么会引发该错误?
答案 0 :(得分:0)
预测是list
而不是numpy array
尝试将列表放入numpy数组
>>> predict
[array([-45.73329593, -47.23015876]), array([-56.83024746, -59.20630121]), array([-53.17297542, -55.19852072]), array([-35.67031864, -36.09391906]), array([-65.57891295, -66.81787995]), array([-62.64077968, -64.78048969]), array([-60.44866178, -61.96371683]), array([-46.36333681, -49.33896595]), array([-44.94102615, -46.89321275]), array([-58.67657099, -60.2740146 ]), array([-62.4623459 , -64.55626115])]
>>> type(predict)
<class 'list'>
>>> pred_a = np.array(predict)
>>> type(pred_a)
<class 'numpy.ndarray'>