[英]Classification metrics can't handle a mix of multiclass and multilabel-indicator targets
here is the snippet of my code:这是我的代码片段:
from mlxtend.plotting import plot_confusion_matrix
from sklearn.metrics import confusion_matrix
y_pred = (model.predict(X_test) > 0.5).astype("int32")
mat = confusion_matrix(y_test, y_pred)
plot_confusion_matrix(conf_mat=mat, class_names=label.classes_, show_normed=True, figsize=(7,7))
I am getting this error on the 4th line "Classification metrics can't handle a mix of multiclass and multilabel-indicator targets" so the confusion matrix is not shown, so anyone could tell me what's wrong on it?我在第 4 行收到此错误“分类指标无法处理多类和多标签指标目标的混合” ,因此未显示混淆矩阵,所以任何人都可以告诉我它有什么问题? Thanks in advance ^^
提前谢谢^^
I think you need to add one more step to your calculations.我认为您需要在计算中再增加一步。 Right now you're doing this:
现在你正在这样做:
y_pred = (model.predict(X_test) > 0.5).astype("int32")
But usually, for binary classification, model.predict(X_test)
produces two values - for class 0 and class 1. You need to take the values for class 1: y_pred = (model.predict(X_test) > 0.5).astype("int32")
But usually, for binary classification, model.predict(X_test)
produces two values - for class 0 and class 1. You need to take the values for class 1:
y_pred = (model.predict(X_test)[:, 1] > 0.5).astype("int32")
After this the confusion matrix should work without errors.在此之后,混淆矩阵应该可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.