【问题标题】:scikit-learn calculate F1 in multilabel classificationscikit-learn 在多标签分类中计算 F1
【发布时间】:2016-01-24 10:16:38
【问题描述】:

我正在尝试在multi-label classification 中使用 scikit 计算宏 F1

from sklearn.metrics import f1_score

y_true = [[1,2,3]]
y_pred = [[1,2,3]]

print f1_score(y_true, y_pred, average='macro')

但是它失败并显示错误消息

ValueError: multiclass-multioutput is not supported

如何计算具有多标签分类的宏 F1?

【问题讨论】:

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


    【解决方案1】:

    在当前的 scikit-learn 版本中,您的代码会导致以下警告:

    DeprecationWarning: Direct support for sequence of sequences multilabel
        representation will be unavailable from version 0.17. Use
        sklearn.preprocessing.MultiLabelBinarizer to convert to a label
        indicator representation.
    

    按照此建议,您可以使用sklearn.preprocessing.MultiLabelBinarizer 将此多标签类转换为f1_score 接受的形式。例如:

    from sklearn.preprocessing import MultiLabelBinarizer
    from sklearn.metrics import f1_score
    
    y_true = [[1,2,3]]
    y_pred = [[1,2,3]]
    
    m = MultiLabelBinarizer().fit(y_true)
    
    f1_score(m.transform(y_true),
             m.transform(y_pred),
             average='macro')
    # 1.0
    

    【讨论】:

    • 想知道如何解决多元回归问题。
    猜你喜欢
    • 2016-10-17
    • 2018-03-25
    • 2016-08-05
    • 2014-11-19
    • 2013-04-30
    • 2017-08-05
    • 1970-01-01
    • 2019-04-23
    • 2018-11-13
    相关资源
    最近更新 更多