precision_recall_curve#

sklearn.metrics.precision_recall_curve(y_true, y_score=None, *, pos_label=None, sample_weight=None, drop_intermediate=False, probas_pred='deprecated')[源代码]#

Compute precision-recall pairs for different probability thresholds.

注意:此实现仅限于二进制分类任务。

精确度就是 tp / (tp + fp) 哪里 tp 是真阳性的数量, fp 假阳性的数量。准确性直观地是分类器不将阴性样本标记为阳性的能力。

召回是比例 tp / (tp + fn) 哪里 tp 是真阳性的数量, fn 假阴性的数量。召回直观地是分类器找到所有阳性样本的能力。

最后一个precision和recall值为1。乙腈-0.并且不具有相应的阈值。这确保图形从y轴开始。

第一个精确度和召回率值是精确度=类别平衡和召回率=1.0,这对应于始终预测正类别的分类器。

阅读更多的 User Guide .

参数:
y_true形状类似阵列(n_samples,)

真正的二进制标签。如果标签不是{-1,1}或{0,1},则应显式给出pos_Label。

y_score形状类似阵列(n_samples,)

目标分数可以是积极类别的概率估计,也可以是决策的非阈值测量(由 decision_function 在一些分类器上)。为 decision_function 分数、大于或等于零的值应表示阳性类别。

pos_labelint、float、bool或string,默认值为无

The label of the positive class. When pos_label=None, if y_true is in {-1, 1} or {0, 1}, pos_label is set to 1, otherwise an error will be raised.

sample_weight形状类似数组(n_samples,),默认=无

样本重量。

drop_intermediate布尔,默认=假

是否降低一些不会出现在绘制的准确率-召回曲线上的次优阈值。这对于创建更轻的精确召回曲线非常有用。

Added in version 1.3.

probas_pred形状类似阵列(n_samples,)

目标分数可以是积极类别的概率估计,也可以是决策的非阈值测量(由 decision_function 在一些分类器上)。

自 1.5 版本弃用: probas_pred 已弃用,将在1.7中删除。使用 y_score 而不是.

返回:
precisionndarray of shape(n_thresholds + 1,)

精度值,使得元素i是得分>=阈值的预测精度 [i] 最后一个元素是1。

recallndarray of shape(n_thresholds + 1,)

降低召回率值,使元素i是得分>=阈值的预测的召回率 [i] 最后一个元素是0。

thresholds形状的nd数组(n_thields,)

增加用于计算精度和回忆的决策函数的阈值 n_thresholds = len(np.unique(probas_pred)) .

参见

PrecisionRecallDisplay.from_estimator

给定二进制分类器绘制精确召回曲线。

PrecisionRecallDisplay.from_predictions

使用二元分类器的预测绘制精确召回曲线。

average_precision_score

根据预测分数计算平均精度。

det_curve

计算不同概率阈值的错误率。

roc_curve

计算接收器工作特性(ROC)曲线。

示例

>>> import numpy as np
>>> from sklearn.metrics import precision_recall_curve
>>> y_true = np.array([0, 0, 1, 1])
>>> y_scores = np.array([0.1, 0.4, 0.35, 0.8])
>>> precision, recall, thresholds = precision_recall_curve(
...     y_true, y_scores)
>>> precision
array([0.5       , 0.66666667, 0.5       , 1.        , 1.        ])
>>> recall
array([1. , 1. , 0.5, 0.5, 0. ])
>>> thresholds
array([0.1 , 0.35, 0.4 , 0.8 ])