绘制 ROC 曲线 - 索引错误太多

use*_*627 2 python numpy roc scikit-learn

我直接从这里获取 ROC 代码:http : //scikit-learn.org/stable/auto_examples/plot_roc.html

如您所见,我在 for 循环中将我的类数硬编码为 46,但是即使我将其设置为低至 2,我仍然会收到错误消息。

# Compute ROC curve and ROC area for each class
tpr = dict()
roc_auc = dict()
for i in range(46):
    fpr[i], tpr[i], _ = roc_curve(y_test[:, i], y_pred[:, i])
    roc_auc[i] = auc(fpr[i], tpr[i])
Run Code Online (Sandbox Code Playgroud)

错误是:

Traceback (most recent call last):
  File "C:\Users\app\Documents\Python Scripts\gbc_classifier_test.py", line 150, in <module>
    fpr[i], tpr[i], _ = roc_curve(y_test[:, i], y_pred[:, i])
IndexError: too many indices
Run Code Online (Sandbox Code Playgroud)

y_pred正如你在这里看到的: array.shape() 给出错误元组不可调用

并且y_test只是一个类似于 y_pred 的一维数组,除了我的问题的真正类。

我不明白,什么有太多的索引?

Fre*_*Foo 5

无论是y_pred在您的其他问题,并表示y_test为1-d,这样的表达y_pred[:, i],并y_test[:, i]有太多的指标。您只能使用单个索引索引一维数组。

也就是说,您可能应该只调用roc_curve(y_test, y_pred).