sklearn.metrics.precision_recall_curve?

sklearn.metrics.precision_recall_curve(y_true, probas_pred, *, pos_label=None, sample_weight=None)

[源碼]

計算不同概率閾值的精確召回對

注意:此實現僅限于二進制分類任務。

精度是tp /(tp + fp)的比率,其中tp是真正例的數目,fp是假正例的數目。從直覺上講,精度是分類器不將負例樣本標記為正例的能力。

召回率是tp /(tp + fn)的比率,其中tp是真正例的數目,fn是假負例的數目。直觀上,召回是分類器找到所有正例樣本的能力。

最后的精度和召回值分別為1.和0,并且沒有相應的閾值。這樣可以確保圖形從y軸開始。

用戶指南中閱讀更多內容。

參數 說明
y_true array, shape = [n_samples]
真正的二進制標簽。 如果標簽既不是{-1,1}也不是{0,1},則應該明確給出pos_label。
probas_pred array, shape = [n_samples]
估計的概率或決策函數。
pos_label int or str, default=None
正例類別的標簽。當pos_label = None時,如果y_true在{-1,1}或{0,1}中,則pos_label設置為1,否則將引發錯誤。
sample_weight array-like of shape (n_samples,), default=None
樣本權重。
返回值 說明
precision array, shape = [n_thresholds + 1]
精度值,以使元素i為score>=thresholds [i]且最后一個元素為1的預測精度。
recall array, shape = [n_thresholds + 1]
降低召回值使元素i為score> = thresholds [i]且最后一個元素為0的預測的召回。
thresholds array, shape = [n_thresholds <= len(np.unique(probas_pred))]
用于計算精度和召回率的決策函數的閾值不斷增加。

另見:

示例

>>> import numpy as np
>>> from sklearn.metrics import precision_recall_curve
>>> y_true = np.array([0011])
>>> y_scores = np.array([0.10.40.350.8])
>>> precision, recall, thresholds = precision_recall_curve(
...     y_true, y_scores)
>>> precision
array([0.666666670.5       , 1.        , 1.        ])
>>> recall
array([1. , 0.50.50. ])
>>> thresholds
array([0.350.4 , 0.8 ])

sklearn.metrics.precision_recall_curve應用示例?