我做错了什么?我将两个变量都设置为列表。还尝试了 np.array
。
y = list(y_test.values)
yhat = list(predictions)
print(y)
print(yhat)
confusion_matrix = pd.DataFrame(confusion_matrix(y, yhat), columns=["Predicted False", "Predicted True"], index=["Actual False", "Actual True"])
display(confusion_matrix)
输出:
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, ..., 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, ..., 0]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-159-e1640f0e3b13> in <module>()
45 print(yhat)
46
---> 47 confusion_matrix = pd.DataFrame(confusion_matrix(y, yhat), columns=["Predicted False", "Predicted True"], index=["Actual False", "Actual True"])
48 display(confusion_matrix)
49
TypeError: 'DataFrame' object is not callable
不知道这里发生了什么......
最佳答案
你是在笔记本上做的吗?如果是这样,可能 confusion_matrix
方法在您第一次调用它时已被 DataFrame 隐藏。尝试更改变量名并重新启动内核。
关于python - 混淆矩阵错误 'DataFrame' "object is not callable",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50428173/