python - 混淆矩阵错误 'DataFrame' "object is not callable"

标签 python compiler-errors confusion-matrix

我做错了什么?我将两个变量都设置为列表。还尝试了 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/

相关文章:

python - 如何访问从 google books API python 返回的 JSON 对象的值?

java - 为什么在已经声明时处理或声明错误?

python-3.x - 计算混淆矩阵的更快方法?

python - ImportError : libgssapi_krb5. so.2:无法打开共享对象文件:没有这样的文件或目录

Python 斜率(给定两个点找到斜率)-答案有效但无效;

python - 按时间和组划分的 Z 分数

java - 无法覆盖父类(super class)的方法

在 Visual Studio Code 中进行 C 编译

python - 计算用于对象检测的混淆矩阵的正确方法是什么?

matlab - MATLAB 中的plotconfusion 和Confusionmat 函数有什么区别?