maxframe.learn.metrics.roc_curve#
- maxframe.learn.metrics.roc_curve(y_true, y_score, pos_label=None, sample_weight=None, drop_intermediate=True, execute=False, session=None, run_kwargs=None)[源代码]#
计算接收者操作特征(ROC)
注意:此实现仅限于二分类任务。
更多信息请参见 用户指南。
- 参数:
y_true (tensor, shape = [n_samples]) -- 真实的二分类标签。如果标签不是{-1, 1}或{0, 1},则应显式指定pos_label。
y_score (tensor, 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曲线很有用。
- 返回:
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曲线下面积
备注
由于阈值是按从低到高的顺序排列的,返回时会将其反转,以确保它们与
fpr和tpr相对应,这两个值在计算过程中是按相反顺序排列的。引用
示例
>>> import maxframe.tensor as mt >>> from maxframe.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 ])