假設我有以下內容:
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: multilabel-indicator format is not supported
可以做些什么來解決這個問題?我不太確定我能做什么。請幫忙。
uj5u.com熱心網友回復:
這些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://www.uj5u.com/ruanti/524678.html
