简体   繁体   English

关于 sklearn 中的 confusion_matrix()

[英]About confusion_matrix() in sklearn

print(type(prediction))
print(type(np.array(testset_target)))
mat = confusion_matrix(np.array(testset_target),prediction)

output:输出:

<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-ebab29cbd03f> in <module>
     23 print(type(prediction))
     24 print(type(np.array(testset_target)))
---> 25 mat = confusion_matrix(np.array(testset_target),prediction)
     26 confusion_matrix.append(mat)
     27 acc_sco=accuracy_score(prediction,testset_target)

TypeError: 'list' object is not callable

They are both np.ndarray type, but why error said list都是np.ndarray类型,但是为什么报错说list

You assigned confusion_matrix to something (a list).您将confusion_matrix分配给了某物(列表)。 So confusion_matrix does not refer to the Sklearn function anymore, but to a list.所以confusion_matrix不再引用 Sklearn 函数,而是引用一个列表。 So you can't "call" it.所以你不能“调用”它。 What gave it away is this line: confusion_matrix.append(mat) .泄露的是这一行: confusion_matrix.append(mat)

You can solve this problem if you change the name of your list and restart your program.如果更改列表名称并重新启动程序,则可以解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更改混淆矩阵(sklearn)中的值 - Changing values in confusion_matrix (sklearn) 如何从函数内打印sklearn confusion_matrix输出? - How to print sklearn confusion_matrix output from within a function? 使用 sklearn SVC 计算训练集的混淆矩阵 - Calculate confusion_matrix for Training set with sklearn SVC 在sklearn指标confusion_matrix中包括零命中的行和列 - Include rows and columns with zero hits in sklearn metrics confusion_matrix sklearn confusion_matrix: ValueError: 没有足够的值来解压(预期 4,得到 1) - sklearn confusion_matrix: ValueError: not enough values to unpack (expected 4, got 1) 为什么我的 sklearn 混淆矩阵和 plot_confusion_matrix 的值不相等? - Why my values from sklearn confusion_matrix and plot_confusion_matrix are not equal? sklearn混淆_矩阵在错误的位置显示错误的尺寸/刻度线 - sklearn confusion_matrix displaying with wrong dimensions / tick marks at wrong spots 为什么我的 sklearn.metrics chaos_matrix output 看起来是转置的? - Why does my sklearn.metrics confusion_matrix output look transposed? 如何解释sklearn confusion_matrix函数中的labels参数? - How do I interpret the labels argument in the sklearn confusion_matrix function? fusion_matrix() 库给出 ValueError - confusion_matrix() library is giving ValueError
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM