为什么 sklearn returns 准确率和加权平均在二进制分类中召回相同的值?
Why sklearn returns the accuracy and weighted-average recall the same value in binary classification?
我的问题是二进制分类,我使用以下代码获取 accuracy
和 weighted average recall
。
from sklearn.ensemble import RandomForestClassifier
clf=RandomForestClassifier(random_state = 0, class_weight="balanced")
from sklearn.model_selection import cross_validate
cross_validate(clf, X, y, cv=10, scoring = ('accuracy', 'precision_weighted', 'recall_weighted', 'f1_weighted'))
我注意到 accuracy
和 weighted average recall
的值相等。但是,据我了解,这两个指标涵盖了两个不同的方面,因此,我不清楚为什么它们完全相等。
我发现一个 post 有类似的问题:https://www.researchgate.net/post/Multiclass_classification_micro_weighted_recall_equals_accuracy。但是,我没有发现 post 有用的答案。
如果需要,我很乐意提供更多详细信息。
准确度是:
TP + TN / (P+ N)
因此,假设您有 50 个正面 类 和 50 个负面,并且不知何故这是对您的正面 类 的 25 个正确预测和对您的负面 类 的 25 个正确预测,然后:
25 + 25 / (50+50) = 0.5
加权平均召回率:
第一次回忆:TP/P = 25/50 = 0.5
加权召回率:
(recall_posivite*number_positve)+(recall_negative*number_negative)/(number_positive + number_negativ) = 0.5*50+0.5*50/(50+50) = 50/100 = 0.5
我希望这有助于理解它可能发生!
我的问题是二进制分类,我使用以下代码获取 accuracy
和 weighted average recall
。
from sklearn.ensemble import RandomForestClassifier
clf=RandomForestClassifier(random_state = 0, class_weight="balanced")
from sklearn.model_selection import cross_validate
cross_validate(clf, X, y, cv=10, scoring = ('accuracy', 'precision_weighted', 'recall_weighted', 'f1_weighted'))
我注意到 accuracy
和 weighted average recall
的值相等。但是,据我了解,这两个指标涵盖了两个不同的方面,因此,我不清楚为什么它们完全相等。
我发现一个 post 有类似的问题:https://www.researchgate.net/post/Multiclass_classification_micro_weighted_recall_equals_accuracy。但是,我没有发现 post 有用的答案。
如果需要,我很乐意提供更多详细信息。
准确度是:
TP + TN / (P+ N)
因此,假设您有 50 个正面 类 和 50 个负面,并且不知何故这是对您的正面 类 的 25 个正确预测和对您的负面 类 的 25 个正确预测,然后:
25 + 25 / (50+50) = 0.5
加权平均召回率:
第一次回忆:TP/P = 25/50 = 0.5
加权召回率:
(recall_posivite*number_positve)+(recall_negative*number_negative)/(number_positive + number_negativ) = 0.5*50+0.5*50/(50+50) = 50/100 = 0.5
我希望这有助于理解它可能发生!