confusion_matrix() 接受 2 个位置参数,但给出了 3 个

confusion_matrix() takes 2 positional arguments but 3 were given

enter image description here

从上图可以看出,这个问题让我很困惑。

labels 不是位置参数而是关键字参数。

因此,您应该按如下方式调用该函数:

from sklearn.metrics import confusion_matrix
confusion_matrix(y_true, y_pred, labels=classes)