confusion_matrix_at_thresholds#

sklearn.metrics.confusion_matrix_at_thresholds(y_true, y_score, pos_label=None, sample_weight=None)[source]#

针对每个分类阈值计算二元混淆矩阵项。

用户指南中了解更多信息。

1.8 版本新增。

参数:
y_true形状为 (n_samples,) 的 ndarray

二元分类的真实目标。

y_score形状为 (n_samples,) 的 ndarray

估计的概率或决策函数的输出。

pos_labelint, float, bool or str, default=None

正类别的标签。

sample_weightshape 为 (n_samples,) 的 array-like, default=None

样本权重。

返回:
tns形状为 (n_thresholds,) 的 ndarray

真负例的计数,索引 i 是被分配了 score < thresholds[i] 的负样本数量。

fps形状为 (n_thresholds,) 的 ndarray

假正例的计数,索引 i 是被分配了 score >= thresholds[i] 的负样本数量。负样本的总数等于 fps[-1]

fns形状为 (n_thresholds,) 的 ndarray

假负例的计数,索引 i 是被分配了 score < thresholds[i] 的正样本数量。

tps形状为 (n_thresholds,) 的 ndarray

真正例的递增计数,索引 i 是被分配了 score >= thresholds[i] 的正样本数量。正样本的总数等于 tps[-1]

thresholds形状为 (n_thresholds,) 的 ndarray

递减的分数值。

另请参阅

confusion_matrix

计算分类矩阵以评估分类器的准确性。

roc_curve

计算接收者操作特征 (ROC) 曲线。

precision_recall_curve

计算精确率-召回率曲线。

det_curve

计算检测错误权衡(DET)曲线。

示例

>>> import numpy as np
>>> from sklearn.metrics import confusion_matrix_at_thresholds
>>> y_true = np.array([0., 0., 1., 1.])
>>> y_score = np.array([0.1, 0.4, 0.35, 0.8])
>>> tns, fps, fns, tps, thresholds = confusion_matrix_at_thresholds(y_true, y_score)
>>> tns
array([2., 1., 1., 0.])
>>> fps
array([0., 1., 1., 2.])
>>> fns
array([1., 1., 0., 0.])
>>> tps
array([1., 1., 2., 2.])
>>> thresholds
array([0.8 , 0.4 , 0.35, 0.1 ])