[英]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. 我在调用confusion_matrix
时似乎遇到错误,请参阅下文。 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. 无论normalisedArr_y5
和predicted5
应np.arrays或列表。 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 1确保两个值都是@Roelant指定的np数组或列表
2 do not assign to your variable's name the same name as the function name 2不要为变量的名称指定与函数名称相同的名称
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 因此,只需检查两个数据帧变量是否相同(此处为df
)并再次执行步骤@ Garch2017
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.