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,) 的 array-like
二分类的真实目标值。
- y_score形状为 (n_samples,) 的类数组
估计的概率或决策函数的输出。
- 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 ])