mars.learn.metrics.roc_curve#

mars.learn.metrics.roc_curve(y_true, y_score, pos_label=None, sample_weight=None, drop_intermediate=True, session=None, run_kwargs=None)[来源]#

计算接收者操作特征(ROC)

注意:该实现仅限于二元分类任务。

用户指南中阅读更多内容。

Parameters
  • y_true (tensor, shape = [n_samples]) – 真实的二元标签。如果标签不是{-1, 1}或{0, 1},则应该明确给出pos_label。

  • y_score (张量, 形状 = [样本数]) – 目标分数,可以是正类的概率估计、置信值,或者是未阈值化的决策测量(由某些分类器的“decision_function”返回)。

  • pos_label (intstr, 默认=None) – 正类的标签。 当 pos_label=None 时,如果 y_true 属于 {-1, 1} 或 {0, 1}, pos_label 被设置为 1,否则会引发错误。

  • sample_weight (类数组,形状 (n_samples,), 默认值=None) – 样本权重。

  • drop_intermediate (boolean, optional (default=True)) –

    是否删除一些在绘制的ROC曲线上不会出现的次优阈值。这对于创建更简洁的ROC曲线是有用的。

    在版本0.17中新增: 参数 drop_intermediate

Returns

  • fpr (tensor, shape = [>2]) – 增加的假阳性率,其中元素 i 是预测得分 >= thresholds[i] 的假阳性率。

  • tpr (tensor, shape = [>2]) – 增加的真阳性率,其中元素 i 是预测得分 >= thresholds[i] 的真阳性率。

  • thresholds (tensor, shape = [n_thresholds]) – 用于计算 fpr 和 tpr 的决策函数上的递减阈值。 thresholds[0] 代表没有被预测的实例,并且被任意设置为 max(y_score) + 1

另请参阅

roc_auc_score

计算ROC曲线下面积

备注

由于这些阈值是从低到高排序的,所以在返回时会反转它们,以确保它们与在计算过程中按反向顺序排序的 fprtpr 相对应。

参考文献

1

接收者操作特征的维基百科条目

2

Fawcett T. ROC分析简介[J]. 模式识别通讯, 2006, 27(8):861-874.

示例

>>> import mars.tensor as mt
>>> from mars.learn import metrics
>>> y = mt.array([1, 1, 2, 2])
>>> scores = mt.array([0.1, 0.4, 0.35, 0.8])
>>> fpr, tpr, thresholds = metrics.roc_curve(y, scores, pos_label=2)
>>> fpr
array([0. , 0. , 0.5, 0.5, 1. ])
>>> tpr
array([0. , 0.5, 0.5, 1. , 1. ])
>>> thresholds
array([1.8 , 0.8 , 0.4 , 0.35, 0.1 ])