我想知道如何计算多类多标签分类中的精度和召回率,即存在多个标签且每个实例可以有多个标签的分类?
我想知道如何计算多类多标签分类中的精度和召回率,即存在多个标签且每个实例可以有多个标签的分类?
对于多标签分类,您有两种选择。首先考虑以下内容。
度量指标以每个数据点的方式计算。对于每个预测标签,仅计算其分数,然后将这些分数汇总到所有数据点中。
还有其他指标。
这里分别表示仅针对
标签 的真正例数、假正例数、真负例数和假负例数。请保留HTML标签。
这里$B$代表混淆矩阵基于的任何指标。在您的情况下,您将插入标准精度和召回率公式。对于宏平均值,您传递每个标签计数,然后进行求和;对于微平均值,您首先平均计数,然后应用您的指标函数。
你可能会对多标签度量中的代码感兴趣,它是这里的一部分,属于mldr包在R中。此外,您可能还想查看Java多标签库MULAN。(precision(A) + precision(B) + precision(C)) / 3
同样适用于召回率。
我不是专家,但根据以下来源,这是我所确定的:
https://list.scms.waikato.ac.nz/pipermail/wekalist/2011-March/051575.html http://stats.stackexchange.com/questions/21551/how-to-compute-precision-recall-for-multiclass-multilabel-classification
Now, to compute recall for label A you can read off the values from the confusion matrix and compute:
= TP_A/(TP_A+FN_A)
= TP_A/(Total gold labels for A)
Now, let us compute precision for label A, you can read off the values from the confusion matrix and compute:
= TP_A/(TP_A+FP_A)
= TP_A/(Total predicted as A)
You just need to do the same for the remaining labels B and C. This applies to any multi-class classification problem.
这里是一篇完整的文章,介绍了如何计算任何多类别分类问题的精确度和召回率,包括示例。
使用sklearn
和numpy
的Python代码:
from sklearn.metrics import confusion_matrix
import numpy as np
labels = ...
predictions = ...
cm = confusion_matrix(labels, predictions)
recall = np.diag(cm) / np.sum(cm, axis = 1)
precision = np.diag(cm) / np.sum(cm, axis = 0)