不平衡分类报告#

imblearn.metrics.classification_report_imbalanced(y_true, y_pred, *, labels=None, target_names=None, sample_weight=None, digits=2, alpha=0.1, output_dict=False, zero_division='warn')[source]#

基于用于不平衡数据集的指标构建分类报告。

已经提出了特定的指标来评估在不平衡数据集上执行的分类。本报告汇编了最先进的指标:精确度/召回率/特异性、几何平均值和几何平均值的平衡准确率指数。

用户指南中阅读更多内容。

Parameters:
y_true1d array-like, or label indicator array / sparse matrix

真实(正确)目标值。

y_pred1d array-like, or label indicator array / sparse matrix

分类器返回的估计目标。

labelsarray-like of shape (n_labels,), default=None

可选的标签索引列表,包含在报告中。

target_nameslist of str of shape (n_labels,), default=None

可选的显示名称与标签匹配(顺序相同)。

sample_weightarray-like of shape (n_samples,), default=None

样本权重。

digitsint, default=2

用于格式化输出浮点值的数字位数。 当 output_dictTrue 时,此设置将被忽略,并且返回的值不会被四舍五入。

alphafloat, default=0.1

权重因子。

output_dictbool, default=False

如果为True,则以字典形式返回输出。

在版本0.8中添加。

zero_division“warn” or {0, 1}, default=”warn”

设置当出现零除时返回的值。如果设置为“warn”,则其作用为0,但也会引发警告。

在版本0.8中添加。

Returns:
reportstring / dict

精确度、召回率、特异性、几何平均数和指数平衡准确率的文本摘要。 如果output_dict为True,则返回字典。字典具有以下结构:

{'label 1': {'pre':0.5,
             'rec':1.0,
             ...
            },
 'label 2': { ... },
  ...
}

示例

>>> import numpy as np
>>> from imblearn.metrics import classification_report_imbalanced
>>> y_true = [0, 1, 2, 2, 2]
>>> y_pred = [0, 0, 2, 2, 1]
>>> target_names = ['class 0', 'class 1', 'class 2']
>>> print(classification_report_imbalanced(y_true, y_pred,     target_names=target_names))
                   pre       rec       spe        f1       geo       iba       sup

    class 0       0.50      1.00      0.75      0.67      0.87      0.77         1
    class 1       0.00      0.00      0.75      0.00      0.00      0.00         1
    class 2       1.00      0.67      1.00      0.80      0.82      0.64         3

avg / total       0.70      0.60      0.90      0.61      0.66      0.54         5

使用imblearn.metrics.classification_report_imbalanced的示例#

多类分类与欠采样

Multiclass classification with under-sampling

文本文档中的主题分类示例

Example of topic classification in text documents

通过编译报告评估分类

Evaluate classification by compiling a report