【问题标题】:ValueError: multilabel-indicator is not supported for confusion matrixValueError:混淆矩阵不支持多标签指示符
【发布时间】:2019-02-12 19:20:34
【问题描述】:

在我的二元分类问题中尝试使用混淆矩阵时遇到此错误。 YYhat 都是 numpy 数组。我已尝试将 .argmax 作为建议的解决方案 - 我不再收到错误,但输出不是我知道的混淆矩阵。

Accuracy: 0.9982449999999999
Accuracy: 0.9983374013937532

shape of y =  (1, 200000)
shape of yhat =  (1, 200000)

错误

 ValueError                                Traceback (most recent call last) <ipython-input-13-ebb660b4585a> in <module>()
     12 print("shape of yhat = ", yhat.shape)
     13 
---> 14 cm = confusion_matrix(y,yhat)
     15 
     16 print("confusion matrix = ", cm)

/anaconda3/lib/python3.6/site-packages/sklearn/metrics/classification.py in confusion_matrix(y_true, y_pred, labels, sample_weight)
    250     y_type, y_true, y_pred = _check_targets(y_true, y_pred)
    251     if y_type not in ("binary", "multiclass"):
--> 252         raise ValueError("%s is not supported" % y_type)
    253 
    254     if labels is None:

ValueError: multilabel-indicator is not supported

【问题讨论】:

  • 嗨!欢迎来到 StackOverflow!我认为如果你有正确的格式,你可以大大改善你的帖子。此外,您应该考虑提供Minimal Complete Verifiable Example (MCVE)
  • 嗨,谢谢。你可以说我是堆栈溢出以及 NN 和 Python 的新手。该代码非常简单,并在错误消息中进行了概述:cm = chaos_matrix(y,yhat)。我在两个熟化的阵列上对其进行了测试,并且有效。但是,不能解决我真正的问题。
  • @SubhashDesai 欢迎使用 Stackoverflow,以后你也应该包含代码

标签: python neural-network


【解决方案1】:

如下添加你的代码

cm = confusion_matrix(y.argmax(axis=1),yhat.argmax(axis=1))

之前问过here

【讨论】:

    猜你喜欢
    • 2018-04-07
    • 2020-01-22
    • 1970-01-01
    • 2018-11-06
    • 2018-01-15
    • 2021-11-11
    • 2021-03-22
    • 2020-07-31
    • 2021-08-15
    相关资源
    最近更新 更多