當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python cuml.metrics.precision_recall_curve用法及代碼示例

用法:

cuml.metrics.precision_recall_curve(y_true, probs_pred) → Tuple[cuml.common.array.CumlArray, cuml.common.array.CumlArray, cuml.common.array.CumlArray]

針對不同的概率閾值計算precision-recall 對

注意

此實現僅限於二進製分類任務。精度是比率tp / (tp + fp),其中tp 是真陽性數,fp 是假陽性數。精度直觀地是分類器不將負樣本標記為正樣本的能力。

召回率是 tp / (tp + fn) 的比率,其中 tp 是真陽性數,fn 是假陰性數。召回率直觀地是分類器找到所有正樣本的能力。最後的精度和召回值分別為 1. 和 0.,並且沒有相應的閾值。這可確保圖形從 y 軸開始。

閱讀 scikit-learn 的 User Guide 了解更多信息。

參數

y_true數組,形狀 = [n_samples]

真正的二進製標簽,{0, 1}。

probas_pred數組,形狀 = [n_samples]

估計的概率或決策函數。

返回

precision數組,形狀 = [n_thresholds + 1]

精度值,使得元素 i 是 score >= thresholds[i] 且最後一個元素為 1 的預測的精度。

recall數組,形狀 = [n_thresholds + 1]

減少召回值,使得元素 i 是分數 >= 閾值 [i] 的預測的召回,最後一個元素為 0。

thresholds數組,形狀 = [n_thresholds <= len(np.unique(probas_pred))]

增加用於計算精度和召回率的決策函數的閾值。

例子

import numpy as np
from cuml.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)
print(precision)
print(recall)
print(thresholds)

輸出:

array([0.66666667, 0.5       , 1.        , 1.        ])
array([1. , 0.5, 0.5, 0. ])
array([0.35, 0.4 , 0.8 ])

相關用法


注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cuml.metrics.precision_recall_curve。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。