【问题标题】:Getting accuracy for each category in a multi-label classification problem在多标签分类问题中获取每个类别的准确性
【发布时间】:2021-03-20 04:30:51
【问题描述】:

我需要计算多标签分类问题中每个类别的准确度(而不是整体准确度)。使用 scikit-learn 库中的 classification_report 很容易找到每个类别的准确率、召回率和 F 分数。共有13个类别分布如下:

                   precision    recall  f1-score   support

     Category 1       0.58      0.48      0.53       244
     Category 2       0.91      0.85      0.88       728
     Category 3       0.90      0.92      0.91      1319
     Category 4       0.70      0.55      0.62       533
     Category 5       1.00      0.10      0.18        20
     Category 6       0.94      0.84      0.89      2038
     Category 7       0.83      0.78      0.80      1930
     Category 8       0.85      0.44      0.58       113
     Category 9       0.88      0.87      0.87      1329
     Category 10      0.79      0.54      0.64        61
     Category 11      0.81      0.77      0.79       562
     Category 12      0.71      0.62      0.66       416
     Category 13      0.76      0.60      0.67       500

      micro avg       0.86      0.78      0.82      9793
      macro avg       0.82      0.64      0.69      9793
   weighted avg       0.85      0.78      0.81      9793
    samples avg       0.86      0.82      0.83      9793

我知道可以通过以下方式找到准确度:Accuracy=(TP+TN)/(TP+TN+FP+FN),但为这个多标签分类问题找到 TPTN 对我来说是个问题。

stackoverflow 上有一个类似的问题Calculating accuracy from precision, recall, f1-score - scikit-learn 但仅适用于二分类问题。

注意: 我曾尝试从 sklearn.metrics 中提取 multilabel_confusion_matrixconfusion_matrix 来提取混淆矩阵,但都给了我相同的以下错误:ValueError: Classification metrics can't handle a mix of multilabel-indicator and continuous-multioutput targets

有什么想法吗?

【问题讨论】:

  • 您可以创建一个 13 x 13 矩阵并将各个指标计算为一个与休息
  • 请改用multilabel_confusion_matrix,并用结果更新您的问题。

标签: python machine-learning classification data-science


【解决方案1】:

检查每个标签的公式的准确性。在多标签分类器中,您可以找到每个标签(类)的准确度和每个实例的准确度。

【讨论】:

    【解决方案2】:

    您可以使用以下代码从原始数组中手动​​计算每个类别的准确度:

    class_accuracies = []
    for class_ in np.unique(y_true):
        class_acc = np.mean(y_pred[y_true == class_] == class_)
        class_acuracies.append(class_acc)
    

    【讨论】:

      猜你喜欢
      • 2017-12-03
      • 1970-01-01
      • 2019-11-18
      • 2020-08-14
      • 1970-01-01
      • 2018-05-25
      • 2017-02-07
      • 2022-11-05
      • 2013-01-01
      相关资源
      最近更新 更多