求AUC报错ValueError: Data is not binary and pos_label is not specified或continuous format is not support

我的源代码

roc_auc_score(y_true=y_test, y_score=y_predict)

报错

ValueError: Data is not binary and pos_label is not specified

解决办法

第一步:将你的y_true和 y_score改为数组格式并且dtype为float64

在这里插入图片描述

第二步:设置pos_label

详细尝试情况截图

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

尝试1

在这里插入图片描述

尝试2

在这里插入图片描述

尝试3

在这里插入图片描述

尝试4

在这里插入图片描述
综上,没有设置pos_label=2的情况下直接用roc_auc_score是肯定不行的,需要这样:

import numpy as np

from sklearn import metrics

fpr, tpr, thresholds = metrics.roc_curve(y_c, y_d, pos_label=2)

metrics.auc(fpr, tpr)
发布了549 篇原创文章 · 获赞 719 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/qq_35456045/article/details/104545096
今日推荐