sklearn.metrics.roc_curve?

sklearn.metrics.roc_curve(y_true, y_score, *, pos_label=None, sample_weight=None, drop_intermediate=True)

源碼

計算接收器工作特性(ROC)

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

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

參數 說明
y_true array, shape = [n_samples]
真正的二進制標簽。 如果標簽既不是{-1,1}也不是{0,1},則應該明確給出pos_label。
y_score array, shape = [n_samples]
目標分數可以是正例類的概率估計值,置信度值或決策的非閾值度量(如某些分類器上的“ decision_function”所返回)。
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
樣本權重。
drop_intermediate boolean, optional (default=True)
是否降低一些未達到最佳閾值的閾值,這些閾值不會出現在繪制的ROC曲線上。 這對于創建較淺的ROC曲線很有用。

版本0.17中的新功能:參數drop_intermediate。
返回值 說明
fpr array, shape = [>2]
增加假正例率,使得元素i是score >= thresholds[i]預測的假正例率。
tpr array, shape = [>2]
增加真正例率,使得元素i是score >= thresholds[i]的預測的真正例率。
thresholds array, shape = [n_thresholds]
用于計算fpr和tpr的決策函數的閾值遞減。 thresholds [0]表示沒有實例在預測中,可以任意設置為max(y_score)+ 1。

另見:

由于閾值從低到高排序,返回時將它們反轉以確保它們對應于fpr和tpr(它們在計算過程中按相反的順序排序)。

參考

1 Wikipedia entry for the Receiver operating characteristic

2 Fawcett T. An introduction to ROC analysis[J]. Pattern Recognition Letters, 2006, 27(8):861-874.

示例

>>> import numpy as np
>>> from sklearn import metrics
>>> y = np.array([1122])
>>> scores = np.array([0.10.40.350.8])
>>> fpr, tpr, thresholds = metrics.roc_curve(y, scores, pos_label=2)
>>> fpr
array([0. , 0. , 0.50.51. ])
>>> tpr
array([0. , 0.50.51. , 1. ])
>>> thresholds
array([1.8 , 0.8 , 0.4 , 0.350.1 ])