简体   繁体   中英

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

You assigned confusion_matrix to something (a list). So confusion_matrix does not refer to the Sklearn function anymore, but to a list. So you can't "call" it. What gave it away is this line: confusion_matrix.append(mat) .

You can solve this problem if you change the name of your list and restart your program.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM