简体   繁体   中英

sklearn.metrics.confusion_matrix - TypeError: 'numpy.ndarray' object is not callable

I seem to be getting an error when calling confusion_matrix , please see below. How can I get this to work?

from sklearn.metrics import confusion_matrix
confusion_matrix = confusion_matrix(normalisedArr_y5,predicted5)

Both normalisedArr_y5 and predicted5 should be np.arrays or lists. Apparently one or both are not. You could try:

confusion_matrix = confusion_matrix(normalisedArr_y5.tolist(),predicted5.tolist())

1 Be sure that both values are np arrays or lists as specified by @Roelant
2 do not assign to your variable's name the same name as the function name

from sklearn.metrics import confusion_matrix
cfm = confusion_matrix(normalisedArr_y5,predicted5)
print(cfm)

In my case, I was defining

normalisedArr_x5 = df.iloc[:,:-1]

and

normalisedArr_y5 = data.iloc[:,-1:]

and this Error was coming.

So just check if both the dataframe variables are the same (here df ) and perform the steps again @Garch2017

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