s.a*_*ali 3 python scikit-learn deep-learning
I am using balanced_accuracy_score and accuracy_score both in sklearn.metrics.
According to documentation, those two metrics are the same but in my code, the first is giving me 96% and the second one is 97% while accuracy from training is 98%
Can you explain to me what is the difference between the three accuracies and how each is computed?
Note: the problem is a multi-classification problem with three classes.
I have attached code samples.
accuracy is 98%
model.compile(loss='categorical_crossentropy',
optimizer=Adam(lr=0.00001),
metrics=['accuracy'])
Run Code Online (Sandbox Code Playgroud)
accuracy is 96%
from sklearn.metrics import balanced_accuracy_score
balanced_accuracy_score(all_labels, all_predications)
Run Code Online (Sandbox Code Playgroud)
准确率为 97%
from sklearn.metrics import accuracy_score
accuracy_score(all_labels, all_predications)
Run Code Online (Sandbox Code Playgroud)
seu*_*rg1 12
据我了解的问题(不知道什么all_labels,all_predictions)在你OUT之间样本外预测的运行上的差异balanced_accuracy_score以及accuracy_score由前者功能的平衡造成的。
accuracy_score 简单地返回您正确预测的标签百分比(即有 1000 个标签,您准确预测了 980 个,即您获得了 98% 的分数。
balanced_accuracy_score但是工作方式不同,因为它返回每个类的平均准确率,这是一个不同的指标。假设您的 1000 个标签来自 2 个类,其中第 1 类中有 750 个观察值,第 2 类中有 250 个观察值。如果您在每个类中预测错误 10 个,则第 1 类的准确率为 740/750= 98.7%,而 240/250=96第 2 类中的 %balanced_accuracy_score将返回 (98.7%+96%)/2 = 97.35%。因此,我相信根据文档,该程序可以按预期工作。
Accuracy = tp+tn/(tp+tn+fp+fn) 不适用于不平衡的类。
因此我们可以使用平衡精度 = TPR+TNR/2
TPR= 真阳性率 = tp/(tp+fn) :也称为“敏感度”
TNR = 真阴性率 = tn/(tn+fp) :也称为“特异性”
Balanced Accuracy 给出的结果几乎与 ROC AUC Score 相同。
链接:
1 https://en.wikipedia.org/wiki/Precision_and_recall
3 https://scikit-learn.org/stable/modules/generated/sklearn.metrics.roc_auc_score.html
| 归档时间: |
|
| 查看次数: |
5862 次 |
| 最近记录: |