简体   繁体   English

分类指标无法处理多类和多标签指标目标的混合

[英]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.

相关问题 如何处理 ValueError:分类指标无法处理多标签指标和多类目标错误的混合 - how to handle ValueError: Classification metrics can't handle a mix of multilabel-indicator and multiclass targets error ValueError:分类指标无法在 ROC 曲线计算中处理多类和多标签指标目标的混合 - ValueError: Classification metrics can't handle a mix of multiclass and multilabel-indicator targets in ROC curve calculation ValueError:分类指标无法处理多类和多标记指标目标的混合 - ValueError: Classification metrics can't handle a mix of multiclass and multilabel-indicator targets 混淆矩阵错误“分类指标无法处理多标签指标和多类目标的混合” - confusion matrix error "Classification metrics can't handle a mix of multilabel-indicator and multiclass targets" 错误:分类指标无法处理多类多输出和多标记指标目标的混合 - Error: Classification metrics can't handle a mix of multiclass-multioutput and multilabel-indicator targets 如何修复 ValueError:分类指标无法处理模型的多类和多标签指标目标的混合? - How to fix ValueError: Classification metrics can't handle a mix of multiclass and multilabel-indicator targets for model? ValueError:分类指标无法处理多标签指标和连续多输出目标错误的混合 - ValueError: Classification metrics can't handle a mix of multilabel-indicator and continuous-multioutput targets error ValueError:分类指标无法处理多标签指标和连续多输出目标的混合 - ValueError: Classification metrics can't handle a mix of multilabel-indicator and continuous-multioutput targets ValueError:分类指标无法处理多标签指标和连续多输出目标 sklearn 的混合 - ValueError: Classification metrics can't handle a mix of multilabel-indicator and continuous-multioutput targets sklearn ValueError:分类指标无法处理多标签指标和二进制目标的混合 - ValueError: Classification metrics can't handle a mix of multilabel-indicator and binary targets
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM