假设我有以下情况:
x_train
y_train
x_test
y_test
一共有7个标签(从0到6),我试着为每个标签类型的测试数据创建一个ROC曲线。我已经看过这篇文章,https://stackoverflow.com/questions/65236646/valueerror-multilabel-indicator-format-is-not-supported-for-roc-curve-sklea,并试图创建一个可以工作的代码,但是我运气不好。
我运行了数据集的模型,这是一个CNN模型:
history_model = model.fit(
x_train, y_train,
epochs=1000,
batch_size = 16,
validation_data=(x_test, y_test),
verbose=2)
为了可视化数据,我尝试做一个ROC曲线,这可以帮助我了解TP率和FP率。现在,我试着做一个ROC曲线.
y_pred = model.predict(x_test)
fpr, tpr, threshold = metrics.roc_curve(y_test, y_pred)
roc_auc = metrics.auc(fpr, tpr)
但是,我得到了以下错误:不支持ValueError:多标签-指示符格式
怎样才能绕过这个问题呢?我不太确定我能做什么。请帮帮忙。
发布于 2022-10-31 13:38:44
roc_curve and auc
函数只适用于一维数组.在您的情况下,您必须循环每个标签。
fpr_list = []
tpr_list = []
threshold_list = []
roc_auc_list = []
for i in range(7): # you can make this more general
fpr, tpr, threshold = metrics.roc_curve(y_test[:, i], y_pred[:, i])
roc_auc = metrics.auc(fpr, tpr)
fpr_list.append(fpr)
tpr_list.append(tpr)
threshold_list.append(threshold)
roc_auc_list.append(roc_auc)
https://stackoverflow.com/questions/74258347
复制相似问题