为什么 roc_curve 只返回 3 个值? [英] Why does roc_curve return only 3 values?
问题描述
我将标签为 0 和 1 的形状 (999,
) 的 y_true
和 y_pred
传递给 FP, TP, threshold =roc_curve(y_true, y_pred, pos_label=1)
结果 array
只有 3 个元素被返回.有什么问题?
I pass y_true
and y_pred
of shapes (999,
) with labels 0 and 1 to FP, TP, threshold = roc_curve(y_true, y_pred, pos_label=1)
and as a result array
of only 3 elements is being returned. What can be wrong?
整个代码片段
def get_roc_auc_scores(y_pred_labels, y_true_labels):
roc_auc_scores = {key: {'FP': [], 'TP': [], 'Scores': []} for key in ['Low', 'High']}
for key in roc_auc_scores.keys():
for y_pred in y_pred_labels:
# Get True Positive and False Positive labels
fp, tp, thresh = roc_curve(y_true_labels[key], y_pred, pos_label=1)
roc_auc_scores[key]['FP'].append(fp)
roc_auc_scores[key]['TP'].append(tp)
# Get AUC score
auc_score = roc_auc_score(y_true_labels[key], y_pred)
roc_auc_scores[key]['Scores'].append(auc_score)
return roc_auc_scores
其中 y_pred_labels
是一个包含 6 个带有预测的 arrays
的列表,y_true_labels
包含真实的标签.高和低仅描述特定情况.
where y_pred_labels
is a list containing 6 arrays
with predictions and y_true_labels
contains true labels. High and Low describe only the specific case.
推荐答案
ROC 曲线是通过改变决策阈值来构建的:您不应将硬类预测作为 y_score
传递,而是通过概率分数或其他一些置信度量.
ROC curves are built by varying a decision threshold: you should not pass hard class predictions as y_score
, but instead the probability scores or some other confidence measure.
来自文档:
y_score : array, shape = [n_samples]
目标分数,可以是正类的概率估计、置信度值或决策的非阈值度量(如某些分类器上的decision_function"返回).
Target scores, can either be probability estimates of the positive class, confidence values, or non-thresholded measure of decisions (as returned by "decision_function" on some classifiers).
通过硬二元分类,只有三个相关阈值:一个低于 0,一个介于 0 和 1 之间,一个大于 1.
Passing a hard binary classification, there are only three relevant thresholds: one below 0, one between 0 and 1, and one greater than 1.
这篇关于为什么 roc_curve 只返回 3 个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!