为什么sklearn在二进制分类中会返回相同的值,而加权平均召回率相同?

问题描述 投票:0回答:1

我的问题是二进制分类,在其中我使用以下代码来获取accuracyweighted 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'))

我注意到accuracyweighted average recall的值相等。但是,据我了解,这两个指标涵盖了两个不同方面,因此,我不清楚为什么它们完全相等。

[我发现有类似问题的帖子:https://www.researchgate.net/post/Multiclass_classification_micro_weighted_recall_equals_accuracy。但是,我没有发现该帖子的答案有用。

如果需要,我很乐意提供更多详细信息。

python machine-learning scikit-learn classification metrics
1个回答
0
投票

准确度是:

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

我希望这有助于了解它会发生!

© www.soinside.com 2019 - 2024. All rights reserved.