Assuming that I have the following:
x_train
y_train
x_test
y_test
And there is 7 labels total (0 through 6), I am trying to create a ROC curve for each individual label type of the testing data. I already looked at this post,https://stackoverflow.com/questions/65236646/valueerror-multilabel-indicator-format-is-not-supported-for-roc-curve-sklea and tried to create a code that would work, however I am having bad luck.
I ran the model for the datasets, which is a CNN model:
history_model = model.fit(
x_train, y_train,
epochs=1000,
batch_size = 16,
validation_data=(x_test, y_test),
verbose=2)
In order to visualize the data, I am trying to make a ROC curve, which can help me understand the TP rate and FP rate. Now, I tried the following to make a ROC curve...
y_pred = model.predict(x_test)
fpr, tpr, threshold = metrics.roc_curve(y_test, y_pred)
roc_auc = metrics.auc(fpr, tpr)
However, I am getting the following error: ValueError: multilabel-indicator format is not supported
What can be done to get around this issue? I'm not too sure what I can do. Please help.
CodePudding user response:
The roc_curve and auc
functions only work on 1-d arrays. In your case, you must loop for each label.
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)