可进行多类别分类

可进行多类别分类

本文介绍了每类F1分数,可进行多类别分类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python和scikit-learn处理多类分类问题.目前,我正在使用classification_report函数评估分类器的性能,并获得如下报告:

I'm working on a multiclass classification problem using python and scikit-learn. Currently, I'm using the classification_report function to evaluate the performance of my classifier, obtaining reports like the following:

>>> print(classification_report(y_true, y_pred, target_names=target_names))
             precision    recall  f1-score   support

    class 0       0.50      1.00      0.67         1
    class 1       0.00      0.00      0.00         1
    class 2       1.00      0.67      0.80         3

avg / total       0.70      0.60      0.61         5

要进行进一步的分析,我对获得每个可用班级的每班级f1分数很感兴趣.也许是这样的:

To do further analysis, I'm interesting in obtaining the per-class f1 score of each of the classes available. Maybe something like this:

>>> print(calculate_f1_score(y_true, y_pred, target_class='class 0'))
0.67

在scikit-learn上有类似的内容吗?

Is there something like that available on scikit-learn?

推荐答案

来自f1_score 文档.

from sklearn.metrics import f1_score
y_true = [0, 1, 2, 0, 1, 2]
y_pred = [0, 2, 1, 0, 0, 1]

f1_score(y_true, y_pred, average=None)

胜利:

array([ 0.8,  0. ,  0. ])

每个班的分数是多少.

这篇关于每类F1分数,可进行多类别分类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 17:43