简体   繁体   English

带有二进制混淆矩阵的sklearns.metrics.classification_report和sklearns.metrics.f1_score中每个F1得分值之间的差异

[英]Differences between each F1-score values in sklearns.metrics.classification_report and sklearns.metrics.f1_score with a binary confusion matrix

I have (true) boolean values and predicted boolean values like: 我有(true)布尔值和预测的布尔值,例如:

y_true = np.array([True, True, False, False, False, True, False, True, True,
       False, True, False, False, False, False, False, True, False,
        True, True, True, True, False, False, False, True, False,
        True, False, False, False, False, True, True, False, False,
       False, True, True, True, True, False, False, False, False,
        True, False, False, False, False, False, False, False, False,
       False, True, True, False, True, False, True, True, True,
       False, False, True, False, True, False, False, True, False,
       False, False, False, False, False, False, False, True, False,
        True, True, True, True, False, False, True, False, True,
        True, False, True, False, True, False, False, True, True,
       False, False, True, True, False, False, False, False, False,
       False, True, True, False])

y_pred = np.array([False, False, False, False, False, True, False, False, True,
       False, True, False, False, False, False, False, False, False,
        True, True, True, True, False, False, False, False, False,
       False, False, False, False, False, True, False, False, False,
       False, True, False, False, False, False, False, False, False,
        True, False, False, False, False, False, False, False, False,
       False, True, False, False, False, False, False, False, False,
       False, False, True, False, False, False, False, True, False,
       False, False, False, False, False, False, False, True, False,
       False, True, False, False, False, False, True, False, True,
        True, False, False, False, True, False, False, True, True,
       False, False, True, True, False, False, False, False, False,
       False, True, False, False])

I'm using the following imports 我正在使用以下导入

from sklearn.metrics import f1_score, classification_report, confusion_matrix

Confusion matrix looks like: 混淆矩阵如下:

print(confusion_matrix(y_true, y_pred))

[[67  0]
 [21 24]]

I'm doing: 我正在做:

print("f1_score: %f" % f1_score(y_true, y_pred))
print(classification_report(y_true, y_pred))

I get: 我得到:

f1_score: 0.695652
             precision    recall  f1-score   support

      False       0.76      1.00      0.86        67
       True       1.00      0.53      0.70        45

avg / total       0.86      0.81      0.80       112

I see 4 values of f1-score ( 0.695652 , 0.86 , 0.70 , 0.80 ). 我看到的4个值f1-score0.6956520.860.700.80 )。 I wonder what are differences between each values and how they are calculated. 我想知道每个值之间的区别是什么以及如何计算它们。

I think that 0.695652 is the same thing with 0.70 . 我认为0.6956520.70是同一回事。 In the scikit-learn f1_score documentation explains that in default mode : F1 score gives the positive class in binary classification. 在scikit-learn中, f1_score 文档解释了在默认模式下:F1分数在二​​进制分类中为positive class

Also you can easily reach the score of 0.86 with the formulation of F1 score. 同样,使用F1得分公式,您可以轻松达到0.86的得分。 The formulation of F1 score is F1分数的公式是

F1 = 2 * (precision * recall) / (precision + recall)

EDIT : 编辑:

Confusion matrix is something like that : 混淆矩阵是这样的:

                    Prediction
                    FALSE | TRUE
True Value  FALSE    67      0
            TRUE     21      24

67 = True Negative, 0 = False Negative
21 = False Positive, 24  = True Positive

In finding the avg / total, formula uses this values like you said in the comment. 在查找平均/总计时,公式将使用您在注释中所说的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么 sklearns 分类报告中的“加权”平均 F1 分数与根据公式计算的 F1 分数不同? - Why is the 'weighted' average F1 score from sklearns classification report different from the F1 score calculated from the formula? 如何从 faster-RCNN 计算 F1 分数和其他分类指标? (PyTorch 中的对象检测) - How can I calculate the F1-score and other classification metrics from a faster-RCNN? (object detection in PyTorch) 如何提高 CNN 分类中的 F1-score - How to improve the F1-score in CNN classification 如何从Sklearn分类报告中返回精确度,召回率和F1分数的平均分数? - How to return average score for precision, recall and F1-score from Sklearn Classification report? h2o:F1 分数和其他二元分类指标缺失 - h2o: F1 score and other binary classification metrics missing F1分数总是〜0.75? - f1-score always ~0.75? 解读sklearns的GridSearchCV最佳成绩 - Interpreting sklearns' GridSearchCV best score 多类分类的每类 F1 分数 - F1-score per class for multi-class classification Keras F1评分指标用于训练模型 - Keras F1 score metrics for training the model metrics.f1_score - 未确定对象的长度 - metrics.f1_score - length of unsized object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM