【问题标题】:Plotting ROC curve - too many indices error绘制 ROC 曲线 - 索引错误过多
【发布时间】:2014-09-27 07:37:18
【问题描述】:

我直接从这里获取 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])

错误是:

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

y_pred 如下所示: array.shape() giving error tuple not callable

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

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

【问题讨论】:

    标签: python numpy scikit-learn roc


    【解决方案1】:

    您的另一个问题中显示的y_predy_test 都是一维的,因此表达式y_pred[:, i]y_test[:, i] 的索引太多。您只能使用单个索引来索引一维数组。

    也就是说,您或许应该致电roc_curve(y_test, y_pred)

    【讨论】:

      猜你喜欢
      • 2021-03-03
      • 2019-02-27
      • 2015-04-08
      • 1970-01-01
      • 2020-01-20
      • 2016-02-04
      • 2018-12-24
      • 2022-01-13
      • 1970-01-01
      相关资源
      最近更新 更多