【问题标题】:scikit weighted f1 score calculation and usagescikit加权f1分数计算及使用
【发布时间】:2016-01-24 10:25:39
【问题描述】:

我对 sklearn.metrics.f1_score 中的 weighted 平均值有疑问

sklearn.metrics.f1_score(y_true, y_pred, labels=None, pos_label=1, average='weighted', sample_weight=None)

Calculate metrics for each label, and find their average, weighted by support (the number of true instances for each label). This alters ‘macro’ to account for label imbalance; it can result in an F-score that is not between precision and recall.

首先,如果有任何参考证明使用加权 F1 是合理的,我只是好奇在哪些情况下我应该使用加权 F1。

第二,听说weighted-F1已经弃用了,是真的吗?

第三,实际加权-F1是如何计算的,例如

{
    "0": {
        "TP": 2,
        "FP": 1,
        "FN": 0,
        "F1": 0.8
    },
    "1": {
        "TP": 0,
        "FP": 2,
        "FN": 2,
        "F1": -1
    },
    "2": {
        "TP": 1,
        "FP": 1,
        "FN": 2,
        "F1": 0.4
    }
}

如何计算上例的加权-F1。我虽然应该是(0.8*2/3 + 0.4*1/3)/3,但是我错了。

【问题讨论】:

    标签: machine-learning nlp scikit-learn precision-recall


    【解决方案1】:

    首先,如果有任何参考证明使用加权 F1 是合理的,我只是好奇在哪些情况下我应该使用加权 F1。

    我没有任何参考资料,但如果您对多标签分类感兴趣,您关心所有类的精度/召回率,那么加权 f1 分数是合适的。如果你有只关心正样本的二元分类,那么它可能不合适。

    第二,听说weighted-F1已经弃用了,是真的吗?

    不,weighted-F1 本身并没有被弃用。在 v0.16 中,仅弃用了函数接口的某些方面,然后只是为了在以前模棱两可的情况下使其更加明确。 (历史讨论on github 或查看the source code 并在页面中搜索“已弃用”以查找详细信息。)

    第三,实际加权-F1 是如何计算的?

    来自f1_score的文档:

    ``'weighted'``:
      Calculate metrics for each label, and find their average, weighted
      by support (the number of true instances for each label). This
      alters 'macro' to account for label imbalance; it can result in an
      F-score that is not between precision and recall.
    

    因此平均值由 support 加权,即具有给定标签的样本数。由于您上面的示例数据不包括支持,因此无法根据您列出的信息计算加权 f1 分数。

    【讨论】:

    • 感谢您的详尽回答。只有一个问题:如果支持是每个标签的真实实例数,我们不能通过为每个标签添加TP + FN 来计算吗?
    猜你喜欢
    • 2017-05-07
    • 2016-01-24
    • 1970-01-01
    • 2017-09-11
    • 2019-11-25
    • 2021-08-29
    • 2020-06-17
    • 2018-07-16
    • 2015-12-10
    相关资源
    最近更新 更多