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

标签 python numpy scikit-learn roc

我直接从这里获取 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 类似的一维数组,除了我的问题的真实类别。

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

最佳答案

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

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

关于python - 绘制 ROC 曲线 - 索引错误太多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25125300/

相关文章:

python - 如何加密django中的密码字段

python - Matplotlib numpy 矩阵的时间序列图

python - 为什么向量化的 Pinv 比未向量化的慢?

python - 2D 或 3D 中的 Numpy trim_zeros

pandas - 大型数据集的一次热编码

python Pandas : Counting the frequency of a specific value in each row of dataframe?

python - 使用 SymPy 求解方程的 2 条边

python - 如何分组和转发填充0

python - 查找 sklearn 决策树分类器的随机状态

python - sklearn 矩阵分解示例