specificity_score#
- imblearn.metrics.specificity_score(y_true, y_pred, *, labels=None, pos_label=1, average='binary', sample_weight=None)[source]#
计算特异性。
特异性是比率
tn / (tn + fp)
,其中tn
是真阴性的数量,fp
是假阳性的数量。特异性量化了避免假阳性的能力。最佳值为1,最差值为0。
更多内容请参阅用户指南。
- Parameters:
- y_truearray-like of shape (n_samples,)
真实(正确)目标值。
- y_predarray-like of shape (n_samples,)
分类器返回的估计目标。
- labelsarray-like, default=None
当
average != 'binary'
时要包含的标签集,以及如果average is None
时的顺序。数据中存在的标签可以被排除,例如在计算多类平均值时忽略大多数负类,而数据中不存在的标签将在宏平均值中导致0个组件。- pos_labelstr, int or None, default=1
如果
average='binary'
且数据是二元的,则报告该类。 如果pos_label is None
并且在二元分类中,如果average
是'weighted'
之一,则此函数返回平均特异性。 如果数据是多类的,则此设置将被忽略; 设置labels=[pos_label]
和average != 'binary'
将仅报告该标签的分数。- averagestr, default=None
如果
None
,则返回每个类的分数。否则,这将决定对数据执行的平均类型:'binary'
:仅报告由
pos_label
指定的类别结果。 这仅在目标(y_{true,pred}
)为二元时适用。'micro'
:通过计算总的真正例、假反例和假正例来全局计算指标。
'macro'
:计算每个标签的指标,并找到它们的未加权平均值。这不考虑标签不平衡的情况。
'weighted'
:计算每个标签的指标,并根据支持度(每个标签的真实实例数量)找到它们的加权平均值。这改变了“宏”以考虑标签不平衡;它可能导致F分数不在精确度和召回率之间。
'samples'
:计算每个实例的指标,并找到它们的平均值(仅对多标签分类有意义,这与
accuracy_score
不同)。
- sample_weightarray-like of shape (n_samples,), default=None
样本权重。
- Returns:
- specificityfloat (if
average is None
) or ndarray of shape (n_unique_labels,) 特异性指标。
- specificityfloat (if
示例
>>> import numpy as np >>> from imblearn.metrics import specificity_score >>> y_true = [0, 1, 2, 0, 1, 2] >>> y_pred = [0, 2, 1, 0, 0, 1] >>> specificity_score(y_true, y_pred, average='macro') 0.66... >>> specificity_score(y_true, y_pred, average='micro') 0.66... >>> specificity_score(y_true, y_pred, average='weighted') 0.66... >>> specificity_score(y_true, y_pred, average=None) array([0.75, 0.5 , 0.75])