gpt4 book ai didi

python - 值错误 : Data is not binary and pos_label is not specified for roc_curve

转载 作者:行者123 更新时间:2023-11-28 20:40:22 24 4
gpt4 key购买 nike

我正在尝试计算 roc_curve 但我收到此错误消息

Traceback (most recent call last):
File "script.py", line 94, in <module>
fpr, tpr, _ = roc_curve(y_validate, status[:,1])
File "/usr/local/lib/python2.7/site-packages/sklearn/metrics/ranking.py", line 501, in roc_curve
y_true, y_score, pos_label=pos_label, sample_weight=sample_weight)
File "/usr/local/lib/python2.7/site-packages/sklearn/metrics/ranking.py", line 308, in _binary_clf_curve
raise ValueError("Data is not binary and pos_label is not specified")
ValueError: Data is not binary and pos_label is not specified

我的代码

status = rf.predict_proba(x_validate)
fpr, tpr, _ = roc_curve(y_validate, status[:,1]) //error generated here
roc_auc = auc(fpr, tpr)
print roc_auc

P.S:不太理解这个解决方案(ValueError: Data is not binary and pos_label is not specified),因为它似乎并没有真正相关。

最佳答案

要使 ROC 曲线计算有效,您必须指定要视为“真”或“正”标签的标签。 Scikit-learn 假设提供给它的数据总是有标签 0 和 1(在你的例子中是变量 y_validate),其中一个被任意选为正标签(我不完全知道如何 - 我相信您可以深入研究源代码并找出答案)。

如您的错误消息中所述 - 您的数据没有这种预期的二进制格式。即使你的数据是二进制的,但标签是“T”和“F”,它也会抛出这个错误。所以根据 roc_curve() function from scikit-learn 的文档,您需要准确指定将哪个字符串标签用作“正类”。因此,如果您的标签在 y_validate 变量中是“T”和“F”,您可以这样做:fpr, tpr, _ = roc_curve(y_validate, status[:,1], pos_label= 'T').

关于python - 值错误 : Data is not binary and pos_label is not specified for roc_curve,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35953300/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com